Skip to content

Commit 9274680

Browse files
address feedback
1 parent 2a21c37 commit 9274680

9 files changed

+160
-126
lines changed

datadog/fwprovider/resource_datadog_integration_gcp_sts.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,8 @@ func (r *integrationGcpStsResource) updateState(ctx context.Context, state *inte
356356
state.AccountTags, _ = types.SetValueFrom(ctx, types.StringType, accountTags)
357357
}
358358

359-
mncsapi := attributes.GetMetricNamespaceConfigs()
360-
mncs := make([]*MetricNamespaceConfigModel, 0, len(mncsapi))
361-
for _, mnc := range mncsapi {
359+
mncs := make([]*MetricNamespaceConfigModel, 0)
360+
for _, mnc := range attributes.GetMetricNamespaceConfigs() {
362361
mncs = append(mncs, &MetricNamespaceConfigModel{
363362
ID: types.StringValue(mnc.GetId()),
364363
Disabled: types.BoolValue(mnc.GetDisabled()),
@@ -403,17 +402,16 @@ func (r *integrationGcpStsResource) buildIntegrationGcpStsRequestBody(ctx contex
403402

404403
attributes.SetAccountTags(tfCollectionToSlice[string](ctx, diags, state.AccountTags))
405404

406-
mncs := make([]datadogV2.GCPMetricNamespaceConfig, 0)
407-
for _, mnc := range tfCollectionToSlice[*MetricNamespaceConfigModel](ctx, diags, state.MetricNamespaceConfigs) {
408-
mncs = append(mncs, datadogV2.GCPMetricNamespaceConfig{
409-
Id: mnc.ID.ValueStringPointer(),
410-
Disabled: mnc.Disabled.ValueBoolPointer(),
411-
})
412-
}
413-
414405
// only set this field if the user explicitly sets the field
415406
// otherwise we want to omit it so that the API server can populate defaults when applicable
416-
if !state.MetricNamespaceConfigs.IsUnknown() {
407+
if cfgs := state.MetricNamespaceConfigs; !cfgs.IsUnknown() {
408+
mncs := make([]datadogV2.GCPMetricNamespaceConfig, 0)
409+
for _, mnc := range tfCollectionToSlice[*MetricNamespaceConfigModel](ctx, diags, cfgs) {
410+
mncs = append(mncs, datadogV2.GCPMetricNamespaceConfig{
411+
Id: mnc.ID.ValueStringPointer(),
412+
Disabled: mnc.Disabled.ValueBoolPointer(),
413+
})
414+
}
417415
attributes.SetMetricNamespaceConfigs(mncs)
418416
}
419417

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2025-10-28T13:40:01.25536-04:00

datadog/tests/cassettes/TestAccIntegrationGCPMcs.yaml renamed to datadog/tests/cassettes/TestAccIntGcpStsMetricNamespaceConfigs.yaml

Lines changed: 113 additions & 77 deletions
Large diffs are not rendered by default.

datadog/tests/cassettes/TestAccIntegrationGCPMcs.freeze

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2025-10-24T14:47:21.228764-04:00
1+
2025-10-28T13:35:36.829284-04:00

datadog/tests/cassettes/TestAccIntegrationGcpStsBasic.yaml

Lines changed: 19 additions & 19 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2025-10-24T14:47:45.052034-04:00
1+
2025-10-28T13:35:51.289884-04:00

datadog/tests/cassettes/TestAccIntegrationGcpStsDefault.yaml

Lines changed: 10 additions & 10 deletions
Large diffs are not rendered by default.

datadog/tests/resource_datadog_integration_gcp_sts_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ import (
1515
"github.com/terraform-providers/terraform-provider-datadog/datadog/internal/utils"
1616
)
1717

18-
func TestAccIntegrationGCPMcs(t *testing.T) {
18+
func TestAccIntGcpStsMetricNamespaceConfigs(t *testing.T) {
1919
t.Parallel()
2020
ctx, providers, accProviders := testAccFrameworkMuxProviders(context.Background(), t)
2121
uniq := uniqueEntityName(ctx, t)
2222

23-
// this test the setting of mcs (metric_namespace_configs), which can be updated to have a prometheus default if the user omits the field
24-
t.Run("1. user creates with the field omitted, and updates with the field omitted: both results should have the prometheus entry", func(t *testing.T) {
23+
t.Run("when mrcs never specified in create and update, uses default", func(t *testing.T) {
2524
resource.Test(t, resource.TestCase{
2625
ProtoV5ProviderFactories: accProviders,
2726
CheckDestroy: testAccCheckDatadogIntegrationGcpStsDestroy(providers.frameworkProvider),
@@ -45,6 +44,7 @@ func TestAccIntegrationGCPMcs(t *testing.T) {
4544
Config: fmt.Sprintf(`
4645
resource "datadog_integration_gcp_sts" "foo" {
4746
client_email = "%s@test-project.iam.gserviceaccount.com"
47+
is_cspm_enabled = "true"
4848
}`, uniq),
4949
Check: resource.ComposeTestCheckFunc(testAccCheckDatadogIntegrationGcpStsExists(providers.frameworkProvider)),
5050
ConfigStateChecks: []statecheck.StateCheck{
@@ -60,7 +60,7 @@ func TestAccIntegrationGCPMcs(t *testing.T) {
6060
})
6161
})
6262

63-
t.Run("2. user creates with the field omitted, and updates with the field NOT omitted: prometheus should be gone", func(t *testing.T) {
63+
t.Run("when mrcs never specified in create, but specified on update, overwrites default", func(t *testing.T) {
6464
resource.Test(t, resource.TestCase{
6565
ProtoV5ProviderFactories: accProviders,
6666
CheckDestroy: testAccCheckDatadogIntegrationGcpStsDestroy(providers.frameworkProvider),
@@ -105,7 +105,7 @@ func TestAccIntegrationGCPMcs(t *testing.T) {
105105
})
106106
})
107107

108-
t.Run("3. user creates with the field NOT omitted, and updates with omission, previous entries should be kept", func(t *testing.T) {
108+
t.Run("when mrcs specified in create, but omitted on update, initial configs kept", func(t *testing.T) {
109109
resource.Test(t, resource.TestCase{
110110
ProtoV5ProviderFactories: accProviders,
111111
CheckDestroy: testAccCheckDatadogIntegrationGcpStsDestroy(providers.frameworkProvider),

0 commit comments

Comments
 (0)