From 730b9cde419d5936ac1bea40f465c3085c843efd Mon Sep 17 00:00:00 2001 From: himanikh Date: Wed, 18 Dec 2024 21:23:03 +0000 Subject: [PATCH 1/8] suppressing Project id vs project number diff in forwardingRule.target --- mmv1/products/compute/ForwardingRule.yaml | 2 +- .../tpgresource/common_diff_suppress.go.tmpl | 14 +++- .../tpgresource/common_diff_suppress_test.go | 29 +++++++++ .../tpgresource/self_link_helpers.go | 19 +++++- .../tpgresource/self_link_helpers_test.go | 64 +++++++++++++++++++ 5 files changed, 125 insertions(+), 3 deletions(-) diff --git a/mmv1/products/compute/ForwardingRule.yaml b/mmv1/products/compute/ForwardingRule.yaml index 5dfc75b43ed6..bc2f08622746 100644 --- a/mmv1/products/compute/ForwardingRule.yaml +++ b/mmv1/products/compute/ForwardingRule.yaml @@ -492,7 +492,7 @@ properties: For Private Service Connect forwarding rules that forward traffic to managed services, the target must be a service attachment. update_url: 'projects/{{project}}/regions/{{region}}/forwardingRules/{{name}}/setTarget' update_verb: 'POST' - diff_suppress_func: 'tpgresource.CompareSelfLinkRelativePaths' + diff_suppress_func: 'tpgresource.CompareSelfLinkRelativePathsIgnoreProjectId' custom_expand: 'templates/terraform/custom_expand/self_link_from_name.tmpl' - name: 'labelFingerprint' type: Fingerprint diff --git a/mmv1/third_party/terraform/tpgresource/common_diff_suppress.go.tmpl b/mmv1/third_party/terraform/tpgresource/common_diff_suppress.go.tmpl index 70763fdd58da..fe482095b121 100644 --- a/mmv1/third_party/terraform/tpgresource/common_diff_suppress.go.tmpl +++ b/mmv1/third_party/terraform/tpgresource/common_diff_suppress.go.tmpl @@ -101,6 +101,18 @@ func ProjectNumberDiffSuppress(_, old, new string, _ *schema.ResourceData) bool return a2 == b2 } +// Suppress diffs when the value read from api +// has the project id instead of the project number +func ProjectIDDiffSuppress(_, old, new string, _ *schema.ResourceData) bool { + var a2, b2 string + re := regexp.MustCompile("projects/\\d+") + reN := regexp.MustCompile("projects/[^/]+") + replacement := []byte("projects/equal") + a2 = string(reN.ReplaceAll([]byte(old), replacement)) + b2 = string(re.ReplaceAll([]byte(new), replacement)) + return a2 == b2 +} + func IsNewResource(diff TerraformResourceDiff) bool { name := diff.Get("name") return name.(string) == "" @@ -121,4 +133,4 @@ func CompareCryptoKeyVersions(_, old, new string, _ *schema.ResourceData) bool { func CidrOrSizeDiffSuppress(k, old, new string, d *schema.ResourceData) bool { // If the user specified a size and the API returned a full cidr block, suppress. return strings.HasPrefix(new, "/") && strings.HasSuffix(old, new) -} \ No newline at end of file +} diff --git a/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go b/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go index 3cb2ef2d21c6..3d0655328afc 100644 --- a/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go +++ b/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go @@ -67,6 +67,35 @@ func TestDurationDiffSuppress(t *testing.T) { } } +func TestProjectIDDiffSuppress(t *testing.T) { + cases := map[string]struct { + Old, New string + ExpectDiffSuppress bool + }{ + "different project identifiers": { + Old: "projects/ten-tp/locations/abc/serviceAttachments/xyz", + New: "projects/1234/locations/abc/serviceAttachments/xyz", + ExpectDiffSuppress: yes, + }, + "same values": { + Old: "projects/ten-tp/locations/abc/serviceAttachments/xyz", + New: "projects/ten-tp/locations/abc/serviceAttachments/xyz", + ExpectDiffSuppress: true, + }, + "different resources": { + Old: "projects/ten-tp/locations/abc/serviceAttachments/xyz", + New: "projects/1234/locations/abc/serviceAttachments/jkl", + ExpectDiffSuppress: false, + }, + } + + for tn, tc := range cases { + if ProjectIDDiffSuppress(tc.Old, tc.New, nil) != tc.ExpectDiffSuppress { + t.Fatalf("bad: %s, '%s' => '%s' expect %t", tn, tc.Old, tc.New, tc.ExpectDiffSuppress) + } + } +} + func TestEmptyOrUnsetBlockDiffSuppress(t *testing.T) { cases := map[string]struct { Key, Old, New string diff --git a/mmv1/third_party/terraform/tpgresource/self_link_helpers.go b/mmv1/third_party/terraform/tpgresource/self_link_helpers.go index 5e28a562a2d9..997a23e3c9f5 100644 --- a/mmv1/third_party/terraform/tpgresource/self_link_helpers.go +++ b/mmv1/third_party/terraform/tpgresource/self_link_helpers.go @@ -17,7 +17,7 @@ func CompareResourceNames(_, old, new string, _ *schema.ResourceData) bool { } // Compare only the relative path of two self links. -func CompareSelfLinkRelativePaths(_, old, new string, _ *schema.ResourceData) bool { +func CompareSelfLinkRelativePathsIgnoreProjectId(_, old, new string, r *schema.ResourceData) bool { oldStripped, err := GetRelativePath(old) if err != nil { return false @@ -31,7 +31,24 @@ func CompareSelfLinkRelativePaths(_, old, new string, _ *schema.ResourceData) bo if oldStripped == newStripped { return true } + return ProjectIDDiffSuppress(oldStripped, newStripped, r) +} + +// Compare only the relative path of two self links. +func CompareSelfLinkRelativePaths(_, old, new string, _ *schema.ResourceData) bool { + oldStripped, err := GetRelativePath(old) + if err != nil { + return false + } + newStripped, err := GetRelativePath(new) + if err != nil { + return false + } + + if oldStripped == newStripped { + return true + } return false } diff --git a/mmv1/third_party/terraform/tpgresource/self_link_helpers_test.go b/mmv1/third_party/terraform/tpgresource/self_link_helpers_test.go index d640202c8b52..301537335cec 100644 --- a/mmv1/third_party/terraform/tpgresource/self_link_helpers_test.go +++ b/mmv1/third_party/terraform/tpgresource/self_link_helpers_test.go @@ -66,6 +66,70 @@ func TestCompareSelfLinkOrResourceName(t *testing.T) { } } +func CompareSelfLinkRelativePathsIgnoreProjectId(t *testing.T) { + cases := map[string]struct { + Old, New string + Expect bool + }{ + "full path, project number": { + Old: "https://www.googleapis.com/compute/v1/projects/your-project/global/networks/a-network", + New: "https://www.googleapis.com/compute/v1/projects/1234/global/networks/a-network", + Expect: true, + }, + "partial path, project number": { + Old: "https://www.googleapis.com/compute/v1/projects/your-project/global/networks/a-network", + New: "projects/1234/global/networks/a-network", + Expect: true, + }, + "partial path, same": { + Old: "https://www.googleapis.com/compute/v1/projects/your-project/global/networks/a-network", + New: "projects/your-project/global/networks/a-network", + Expect: true, + }, + "partial path, different name": { + Old: "https://www.googleapis.com/compute/v1/projects/your-project/global/networks/a-network", + New: "projects/your-project/global/networks/another-network", + Expect: false, + }, + "partial path, different project": { + Old: "https://www.googleapis.com/compute/v1/projects/your-project/global/networks/a-network", + New: "projects/another-project/global/networks/a-network", + Expect: false, + }, + "full path, different name": { + Old: "https://www.googleapis.com/compute/v1/projects/your-project/global/networks/a-network", + New: "https://www.googleapis.com/compute/v1/projects/your-project/global/networks/another-network", + Expect: false, + }, + "full path, different project": { + Old: "https://www.googleapis.com/compute/v1/projects/your-project/global/networks/a-network", + New: "https://www.googleapis.com/compute/v1/projects/another-project/global/networks/a-network", + Expect: false, + }, + "beta full path, same": { + Old: "https://www.googleapis.com/compute/v1/projects/your-project/global/networks/a-network", + New: "https://www.googleapis.com/compute/beta/projects/your-project/global/networks/a-network", + Expect: true, + }, + "beta full path, different name": { + Old: "https://www.googleapis.com/compute/v1/projects/your-project/global/networks/a-network", + New: "https://www.googleapis.com/compute/beta/projects/your-project/global/networks/another-network", + Expect: false, + }, + "beta full path, different project": { + Old: "https://www.googleapis.com/compute/v1/projects/your-project/global/networks/a-network", + New: "https://www.googleapis.com/compute/beta/projects/another-project/global/networks/a-network", + Expect: false, + }, + } + + for tn, tc := range cases { + if CompareSelfLinkOrResourceName("", tc.Old, tc.New, nil) != tc.Expect { + t.Errorf("bad: %s, expected %t for old = %q and new = %q", tn, tc.Expect, tc.Old, tc.New) + } + } +} + func TestGetResourceNameFromSelfLink(t *testing.T) { cases := map[string]struct { SelfLink, ExpectedName string From baa5b4a2916ace34ac7007ca3a634a0bf5ae18e8 Mon Sep 17 00:00:00 2001 From: himanikh Date: Wed, 18 Dec 2024 21:37:57 +0000 Subject: [PATCH 2/8] fixes --- .../terraform/tpgresource/common_diff_suppress_test.go | 2 +- mmv1/third_party/terraform/tpgresource/self_link_helpers.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go b/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go index 3d0655328afc..e7c8b0b23c1a 100644 --- a/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go +++ b/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go @@ -90,7 +90,7 @@ func TestProjectIDDiffSuppress(t *testing.T) { } for tn, tc := range cases { - if ProjectIDDiffSuppress(tc.Old, tc.New, nil) != tc.ExpectDiffSuppress { + if ProjectIDDiffSuppress("diffSuppress", tc.Old, tc.New, nil) != tc.ExpectDiffSuppress { t.Fatalf("bad: %s, '%s' => '%s' expect %t", tn, tc.Old, tc.New, tc.ExpectDiffSuppress) } } diff --git a/mmv1/third_party/terraform/tpgresource/self_link_helpers.go b/mmv1/third_party/terraform/tpgresource/self_link_helpers.go index 997a23e3c9f5..186772c1cd21 100644 --- a/mmv1/third_party/terraform/tpgresource/self_link_helpers.go +++ b/mmv1/third_party/terraform/tpgresource/self_link_helpers.go @@ -17,7 +17,7 @@ func CompareResourceNames(_, old, new string, _ *schema.ResourceData) bool { } // Compare only the relative path of two self links. -func CompareSelfLinkRelativePathsIgnoreProjectId(_, old, new string, r *schema.ResourceData) bool { +func CompareSelfLinkRelativePathsIgnoreProjectId(unused1, old, new string, unused2 *schema.ResourceData) bool { oldStripped, err := GetRelativePath(old) if err != nil { return false @@ -31,7 +31,7 @@ func CompareSelfLinkRelativePathsIgnoreProjectId(_, old, new string, r *schema.R if oldStripped == newStripped { return true } - return ProjectIDDiffSuppress(oldStripped, newStripped, r) + return ProjectIDDiffSuppress(unused1, oldStripped, newStripped, unused2) } // Compare only the relative path of two self links. From ca21c7038d0d194534b8357252ab3be815eced95 Mon Sep 17 00:00:00 2001 From: himanikh Date: Wed, 18 Dec 2024 22:00:20 +0000 Subject: [PATCH 3/8] fixes --- .../terraform/tpgresource/common_diff_suppress_test.go | 2 +- .../third_party/terraform/tpgresource/self_link_helpers_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go b/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go index e7c8b0b23c1a..8054d9586366 100644 --- a/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go +++ b/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go @@ -75,7 +75,7 @@ func TestProjectIDDiffSuppress(t *testing.T) { "different project identifiers": { Old: "projects/ten-tp/locations/abc/serviceAttachments/xyz", New: "projects/1234/locations/abc/serviceAttachments/xyz", - ExpectDiffSuppress: yes, + ExpectDiffSuppress: true, }, "same values": { Old: "projects/ten-tp/locations/abc/serviceAttachments/xyz", diff --git a/mmv1/third_party/terraform/tpgresource/self_link_helpers_test.go b/mmv1/third_party/terraform/tpgresource/self_link_helpers_test.go index 301537335cec..5daede238d62 100644 --- a/mmv1/third_party/terraform/tpgresource/self_link_helpers_test.go +++ b/mmv1/third_party/terraform/tpgresource/self_link_helpers_test.go @@ -66,7 +66,7 @@ func TestCompareSelfLinkOrResourceName(t *testing.T) { } } -func CompareSelfLinkRelativePathsIgnoreProjectId(t *testing.T) { +func TestCompareSelfLinkRelativePathsIgnoreProjectId(t *testing.T) { cases := map[string]struct { Old, New string Expect bool From bf775009bf7902a97242690773d21378c19452aa Mon Sep 17 00:00:00 2001 From: himanikh Date: Thu, 19 Dec 2024 00:45:45 +0000 Subject: [PATCH 4/8] fixes --- .../terraform/tpgresource/common_diff_suppress_test.go | 5 ----- mmv1/third_party/terraform/tpgresource/self_link_helpers.go | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go b/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go index 8054d9586366..49b8189eda6f 100644 --- a/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go +++ b/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go @@ -77,11 +77,6 @@ func TestProjectIDDiffSuppress(t *testing.T) { New: "projects/1234/locations/abc/serviceAttachments/xyz", ExpectDiffSuppress: true, }, - "same values": { - Old: "projects/ten-tp/locations/abc/serviceAttachments/xyz", - New: "projects/ten-tp/locations/abc/serviceAttachments/xyz", - ExpectDiffSuppress: true, - }, "different resources": { Old: "projects/ten-tp/locations/abc/serviceAttachments/xyz", New: "projects/1234/locations/abc/serviceAttachments/jkl", diff --git a/mmv1/third_party/terraform/tpgresource/self_link_helpers.go b/mmv1/third_party/terraform/tpgresource/self_link_helpers.go index 186772c1cd21..845c5549c958 100644 --- a/mmv1/third_party/terraform/tpgresource/self_link_helpers.go +++ b/mmv1/third_party/terraform/tpgresource/self_link_helpers.go @@ -31,7 +31,7 @@ func CompareSelfLinkRelativePathsIgnoreProjectId(unused1, old, new string, unuse if oldStripped == newStripped { return true } - return ProjectIDDiffSuppress(unused1, oldStripped, newStripped, unused2) + return ProjectNumberDiffSuppress(unused1, oldStripped, newStripped, unused2) } // Compare only the relative path of two self links. From 8b64a9b954267f046b67b847314efb762ddd272a Mon Sep 17 00:00:00 2001 From: himanikh Date: Thu, 19 Dec 2024 00:46:13 +0000 Subject: [PATCH 5/8] fixes --- .../tpgresource/common_diff_suppress.go.tmpl | 14 +---------- .../tpgresource/common_diff_suppress_test.go | 24 ------------------- 2 files changed, 1 insertion(+), 37 deletions(-) diff --git a/mmv1/third_party/terraform/tpgresource/common_diff_suppress.go.tmpl b/mmv1/third_party/terraform/tpgresource/common_diff_suppress.go.tmpl index fe482095b121..70763fdd58da 100644 --- a/mmv1/third_party/terraform/tpgresource/common_diff_suppress.go.tmpl +++ b/mmv1/third_party/terraform/tpgresource/common_diff_suppress.go.tmpl @@ -101,18 +101,6 @@ func ProjectNumberDiffSuppress(_, old, new string, _ *schema.ResourceData) bool return a2 == b2 } -// Suppress diffs when the value read from api -// has the project id instead of the project number -func ProjectIDDiffSuppress(_, old, new string, _ *schema.ResourceData) bool { - var a2, b2 string - re := regexp.MustCompile("projects/\\d+") - reN := regexp.MustCompile("projects/[^/]+") - replacement := []byte("projects/equal") - a2 = string(reN.ReplaceAll([]byte(old), replacement)) - b2 = string(re.ReplaceAll([]byte(new), replacement)) - return a2 == b2 -} - func IsNewResource(diff TerraformResourceDiff) bool { name := diff.Get("name") return name.(string) == "" @@ -133,4 +121,4 @@ func CompareCryptoKeyVersions(_, old, new string, _ *schema.ResourceData) bool { func CidrOrSizeDiffSuppress(k, old, new string, d *schema.ResourceData) bool { // If the user specified a size and the API returned a full cidr block, suppress. return strings.HasPrefix(new, "/") && strings.HasSuffix(old, new) -} +} \ No newline at end of file diff --git a/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go b/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go index 49b8189eda6f..3cb2ef2d21c6 100644 --- a/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go +++ b/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go @@ -67,30 +67,6 @@ func TestDurationDiffSuppress(t *testing.T) { } } -func TestProjectIDDiffSuppress(t *testing.T) { - cases := map[string]struct { - Old, New string - ExpectDiffSuppress bool - }{ - "different project identifiers": { - Old: "projects/ten-tp/locations/abc/serviceAttachments/xyz", - New: "projects/1234/locations/abc/serviceAttachments/xyz", - ExpectDiffSuppress: true, - }, - "different resources": { - Old: "projects/ten-tp/locations/abc/serviceAttachments/xyz", - New: "projects/1234/locations/abc/serviceAttachments/jkl", - ExpectDiffSuppress: false, - }, - } - - for tn, tc := range cases { - if ProjectIDDiffSuppress("diffSuppress", tc.Old, tc.New, nil) != tc.ExpectDiffSuppress { - t.Fatalf("bad: %s, '%s' => '%s' expect %t", tn, tc.Old, tc.New, tc.ExpectDiffSuppress) - } - } -} - func TestEmptyOrUnsetBlockDiffSuppress(t *testing.T) { cases := map[string]struct { Key, Old, New string From fcded65034903be382f676ca5ed5407700b5b533 Mon Sep 17 00:00:00 2001 From: himanikh Date: Thu, 19 Dec 2024 01:18:47 +0000 Subject: [PATCH 6/8] fixes --- .../third_party/terraform/tpgresource/self_link_helpers_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/third_party/terraform/tpgresource/self_link_helpers_test.go b/mmv1/third_party/terraform/tpgresource/self_link_helpers_test.go index 5daede238d62..b102689e3409 100644 --- a/mmv1/third_party/terraform/tpgresource/self_link_helpers_test.go +++ b/mmv1/third_party/terraform/tpgresource/self_link_helpers_test.go @@ -124,7 +124,7 @@ func TestCompareSelfLinkRelativePathsIgnoreProjectId(t *testing.T) { } for tn, tc := range cases { - if CompareSelfLinkOrResourceName("", tc.Old, tc.New, nil) != tc.Expect { + if CompareSelfLinkRelativePathsIgnoreProjectId("", tc.Old, tc.New, nil) != tc.Expect { t.Errorf("bad: %s, expected %t for old = %q and new = %q", tn, tc.Expect, tc.Old, tc.New) } } From d8dac3ca695884447eff5e742a1f7cba8c843544 Mon Sep 17 00:00:00 2001 From: himanikh Date: Thu, 19 Dec 2024 03:38:11 +0000 Subject: [PATCH 7/8] fixes --- .../terraform/tpgresource/common_diff_suppress.go.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mmv1/third_party/terraform/tpgresource/common_diff_suppress.go.tmpl b/mmv1/third_party/terraform/tpgresource/common_diff_suppress.go.tmpl index 70763fdd58da..8469277e4dde 100644 --- a/mmv1/third_party/terraform/tpgresource/common_diff_suppress.go.tmpl +++ b/mmv1/third_party/terraform/tpgresource/common_diff_suppress.go.tmpl @@ -96,8 +96,8 @@ func ProjectNumberDiffSuppress(_, old, new string, _ *schema.ResourceData) bool reN := regexp.MustCompile("projects/\\d+") re := regexp.MustCompile("projects/[^/]+") replacement := []byte("projects/equal") - a2 = string(reN.ReplaceAll([]byte(old), replacement)) - b2 = string(re.ReplaceAll([]byte(new), replacement)) + a2 = string(re.ReplaceAll([]byte(old), replacement)) + b2 = string(reN.ReplaceAll([]byte(new), replacement)) return a2 == b2 } From ba9084bef6de03f09d395173b0a3afdafa81758c Mon Sep 17 00:00:00 2001 From: himanikh Date: Thu, 26 Dec 2024 19:34:46 +0000 Subject: [PATCH 8/8] fixes --- .../tpgresource/common_diff_suppress.go.tmpl | 14 +++++- .../tpgresource/common_diff_suppress_test.go | 47 +++++++++++++++++++ .../tpgresource/self_link_helpers.go | 2 +- 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/mmv1/third_party/terraform/tpgresource/common_diff_suppress.go.tmpl b/mmv1/third_party/terraform/tpgresource/common_diff_suppress.go.tmpl index 8469277e4dde..d7ed7e3926d2 100644 --- a/mmv1/third_party/terraform/tpgresource/common_diff_suppress.go.tmpl +++ b/mmv1/third_party/terraform/tpgresource/common_diff_suppress.go.tmpl @@ -93,8 +93,20 @@ func DurationDiffSuppress(k, old, new string, d *schema.ResourceData) bool { // has the project number instead of the project name func ProjectNumberDiffSuppress(_, old, new string, _ *schema.ResourceData) bool { var a2, b2 string - reN := regexp.MustCompile("projects/\\d+") + re := regexp.MustCompile("projects/\\d+") + reN := regexp.MustCompile("projects/[^/]+") + replacement := []byte("projects/equal") + a2 = string(re.ReplaceAll([]byte(old), replacement)) + b2 = string(reN.ReplaceAll([]byte(new), replacement)) + return a2 == b2 +} + +// Suppress diffs when the value read from api +// has the project ID instead of the project number +func ProjectIDDiffSuppress(_, old, new string, _ *schema.ResourceData) bool { + var a2, b2 string re := regexp.MustCompile("projects/[^/]+") + reN := regexp.MustCompile("projects/\\d+") replacement := []byte("projects/equal") a2 = string(re.ReplaceAll([]byte(old), replacement)) b2 = string(reN.ReplaceAll([]byte(new), replacement)) diff --git a/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go b/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go index 3cb2ef2d21c6..90be0b54264f 100644 --- a/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go +++ b/mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go @@ -67,6 +67,53 @@ func TestDurationDiffSuppress(t *testing.T) { } } +func TestProjectNumberDiffSuppress(t *testing.T) { + cases := map[string]struct { + Old, New string + ExpectDiffSuppress bool + }{ + "different project identifiers": { + Old: "projects/1234/locations/abc/serviceAttachments/xyz", + New: "projects/ten-tp/locations/abc/serviceAttachments/xyz", + ExpectDiffSuppress: true, + }, + "different resources": { + Old: "projects/1234/locations/abc/serviceAttachments/jkl", + New: "projects/ten-tp/locations/abc/serviceAttachments/xyz", + ExpectDiffSuppress: false, + }, + } + + for tn, tc := range cases { + if ProjectNumberDiffSuppress("diffSuppress", tc.Old, tc.New, nil) != tc.ExpectDiffSuppress { + t.Fatalf("bad: %s, '%s' => '%s' expect %t", tn, tc.Old, tc.New, tc.ExpectDiffSuppress) + } + } +} + +func TestProjectIDDiffSuppress(t *testing.T) { + cases := map[string]struct { + Old, New string + ExpectDiffSuppress bool + }{ + "different project identifiers": { + Old: "projects/ten-tp/locations/abc/serviceAttachments/xyz", + New: "projects/1234/locations/abc/serviceAttachments/xyz", + ExpectDiffSuppress: true, + }, + "different resources": { + Old: "projects/ten-tp/locations/abc/serviceAttachments/xyz", + New: "projects/1234/locations/abc/serviceAttachments/jkl", + ExpectDiffSuppress: false, + }, + } + + for tn, tc := range cases { + if ProjectIDDiffSuppress("diffSuppress", tc.Old, tc.New, nil) != tc.ExpectDiffSuppress { + t.Fatalf("bad: %s, '%s' => '%s' expect %t", tn, tc.Old, tc.New, tc.ExpectDiffSuppress) + } + } +} func TestEmptyOrUnsetBlockDiffSuppress(t *testing.T) { cases := map[string]struct { Key, Old, New string diff --git a/mmv1/third_party/terraform/tpgresource/self_link_helpers.go b/mmv1/third_party/terraform/tpgresource/self_link_helpers.go index 845c5549c958..186772c1cd21 100644 --- a/mmv1/third_party/terraform/tpgresource/self_link_helpers.go +++ b/mmv1/third_party/terraform/tpgresource/self_link_helpers.go @@ -31,7 +31,7 @@ func CompareSelfLinkRelativePathsIgnoreProjectId(unused1, old, new string, unuse if oldStripped == newStripped { return true } - return ProjectNumberDiffSuppress(unused1, oldStripped, newStripped, unused2) + return ProjectIDDiffSuppress(unused1, oldStripped, newStripped, unused2) } // Compare only the relative path of two self links.