Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set ForceNew to true on non-updatable GCP resource fields #1013

Merged
merged 4 commits into from
Mar 31, 2021
Merged
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
1 change: 1 addition & 0 deletions datadog/internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
datadogV2 "github.com/DataDog/datadog-api-client-go/api/v2/datadog"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/meta"

"github.com/terraform-providers/terraform-provider-datadog/version"
)

Expand Down
14 changes: 14 additions & 0 deletions datadog/resource_datadog_integration_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,44 @@ func resourceDatadogIntegrationGcp() *schema.Resource {
Description: "Your Google Cloud project ID found in your JSON service account key.",
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"private_key_id": {
Description: "Your private key ID found in your JSON service account key.",
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"private_key": {
Description: "Your private key name found in your JSON service account key.",
Type: schema.TypeString,
Required: true,
Sensitive: true,
ForceNew: true,
},
"client_email": {
Description: "Your email found in your JSON service account key.",
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"client_id": {
Description: "Your ID found in your JSON service account key.",
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"host_filters": {
Description: "Limit the GCE instances that are pulled into Datadog by using tags. Only hosts that match one of the defined tags are imported into Datadog.",
Type: schema.TypeString,
Optional: true,
},
"automute": {
Description: "Silence monitors for expected GCE instance shutdowns.",
Type: schema.TypeBool,
Default: false,
Optional: true,
},
},
}
}
Expand Down Expand Up @@ -82,6 +93,7 @@ func resourceDatadogIntegrationGcpCreate(d *schema.ResourceData, meta interface{
AuthProviderX509CertUrl: datadogV1.PtrString(defaultAuthProviderX509CertURL),
ClientX509CertUrl: datadogV1.PtrString(defaultClientX509CertURLPrefix + d.Get("client_email").(string)),
HostFilters: datadogV1.PtrString(d.Get("host_filters").(string)),
Automute: datadogV1.PtrBool(d.Get("automute").(bool)),
},
).Execute(); err != nil {
return utils.TranslateClientError(err, "error creating GCP integration")
Expand All @@ -108,6 +120,7 @@ func resourceDatadogIntegrationGcpRead(d *schema.ResourceData, meta interface{})
d.Set("project_id", integration.GetProjectId())
d.Set("client_email", integration.GetClientEmail())
d.Set("host_filters", integration.GetHostFilters())
d.Set("automute", integration.GetAutomute())
return nil
}
}
Expand All @@ -125,6 +138,7 @@ func resourceDatadogIntegrationGcpUpdate(d *schema.ResourceData, meta interface{
ProjectId: datadogV1.PtrString(d.Id()),
ClientEmail: datadogV1.PtrString(d.Get("client_email").(string)),
HostFilters: datadogV1.PtrString(d.Get("host_filters").(string)),
Automute: datadogV1.PtrBool(d.Get("automute").(bool)),
},
).Execute(); err != nil {
return utils.TranslateClientError(err, "error updating GCP integration")
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-12-31T15:42:48.983978+01:00
2021-03-30T13:30:54.526302-04:00
498 changes: 318 additions & 180 deletions datadog/tests/cassettes/TestAccDatadogIntegrationGCP.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2021-02-11T11:22:51.33621+01:00
2021-03-30T13:48:22.326086-04:00
182 changes: 69 additions & 113 deletions datadog/tests/cassettes/TestAccDatadogLogsArchiveGCS_basic.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2021-02-11T11:22:47.402226+01:00
2021-03-30T13:48:19.618471-04:00

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions datadog/tests/resource_datadog_integration_gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ resource "datadog_integration_gcp" "awesome_gcp_project_integration" {
}`, uniq, uniq)
}

func testAccCheckDatadogIntegrationGCPUpdatePrivateKeyConfig(uniq string) string {
return 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 = "%[email protected]"
client_id = "123456789012345678901"
automute = true
}`, uniq, uniq)
}

func TestAccDatadogIntegrationGCP(t *testing.T) {
ctx, accProviders := testAccProviders(context.Background(), t)
client := uniqueEntityName(ctx, t)
Expand Down Expand Up @@ -67,6 +79,9 @@ func TestAccDatadogIntegrationGCP(t *testing.T) {
resource.TestCheckResourceAttr(
"datadog_integration_gcp.awesome_gcp_project_integration",
"host_filters", "foo:bar,buzz:lightyear"),
resource.TestCheckResourceAttr(
"datadog_integration_gcp.awesome_gcp_project_integration",
"automute", "false"),
),
},
{
Expand All @@ -91,6 +106,36 @@ func TestAccDatadogIntegrationGCP(t *testing.T) {
resource.TestCheckResourceAttr(
"datadog_integration_gcp.awesome_gcp_project_integration",
"host_filters", ""),
resource.TestCheckResourceAttr(
"datadog_integration_gcp.awesome_gcp_project_integration",
"automute", "false"),
),
},
{
Config: testAccCheckDatadogIntegrationGCPUpdatePrivateKeyConfig(client),
Check: resource.ComposeTestCheckFunc(
checkIntegrationGCPExists(accProvider),
resource.TestCheckResourceAttr(
"datadog_integration_gcp.awesome_gcp_project_integration",
"project_id", client),
resource.TestCheckResourceAttr(
"datadog_integration_gcp.awesome_gcp_project_integration",
"private_key_id", "1234567890123456789012345678901234567890"),
resource.TestCheckResourceAttr(
"datadog_integration_gcp.awesome_gcp_project_integration",
"private_key", "-----BEGIN PRIVATE KEY-----\n key updated \n-----END PRIVATE KEY-----\n"),
resource.TestCheckResourceAttr(
"datadog_integration_gcp.awesome_gcp_project_integration",
"client_email", fmt.Sprintf("%[email protected]", client)),
resource.TestCheckResourceAttr(
"datadog_integration_gcp.awesome_gcp_project_integration",
"client_id", "123456789012345678901"),
resource.TestCheckResourceAttr(
"datadog_integration_gcp.awesome_gcp_project_integration",
"host_filters", ""),
resource.TestCheckResourceAttr(
"datadog_integration_gcp.awesome_gcp_project_integration",
"automute", "true"),
),
},
},
Expand Down
1 change: 1 addition & 0 deletions docs/resources/integration_gcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ resource "datadog_integration_gcp" "awesome_gcp_project_integration" {

### Optional

- **automute** (Boolean) Silence monitors for expected GCE instance shutdowns.
- **host_filters** (String) Limit the GCE instances that are pulled into Datadog by using tags. Only hosts that match one of the defined tags are imported into Datadog.
- **id** (String) The ID of this resource.

Expand Down