From be79911b48fcdbf23a96c22ae782f281cba5b7b2 Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 7 Nov 2022 11:57:53 -0800 Subject: [PATCH] Added handling of amd64 images on compute disk (#6769) (#12961) * Added handling of amd64 images on compute disk * Removed Test Cases from the TestDiskImageDiffSuppress * Added test cases for amd64 images Signed-off-by: Modular Magician Signed-off-by: Modular Magician --- .changelog/6769.txt | 3 +++ google/resource_compute_disk.go | 13 ++++++++++++ google/resource_compute_disk_test.go | 31 ++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 .changelog/6769.txt diff --git a/.changelog/6769.txt b/.changelog/6769.txt new file mode 100644 index 0000000000..4277d7f27d --- /dev/null +++ b/.changelog/6769.txt @@ -0,0 +1,3 @@ +```release-note:bug +compute: fixed perma-diff on `google_compute_disk` for new amd64 images +``` diff --git a/google/resource_compute_disk.go b/google/resource_compute_disk.go index 0a7bbdf5cc..7eee441fcd 100644 --- a/google/resource_compute_disk.go +++ b/google/resource_compute_disk.go @@ -151,6 +151,19 @@ func diskImageEquals(oldImageName, newImageName string) bool { func diskImageFamilyEquals(imageName, familyName string) bool { // Handles the case when the image name includes the family name // e.g. image name: debian-11-bullseye-v20220719, family name: debian-11 + + // First condition is to check if image contains arm64 because of case like: + // image name: opensuse-leap-15-4-v20220713-arm64, family name: opensuse-leap (should not be evaluated during handling of amd64 cases) + // In second condition, we have to check for amd64 because of cases like: + // image name: ubuntu-2210-kinetic-amd64-v20221022, family name: ubuntu-2210 (should not suppress) + if !strings.Contains(imageName, "-arm64") && strings.Contains(imageName, strings.TrimSuffix(familyName, "-amd64")) { + if strings.Contains(imageName, "-amd64") { + return strings.HasSuffix(familyName, "-amd64") + } else { + return !strings.HasSuffix(familyName, "-amd64") + } + } + // We have to check for arm64 because of cases like: // image name: opensuse-leap-15-4-v20220713-arm64, family name: opensuse-leap (should not suppress) if strings.Contains(imageName, strings.TrimSuffix(familyName, "-arm64")) { diff --git a/google/resource_compute_disk_test.go b/google/resource_compute_disk_test.go index a15591510f..c2e89cd14d 100644 --- a/google/resource_compute_disk_test.go +++ b/google/resource_compute_disk_test.go @@ -247,6 +247,37 @@ func TestDiskImageDiffSuppress(t *testing.T) { New: "debian-11-arm64", ExpectDiffSuppress: false, }, + // amd images + "matching image ubuntu amd64 self_link": { + Old: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-2210-kinetic-amd64-v20221022", + New: "ubuntu-2210-amd64", + ExpectDiffSuppress: true, + }, + "matching image ubuntu-minimal amd64 self_link": { + Old: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-minimal-2210-kinetic-amd64-v20221022", + New: "ubuntu-minimal-2210-amd64", + ExpectDiffSuppress: true, + }, + "different architecture image ubuntu amd64 self_link": { + Old: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-2210-kinetic-amd64-v20221022", + New: "ubuntu-2210", + ExpectDiffSuppress: false, + }, + "different architecture image ubuntu-minimal amd64 self_link": { + Old: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-minimal-2210-kinetic-amd64-v20221022", + New: "ubuntu-minimal-2210", + ExpectDiffSuppress: false, + }, + "different architecture image ubuntu amd64 family": { + Old: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-2210-kinetic-v20221022", + New: "ubuntu-2210-amd64", + ExpectDiffSuppress: false, + }, + "different architecture image ubuntu-minimal amd64 family": { + Old: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-minimal-2210-kinetic-v20221022", + New: "ubuntu-minimal-2210-amd64", + ExpectDiffSuppress: false, + }, } for tn, tc := range cases {