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

Updated labels for cloud run domain mapping diff suppress #8971

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/4720.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
cloudrun: fixed permadiff on `google_cloud_run_domain_mapping.metadata.labels`
```
13 changes: 9 additions & 4 deletions google/resource_cloud_run_domain_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ import (
"google.golang.org/api/googleapi"
)

const domainMappingGoogleProvidedLabel = "cloud.googleapis.com/location"
var domainMappingGoogleProvidedLabels = []string{
"cloud.googleapis.com/location",
"run.googleapis.com/overrideAt",
}

func domainMappingLabelDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
// Suppress diffs for the label provided by Google
if strings.Contains(k, domainMappingGoogleProvidedLabel) && new == "" {
return true
// Suppress diffs for the labels provided by Google
for _, label := range domainMappingGoogleProvidedLabels {
if strings.Contains(k, label) && new == "" {
return true
}
}

// Let diff be determined by labels (above)
Expand Down
55 changes: 55 additions & 0 deletions google/resource_cloud_run_domain_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,61 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestDomainMappingLabelDiffSuppress(t *testing.T) {
cases := map[string]struct {
K, Old, New string
ExpectDiffSuppress bool
}{
"missing run.googleapis.com/overrideAt": {
K: "metadata.0.labels.run.googleapis.com/overrideAt",
Old: "2021-04-20T22:38:23.584Z",
New: "",
ExpectDiffSuppress: true,
},
"explicit run.googleapis.com/overrideAt": {
K: "metadata.0.labels.run.googleapis.com/overrideAt",
Old: "2021-04-20T22:38:23.584Z",
New: "2022-04-20T22:38:23.584Z",
ExpectDiffSuppress: false,
},
"missing cloud.googleapis.com/location": {
K: "metadata.0.labels.cloud.googleapis.com/location",
Old: "us-central1",
New: "",
ExpectDiffSuppress: true,
},
"explicit cloud.googleapis.com/location": {
K: "metadata.0.labels.cloud.googleapis.com/location",
Old: "us-central1",
New: "us-central2",
ExpectDiffSuppress: false,
},
"labels.%": {
K: "metadata.0.labels.%",
Old: "3",
New: "1",
ExpectDiffSuppress: true,
},
"deleted custom key": {
K: "metadata.0.labels.my-label",
Old: "my-value",
New: "",
ExpectDiffSuppress: false,
},
"added custom key": {
K: "metadata.0.labels.my-label",
Old: "",
New: "my-value",
ExpectDiffSuppress: false,
},
}
for tn, tc := range cases {
if domainMappingLabelDiffSuppress(tc.K, tc.Old, tc.New, nil) != tc.ExpectDiffSuppress {
t.Errorf("bad: %s, %q: %q => %q expect DiffSuppress to return %t", tn, tc.K, tc.Old, tc.New, tc.ExpectDiffSuppress)
}
}
}

// Destroy and recreate the mapping, testing that Terraform doesn't return a 409
func TestAccCloudRunDomainMapping_foregroundDeletion(t *testing.T) {
t.Parallel()
Expand Down