Skip to content

Commit

Permalink
[datadog_integration_cloudflare_account] Don't set email left empty a…
Browse files Browse the repository at this point in the history
…nd ignore resource order (#2724)

* don't set email when empty string, and ignore resource order
  • Loading branch information
nkzou authored Dec 17, 2024
1 parent 33b80ca commit c418aca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type integrationCloudflareAccountModel struct {
ApiKey types.String `tfsdk:"api_key"`
Email types.String `tfsdk:"email"`
Name types.String `tfsdk:"name"`
Resources types.List `tfsdk:"resources"`
Resources types.Set `tfsdk:"resources"`
}

func NewIntegrationCloudflareAccountResource() resource.Resource {
Expand Down Expand Up @@ -68,11 +68,11 @@ func (r *integrationCloudflareAccountResource) Schema(_ context.Context, _ resou
},
},
"id": utils.ResourceIDAttribute(),
"resources": schema.ListAttribute{
"resources": schema.SetAttribute{
ElementType: types.StringType,
Optional: true,
Computed: true,
Description: "An allowlist of resources to pull metrics for. Including, `web`, `dns`, `lb` (load balancer), and `worker`).",
Description: "An allowlist of resources to pull metrics for. Includes `web`, `dns`, `lb` (load balancer), and `worker`).",
},
},
}
Expand Down Expand Up @@ -193,7 +193,7 @@ func (r *integrationCloudflareAccountResource) updateState(ctx context.Context,
data := resp.GetData()
attributes := data.GetAttributes()

if email, ok := attributes.GetEmailOk(); ok {
if email, ok := attributes.GetEmailOk(); ok && *email != "" {
state.Email = types.StringValue(*email)
}

Expand All @@ -202,7 +202,7 @@ func (r *integrationCloudflareAccountResource) updateState(ctx context.Context,
}

if resources, ok := attributes.GetResourcesOk(); ok {
state.Resources, _ = types.ListValueFrom(ctx, types.StringType, resources)
state.Resources, _ = types.SetValueFrom(ctx, types.StringType, resources)
}
}

Expand All @@ -216,7 +216,7 @@ func (r *integrationCloudflareAccountResource) buildIntegrationCloudflareAccount
}
attributes.SetName(state.Name.ValueString())

if !state.Resources.IsNull() {
if !state.Resources.IsNull() && !state.Resources.IsUnknown() {
var resources []string
diags.Append(state.Resources.ElementsAs(ctx, &resources, false)...)
attributes.SetResources(resources)
Expand All @@ -238,7 +238,7 @@ func (r *integrationCloudflareAccountResource) buildIntegrationCloudflareAccount
attributes.SetEmail(state.Email.ValueString())
}

if !state.Resources.IsNull() {
if !state.Resources.IsNull() && !state.Resources.IsUnknown() {
var resources []string
diags.Append(state.Resources.ElementsAs(ctx, &resources, false)...)
attributes.SetResources(resources)
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/integration_cloudflare_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ resource "datadog_integration_cloudflare_account" "foo" {
### Optional

- `email` (String) The email associated with the Cloudflare account. If an API key is provided (and not a token), this field is also required.
- `resources` (List of String) An allowlist of resources to pull metrics for. Including, `web`, `dns`, `lb` (load balancer), and `worker`).
- `resources` (Set of String) An allowlist of resources to pull metrics for. Includes `web`, `dns`, `lb` (load balancer), and `worker`).

### Read-Only

Expand Down

0 comments on commit c418aca

Please sign in to comment.