Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[datadog_integration_cloudflare_account] Don't set email left empty and ignore resource order #2724

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading