Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions datadog/fwprovider/resource_datadog_integration_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import (
"context"
"sync"

"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"

"github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
"github.com/hashicorp/terraform-plugin-framework/diag"
frameworkPath "github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
Expand Down Expand Up @@ -117,7 +115,6 @@ func (r *integrationGcpResource) Schema(_ context.Context, _ resource.SchemaRequ
Optional: true,
Computed: true,
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.",
Default: stringdefault.StaticString(""),
DeprecationMessage: "**Note:** This field is deprecated. Instead, use `monitored_resource_configs` with `type=gce_instance`",
},
"cloud_run_revision_filters": schema.SetAttribute{
Expand Down Expand Up @@ -388,7 +385,10 @@ func (r *integrationGcpResource) addOptionalFieldsToBody(ctx context.Context, bo
body.SetIsResourceChangeCollectionEnabled(state.IsResourceChangeCollectionEnabled.ValueBool())
}

body.SetHostFilters(state.HostFilters.ValueString())
if !state.HostFilters.IsUnknown() {
body.SetHostFilters(state.HostFilters.ValueString())
}

body.SetCloudRunRevisionFilters(tfCollectionToSlice[string](ctx, diags, state.CloudRunRevisionFilters))
mrcs := make([]datadogV1.GCPMonitoredResourceConfig, 0)
for _, mrc := range tfCollectionToSlice[*MonitoredResourceConfigModel](ctx, diags, state.MonitoredResourceConfigs) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2026-02-03T14:21:27.948616-05:00
411 changes: 411 additions & 0 deletions datadog/tests/cassettes/TestAccDatadogHostFiltersBug.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2025-09-11T11:40:51.735626-04:00
2026-02-03T14:21:43.835918-05:00
106 changes: 43 additions & 63 deletions datadog/tests/cassettes/TestAccDatadogIntegrationGCP.yaml

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions datadog/tests/resource_datadog_integration_gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,92 @@ import (
"github.com/terraform-providers/terraform-provider-datadog/datadog/fwprovider"
)

func TestAccDatadogHostFiltersBug(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you link the GitHub issue here and add to the PR description? (i.e fixes <issue_link>)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also rename the test to be more explicit about which bug is being fixed?

i.e. TestLegacy_WhenReplacingHostFiltersWithMRC_Succeeds or something like this

t.Parallel()
ctx, providers, accProviders := testAccFrameworkMuxProviders(context.Background(), t)
uniq := uniqueEntityName(ctx, t)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: accProviders,
CheckDestroy: checkIntegrationGCPDestroy(providers.frameworkProvider),
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(`
resource "datadog_integration_gcp" "awesome_gcp_project_integration" {
project_id = "%s"
private_key_id = "1234567890123456789012345678901234567890"
private_key = "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
client_email = "%s@awesome-project-id.iam.gserviceaccount.com"
client_id = "123456789012345678901"
host_filters = "host:one"
}`, uniq, uniq),
Check: resource.ComposeTestCheckFunc(checkIntegrationGCPExists(providers.frameworkProvider)),
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("project_id"), knownvalue.StringExact(uniq)),
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("private_key_id"), knownvalue.StringExact("1234567890123456789012345678901234567890")),
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("private_key"), knownvalue.StringExact("-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n")),
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))),
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("client_id"), knownvalue.StringExact("123456789012345678901")),
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("automute"), knownvalue.Bool(false)),
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("cspm_resource_collection_enabled"), knownvalue.Bool(false)),
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("is_security_command_center_enabled"), knownvalue.Bool(false)),
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("resource_collection_enabled"), knownvalue.Bool(true)),
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("is_resource_change_collection_enabled"), knownvalue.Bool(false)),
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("host_filters"), knownvalue.StringExact("host:one")),
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("monitored_resource_configs"), knownvalue.SetExact([]knownvalue.Check{
knownvalue.ObjectExact(map[string]knownvalue.Check{
"type": knownvalue.StringExact("gce_instance"),
"filters": knownvalue.SetExact([]knownvalue.Check{
knownvalue.StringExact("host:one"),
}),
}),
})),
},
},
{
Config: fmt.Sprintf(`
resource "datadog_integration_gcp" "awesome_gcp_project_integration" {
project_id = "%s"
private_key_id = "1234567890123456789012345678901234567890"
private_key = "-----BEGIN PRIVATE KEY-----\n key updated \n-----END PRIVATE KEY-----\n"
client_email = "%s@awesome-project-id.iam.gserviceaccount.com"
client_id = "123456789012345678901"
automute = true
monitored_resource_configs = [
{
type = "gce_instance"
filters = ["host:one"]
},
]
}`, uniq, uniq),
Check: resource.ComposeTestCheckFunc(checkIntegrationGCPExists(providers.frameworkProvider)),
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("project_id"), knownvalue.StringExact(uniq)),
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("private_key_id"), knownvalue.StringExact("1234567890123456789012345678901234567890")),
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")),
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))),
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("client_id"), knownvalue.StringExact("123456789012345678901")),
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("automute"), knownvalue.Bool(true)),
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("cspm_resource_collection_enabled"), knownvalue.Bool(false)),
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("is_security_command_center_enabled"), knownvalue.Bool(false)),
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("resource_collection_enabled"), knownvalue.Bool(true)),
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("is_resource_change_collection_enabled"), knownvalue.Bool(false)),
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("host_filters"), knownvalue.StringExact("host:one")),
statecheck.ExpectKnownValue("datadog_integration_gcp.awesome_gcp_project_integration", tfjsonpath.New("monitored_resource_configs"), knownvalue.SetExact([]knownvalue.Check{
knownvalue.ObjectExact(map[string]knownvalue.Check{
"type": knownvalue.StringExact("gce_instance"),
"filters": knownvalue.SetExact([]knownvalue.Check{
knownvalue.StringExact("host:one"),
}),
}),
})),
},
},
},
})
}

func TestAccDatadogIntegrationGCP(t *testing.T) {
t.Parallel()
ctx, providers, accProviders := testAccFrameworkMuxProviders(context.Background(), t)
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/integration_gcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ resource "datadog_integration_gcp" "awesome_gcp_project_integration" {
- `automute` (Boolean) Silence monitors for expected GCE instance shutdowns. Defaults to `false`.
- `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.
- `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`.
- `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 `""`.
- `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.
- `is_resource_change_collection_enabled` (Boolean) When enabled, Datadog scans for all resource change data in your Google Cloud environment.
- `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`.
- `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))
Expand Down
Loading