Skip to content

Commit

Permalink
update v1 type to set
Browse files Browse the repository at this point in the history
  • Loading branch information
tedkahwaji committed Oct 9, 2024
1 parent 1417b14 commit a18a644
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
16 changes: 13 additions & 3 deletions datadog/fwprovider/resource_datadog_integration_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
}
Expand Down
6 changes: 3 additions & 3 deletions datadog/tests/resource_datadog_integration_gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ resource "datadog_integration_gcp" "awesome_gcp_project_integration" {
client_email = "%[email protected]"
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)
}

Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down

0 comments on commit a18a644

Please sign in to comment.