Skip to content

Commit

Permalink
added terraform support for cloud_run_revision_filters
Browse files Browse the repository at this point in the history
  • Loading branch information
tedkahwaji committed Oct 8, 2024
1 parent 271c36a commit fa1428b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions datadog/fwprovider/resource_datadog_integration_gcp_sts.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type integrationGcpStsModel struct {
ClientEmail types.String `tfsdk:"client_email"`
DelegateAccountEmail types.String `tfsdk:"delegate_account_email"`
HostFilters types.Set `tfsdk:"host_filters"`
CloudRunRevisionFilters types.Set `tfsdk:"cloud_run_revision_filters"`
IsCspmEnabled types.Bool `tfsdk:"is_cspm_enabled"`
IsSecurityCommandCenterEnabled types.Bool `tfsdk:"is_security_command_center_enabled"`
ResourceCollectionEnabled types.Bool `tfsdk:"resource_collection_enabled"`
Expand Down Expand Up @@ -88,6 +89,11 @@ func (r *integrationGcpStsResource) Schema(_ context.Context, _ resource.SchemaR
Description: "Your Host Filters.",
ElementType: types.StringType,
},
"cloud_run_revision_filters": schema.SetAttribute{
Optional: true,
Description: "Tags to filter which Cloud Run revisions are imported into Datadog. Only revisions that meet specified criteria will be monitored.",
ElementType: types.StringType,
},
"is_cspm_enabled": schema.BoolAttribute{
Optional: true,
Computed: true,
Expand Down Expand Up @@ -272,6 +278,9 @@ func (r *integrationGcpStsResource) updateState(ctx context.Context, state *inte
if hostFilters, ok := attributes.GetHostFiltersOk(); ok && len(*hostFilters) > 0 {
state.HostFilters, _ = types.SetValueFrom(ctx, types.StringType, *hostFilters)
}
if runFilters, ok := attributes.GetCloudRunRevisionFiltersOk(); ok && len(*runFilters) > 0 {
state.CloudRunRevisionFilters, _ = types.SetValueFrom(ctx, types.StringType, *runFilters)
}
if isCspmEnabled, ok := attributes.GetIsCspmEnabledOk(); ok {
state.IsCspmEnabled = types.BoolValue(*isCspmEnabled)
}
Expand Down Expand Up @@ -309,6 +318,11 @@ func (r *integrationGcpStsResource) buildIntegrationGcpStsRequestBody(ctx contex
}
attributes.SetHostFilters(hostFilters)

runFilters := make([]string, 0)
if !state.CloudRunRevisionFilters.IsNull() {
diags.Append(state.CloudRunRevisionFilters.ElementsAs(ctx, &runFilters, false)...)
}

if !state.IsSecurityCommandCenterEnabled.IsUnknown() {
attributes.SetIsSecurityCommandCenterEnabled(state.IsSecurityCommandCenterEnabled.ValueBool())
}
Expand Down
9 changes: 9 additions & 0 deletions datadog/tests/resource_datadog_integration_gcp_sts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func TestAccIntegrationGcpStsBasic(t *testing.T) {
"datadog_integration_gcp_sts.foo", "resource_collection_enabled", "false"),
resource.TestCheckTypeSetElemAttr(
"datadog_integration_gcp_sts.foo", "host_filters.*", "tag:one"),
resource.TestCheckTypeSetElemAttr(
"datadog_integration_gcp_sts.foo", "cloud_run_revision_filters.*", "tag:two"),
resource.TestCheckTypeSetElemAttr(
"datadog_integration_gcp_sts.foo", "cloud_run_revision_filters.*", "tag:one"),
resource.TestCheckTypeSetElemAttr(
"datadog_integration_gcp_sts.foo", "host_filters.*", "tag:two"),
resource.TestCheckTypeSetElemAttr(
Expand All @@ -63,6 +67,8 @@ func TestAccIntegrationGcpStsBasic(t *testing.T) {
"datadog_integration_gcp_sts.foo", "resource_collection_enabled", "true"),
resource.TestCheckNoResourceAttr(
"datadog_integration_gcp_sts.foo", "host_filters"),
resource.TestCheckNoResourceAttr(
"datadog_integration_gcp_sts.foo", "cloud_run_revision_filters"),
resource.TestCheckNoResourceAttr(
"datadog_integration_gcp_sts.foo", "account_tags"),
),
Expand Down Expand Up @@ -92,6 +98,8 @@ func TestAccIntegrationGcpStsDefault(t *testing.T) {
"datadog_integration_gcp_sts.foo", "is_cspm_enabled", "false"),
resource.TestCheckNoResourceAttr(
"datadog_integration_gcp_sts.foo", "host_filters"),
resource.TestCheckNoResourceAttr(
"datadog_integration_gcp_sts.foo", "cloud_run_revision_filters"),
),
},
},
Expand All @@ -104,6 +112,7 @@ resource "datadog_integration_gcp_sts" "foo" {
automute = "false"
client_email = "%[email protected]"
host_filters = ["tag:one", "tag:two"]
cloud_run_revision_filters = ["tag:one", "tag:two"]
is_cspm_enabled = "false"
resource_collection_enabled = "false"
is_security_command_center_enabled = "false"
Expand Down

0 comments on commit fa1428b

Please sign in to comment.