Skip to content

Commit 7353064

Browse files
remove host filters default
1 parent 203f6f5 commit 7353064

File tree

7 files changed

+548
-70
lines changed

7 files changed

+548
-70
lines changed

datadog/fwprovider/resource_datadog_integration_gcp.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ import (
44
"context"
55
"sync"
66

7-
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
8-
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
9-
107
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
118
"github.com/hashicorp/terraform-plugin-framework/diag"
129
frameworkPath "github.com/hashicorp/terraform-plugin-framework/path"
1310
"github.com/hashicorp/terraform-plugin-framework/resource"
1411
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
12+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
1513
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
1614
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1715
"github.com/hashicorp/terraform-plugin-framework/types"
@@ -117,7 +115,6 @@ func (r *integrationGcpResource) Schema(_ context.Context, _ resource.SchemaRequ
117115
Optional: true,
118116
Computed: true,
119117
Description: "List of filters to limit the VM instances that are pulled into Datadog by using tags. Only VM instance resources that apply to specified filters are imported into Datadog.",
120-
Default: stringdefault.StaticString(""),
121118
DeprecationMessage: "**Note:** This field is deprecated. Instead, use `monitored_resource_configs` with `type=gce_instance`",
122119
},
123120
"cloud_run_revision_filters": schema.SetAttribute{
@@ -388,7 +385,10 @@ func (r *integrationGcpResource) addOptionalFieldsToBody(ctx context.Context, bo
388385
body.SetIsResourceChangeCollectionEnabled(state.IsResourceChangeCollectionEnabled.ValueBool())
389386
}
390387

391-
body.SetHostFilters(state.HostFilters.ValueString())
388+
if !state.HostFilters.IsUnknown() {
389+
body.SetHostFilters(state.HostFilters.ValueString())
390+
}
391+
392392
body.SetCloudRunRevisionFilters(tfCollectionToSlice[string](ctx, diags, state.CloudRunRevisionFilters))
393393
mrcs := make([]datadogV1.GCPMonitoredResourceConfig, 0)
394394
for _, mrc := range tfCollectionToSlice[*MonitoredResourceConfigModel](ctx, diags, state.MonitoredResourceConfigs) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2026-02-03T14:21:27.948616-05:00

datadog/tests/cassettes/TestAccDatadogHostFiltersBug.yaml

Lines changed: 411 additions & 0 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-09-11T11:40:51.735626-04:00
1+
2026-02-03T14:21:43.835918-05:00

datadog/tests/cassettes/TestAccDatadogIntegrationGCP.yaml

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

datadog/tests/resource_datadog_integration_gcp_test.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,92 @@ import (
1414
"github.com/terraform-providers/terraform-provider-datadog/datadog/fwprovider"
1515
)
1616

17+
func TestAccDatadogHostFiltersBug(t *testing.T) {
18+
t.Parallel()
19+
ctx, providers, accProviders := testAccFrameworkMuxProviders(context.Background(), t)
20+
uniq := uniqueEntityName(ctx, t)
21+
22+
resource.Test(t, resource.TestCase{
23+
PreCheck: func() { testAccPreCheck(t) },
24+
ProtoV5ProviderFactories: accProviders,
25+
CheckDestroy: checkIntegrationGCPDestroy(providers.frameworkProvider),
26+
Steps: []resource.TestStep{
27+
{
28+
Config: fmt.Sprintf(`
29+
resource "datadog_integration_gcp" "awesome_gcp_project_integration" {
30+
project_id = "%s"
31+
private_key_id = "1234567890123456789012345678901234567890"
32+
private_key = "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
33+
client_email = "%s@awesome-project-id.iam.gserviceaccount.com"
34+
client_id = "123456789012345678901"
35+
host_filters = "host:one"
36+
}`, uniq, uniq),
37+
Check: resource.ComposeTestCheckFunc(checkIntegrationGCPExists(providers.frameworkProvider)),
38+
ConfigStateChecks: []statecheck.StateCheck{
39+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("project_id"), knownvalue.StringExact(uniq)),
40+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("private_key_id"), knownvalue.StringExact("1234567890123456789012345678901234567890")),
41+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("private_key"), knownvalue.StringExact("-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n")),
42+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("client_email"), knownvalue.StringExact(fmt.Sprintf("%s@awesome-project-id.iam.gserviceaccount.com", uniq))),
43+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("client_id"), knownvalue.StringExact("123456789012345678901")),
44+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("automute"), knownvalue.Bool(false)),
45+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("cspm_resource_collection_enabled"), knownvalue.Bool(false)),
46+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("is_security_command_center_enabled"), knownvalue.Bool(false)),
47+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("resource_collection_enabled"), knownvalue.Bool(true)),
48+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("is_resource_change_collection_enabled"), knownvalue.Bool(false)),
49+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("host_filters"), knownvalue.StringExact("host:one")),
50+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("monitored_resource_configs"), knownvalue.SetExact([]knownvalue.Check{
51+
knownvalue.ObjectExact(map[string]knownvalue.Check{
52+
"type": knownvalue.StringExact("gce_instance"),
53+
"filters": knownvalue.SetExact([]knownvalue.Check{
54+
knownvalue.StringExact("host:one"),
55+
}),
56+
}),
57+
})),
58+
},
59+
},
60+
{
61+
Config: fmt.Sprintf(`
62+
resource "datadog_integration_gcp" "awesome_gcp_project_integration" {
63+
project_id = "%s"
64+
private_key_id = "1234567890123456789012345678901234567890"
65+
private_key = "-----BEGIN PRIVATE KEY-----\n key updated \n-----END PRIVATE KEY-----\n"
66+
client_email = "%s@awesome-project-id.iam.gserviceaccount.com"
67+
client_id = "123456789012345678901"
68+
automute = true
69+
monitored_resource_configs = [
70+
{
71+
type = "gce_instance"
72+
filters = ["host:one"]
73+
},
74+
]
75+
}`, uniq, uniq),
76+
Check: resource.ComposeTestCheckFunc(checkIntegrationGCPExists(providers.frameworkProvider)),
77+
ConfigStateChecks: []statecheck.StateCheck{
78+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("project_id"), knownvalue.StringExact(uniq)),
79+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("private_key_id"), knownvalue.StringExact("1234567890123456789012345678901234567890")),
80+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("private_key"), knownvalue.StringExact("-----BEGIN PRIVATE KEY-----\n key updated \n-----END PRIVATE KEY-----\n")),
81+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("client_email"), knownvalue.StringExact(fmt.Sprintf("%s@awesome-project-id.iam.gserviceaccount.com", uniq))),
82+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("client_id"), knownvalue.StringExact("123456789012345678901")),
83+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("automute"), knownvalue.Bool(true)),
84+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("cspm_resource_collection_enabled"), knownvalue.Bool(false)),
85+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("is_security_command_center_enabled"), knownvalue.Bool(false)),
86+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("resource_collection_enabled"), knownvalue.Bool(true)),
87+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("is_resource_change_collection_enabled"), knownvalue.Bool(false)),
88+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("host_filters"), knownvalue.StringExact("host:one")),
89+
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("monitored_resource_configs"), knownvalue.SetExact([]knownvalue.Check{
90+
knownvalue.ObjectExact(map[string]knownvalue.Check{
91+
"type": knownvalue.StringExact("gce_instance"),
92+
"filters": knownvalue.SetExact([]knownvalue.Check{
93+
knownvalue.StringExact("host:one"),
94+
}),
95+
}),
96+
})),
97+
},
98+
},
99+
},
100+
})
101+
}
102+
17103
func TestAccDatadogIntegrationGCP(t *testing.T) {
18104
t.Parallel()
19105
ctx, providers, accProviders := testAccFrameworkMuxProviders(context.Background(), t)

docs/resources/integration_gcp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ resource "datadog_integration_gcp" "awesome_gcp_project_integration" {
6060
- `automute` (Boolean) Silence monitors for expected GCE instance shutdowns. Defaults to `false`.
6161
- `cloud_run_revision_filters` (Set of String, Deprecated) List of filters to limit the Cloud Run revisions that are pulled into Datadog by using tags. Only Cloud Run revision resources that apply to specified filters are imported into Datadog.
6262
- `cspm_resource_collection_enabled` (Boolean) Whether Datadog collects cloud security posture management resources from your GCP project. If enabled, requires `resource_collection_enabled` to also be enabled. Defaults to `false`.
63-
- `host_filters` (String, Deprecated) List of filters to limit the VM instances that are pulled into Datadog by using tags. Only VM instance resources that apply to specified filters are imported into Datadog. Defaults to `""`.
63+
- `host_filters` (String, Deprecated) List of filters to limit the VM instances that are pulled into Datadog by using tags. Only VM instance resources that apply to specified filters are imported into Datadog.
6464
- `is_resource_change_collection_enabled` (Boolean) When enabled, Datadog scans for all resource change data in your Google Cloud environment.
6565
- `is_security_command_center_enabled` (Boolean) When enabled, Datadog will attempt to collect Security Command Center Findings. Note: This requires additional permissions on the service account. Defaults to `false`.
6666
- `monitored_resource_configs` (Set of Object) Configurations for GCP monitored resources. Only monitored resources that apply to specified filters are imported into Datadog. (see [below for nested schema](#nestedatt--monitored_resource_configs))

0 commit comments

Comments
 (0)