From a18a644a757d46ed473f42c12b71c0369359af9a Mon Sep 17 00:00:00 2001 From: Teddy Kahwaji Date: Wed, 9 Oct 2024 13:06:02 -0400 Subject: [PATCH] update v1 type to set --- .../resource_datadog_integration_gcp.go | 16 +++++++++++++--- .../resource_datadog_integration_gcp_test.go | 6 +++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/datadog/fwprovider/resource_datadog_integration_gcp.go b/datadog/fwprovider/resource_datadog_integration_gcp.go index a38ca6b46..edeef285b 100644 --- a/datadog/fwprovider/resource_datadog_integration_gcp.go +++ b/datadog/fwprovider/resource_datadog_integration_gcp.go @@ -5,6 +5,7 @@ import ( "sync" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/setdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/DataDog/datadog-api-client-go/v2/api/datadogV1" @@ -47,7 +48,7 @@ type integrationGcpModel struct { ClientId types.String `tfsdk:"client_id"` Automute types.Bool `tfsdk:"automute"` HostFilters types.String `tfsdk:"host_filters"` - CloudRunRevisionFilters types.String `tfskd:"cloud_run_revision_filters"` + CloudRunRevisionFilters types.Set `tfskd:"cloud_run_revision_filters"` ResourceCollectionEnabled types.Bool `tfsdk:"resource_collection_enabled"` CspmResourceCollectionEnabled types.Bool `tfsdk:"cspm_resource_collection_enabled"` IsSecurityCommandCenterEnabled types.Bool `tfsdk:"is_security_command_center_enabled"` @@ -113,11 +114,11 @@ func (r *integrationGcpResource) Schema(_ context.Context, _ resource.SchemaRequ Computed: true, Default: stringdefault.StaticString(""), }, - "cloud_run_revision_filters": schema.StringAttribute{ + "cloud_run_revision_filters": schema.SetAttribute{ Description: "Tags to filter which Cloud Run revisions are imported into Datadog. Only revisions that meet specified criteria are monitored.", Optional: true, Computed: true, - Default: stringdefault.StaticString(""), + Default: setdefault.StaticValue(types.Set{}), }, "automute": schema.BoolAttribute{ Description: "Silence monitors for expected GCE instance shutdowns.", @@ -296,6 +297,10 @@ func (r *integrationGcpResource) updateState(ctx context.Context, state *integra state.ResourceCollectionEnabled = types.BoolValue(resp.GetResourceCollectionEnabled()) state.IsSecurityCommandCenterEnabled = types.BoolValue(resp.GetIsSecurityCommandCenterEnabled()) + if runFilters, ok := resp.GetCloudRunRevisionFiltersOk(); ok && len(*runFilters) > 0 { + state.CloudRunRevisionFilters, _ = types.SetValueFrom(ctx, types.StringType, *runFilters) + } + // Non-computed values if clientId, ok := resp.GetClientIdOk(); ok { state.ClientId = types.StringValue(*clientId) @@ -353,6 +358,11 @@ func (r *integrationGcpResource) addOptionalFieldsToBody(body *datadogV1.GCPAcco body.SetIsCspmEnabled(state.CspmResourceCollectionEnabled.ValueBool()) body.SetIsSecurityCommandCenterEnabled(state.IsSecurityCommandCenterEnabled.ValueBool()) body.SetHostFilters(state.HostFilters.ValueString()) + + if runFilters, ok := body.GetCloudRunRevisionFiltersOk(); ok && len(*runFilters) > 0 { + body.SetCloudRunRevisionFilters(body.GetCloudRunRevisionFilters()) + } + if !state.ResourceCollectionEnabled.IsUnknown() { body.SetResourceCollectionEnabled(state.ResourceCollectionEnabled.ValueBool()) } diff --git a/datadog/tests/resource_datadog_integration_gcp_test.go b/datadog/tests/resource_datadog_integration_gcp_test.go index 2af49ba87..138895647 100644 --- a/datadog/tests/resource_datadog_integration_gcp_test.go +++ b/datadog/tests/resource_datadog_integration_gcp_test.go @@ -20,7 +20,7 @@ resource "datadog_integration_gcp" "awesome_gcp_project_integration" { client_email = "%s@awesome-project-id.iam.gserviceaccount.com" client_id = "123456789012345678901" host_filters = "foo:bar,buzz:lightyear" - cloud_run_revision_filters = "foo:bar,buzz:lightyear" + cloud_run_revision_filters = ["foo:bar", "buzz:lightyear"] }`, uniq, uniq) } @@ -81,7 +81,7 @@ func TestAccDatadogIntegrationGCP(t *testing.T) { "host_filters", "foo:bar,buzz:lightyear"), resource.TestCheckResourceAttr( "datadog_integration_gcp.awesome_gcp_project_integration", - "cloud_run_revision_filters", "foo:bar,buzz:lightyear"), + "cloud_run_revision_filters", "[\"foo:bar\", \"buzz:lightyear\"]"), resource.TestCheckResourceAttr( "datadog_integration_gcp.awesome_gcp_project_integration", "automute", "false"), @@ -114,7 +114,7 @@ func TestAccDatadogIntegrationGCP(t *testing.T) { "host_filters", ""), resource.TestCheckResourceAttr( "datadog_integration_gcp.awesome_gcp_project_integration", - "cloud_run_revision_filters", ""), + "cloud_run_revision_filters", "[\"foo:bar\", \"buzz:lightyear\"]"), resource.TestCheckResourceAttr( "datadog_integration_gcp.awesome_gcp_project_integration", "automute", "false"),