diff --git a/mmv1/products/cloudscheduler/terraform.yaml b/mmv1/products/cloudscheduler/terraform.yaml index 32a92483b6ef..68a56dca983f 100644 --- a/mmv1/products/cloudscheduler/terraform.yaml +++ b/mmv1/products/cloudscheduler/terraform.yaml @@ -63,6 +63,8 @@ overrides: !ruby/object:Overrides::ResourceOverrides diff_suppress_func: 'authHeaderDiffSuppress' httpTarget.oidcToken: !ruby/object:Overrides::Terraform::PropertyOverride diff_suppress_func: 'authHeaderDiffSuppress' + httpTarget.uri: !ruby/object:Overrides::Terraform::PropertyOverride + diff_suppress_func: 'lastSlashDiffSuppress' appEngineHttpTarget.headers: !ruby/object:Overrides::Terraform::PropertyOverride custom_flatten: 'templates/terraform/custom_flatten/http_headers.erb' validation: !ruby/object:Provider::Terraform::Validation diff --git a/mmv1/third_party/terraform/utils/common_diff_suppress.go.erb b/mmv1/third_party/terraform/utils/common_diff_suppress.go.erb index 0794200e38ac..b9d5d3302dad 100644 --- a/mmv1/third_party/terraform/utils/common_diff_suppress.go.erb +++ b/mmv1/third_party/terraform/utils/common_diff_suppress.go.erb @@ -213,3 +213,17 @@ func compareOptionalSubnet(_, old, new string, _ *schema.ResourceData) bool { // otherwise compare as self links return compareSelfLinkOrResourceName("", old, new, nil) } + +// Suppress diffs in below cases +// "https://hello-rehvs75zla-uc.a.run.app/" -> "https://hello-rehvs75zla-uc.a.run.app" +// "https://hello-rehvs75zla-uc.a.run.app" -> "https://hello-rehvs75zla-uc.a.run.app/" +func lastSlashDiffSuppress(_, old, new string, _ *schema.ResourceData) bool { + if last := len(new) - 1; last >= 0 && new[last] == '/' { + new = new[:last] + } + + if last := len(old) - 1; last >= 0 && old[last] == '/' { + old = old[:last] + } + return new == old +} \ No newline at end of file diff --git a/mmv1/third_party/terraform/utils/common_diff_suppress_test.go.erb b/mmv1/third_party/terraform/utils/common_diff_suppress_test.go.erb index ef4c3f74a730..1e7f2d5d66b8 100644 --- a/mmv1/third_party/terraform/utils/common_diff_suppress_test.go.erb +++ b/mmv1/third_party/terraform/utils/common_diff_suppress_test.go.erb @@ -285,3 +285,42 @@ func TestDurationDiffSuppress(t *testing.T) { } } } + +func TestLastSlashDiffSuppress(t *testing.T) { + cases := map[string]struct { + Old, New string + ExpectDiffSuppress bool + }{ + "slash to no slash": { + Old: "https://hello-rehvs75zla-uc.a.run.app/", + New: "https://hello-rehvs75zla-uc.a.run.app", + ExpectDiffSuppress: true, + }, + "no slash to slash": { + Old: "https://hello-rehvs75zla-uc.a.run.app", + New: "https://hello-rehvs75zla-uc.a.run.app/", + ExpectDiffSuppress: true, + }, + "slash to slash": { + Old: "https://hello-rehvs75zla-uc.a.run.app/", + New: "https://hello-rehvs75zla-uc.a.run.app/", + ExpectDiffSuppress: true, + }, + "no slash to no slash": { + Old: "https://hello-rehvs75zla-uc.a.run.app", + New: "https://hello-rehvs75zla-uc.a.run.app", + ExpectDiffSuppress: true, + }, + "different domains": { + Old: "https://x.a.run.app/", + New: "https://y.a.run.app", + ExpectDiffSuppress: false, + }, + } + + for tn, tc := range cases { + if lastSlashDiffSuppress("uri", tc.Old, tc.New, nil) != tc.ExpectDiffSuppress { + t.Fatalf("bad: %s, '%s' => '%s' expect %t", tn, tc.Old, tc.New, tc.ExpectDiffSuppress) + } + } +} \ No newline at end of file