From 74aed185ba7e05e1ee37a3350e6400ea8ab32c0b Mon Sep 17 00:00:00 2001 From: "Stephen Lewis (Burrows)" Date: Wed, 3 Mar 2021 16:05:03 -0800 Subject: [PATCH] Suppress diff for COS images (#4562) Co-authored-by: Marius Kintel --- mmv1/templates/terraform/constants/disk.erb | 17 +++++++++++++++++ .../tests/resource_compute_disk_test.go.erb | 5 +++++ mmv1/third_party/terraform/utils/image.go | 1 + 3 files changed, 23 insertions(+) diff --git a/mmv1/templates/terraform/constants/disk.erb b/mmv1/templates/terraform/constants/disk.erb index d170c7cb4195..7986ddce1fa1 100644 --- a/mmv1/templates/terraform/constants/disk.erb +++ b/mmv1/templates/terraform/constants/disk.erb @@ -120,6 +120,10 @@ func diskImageFamilyEquals(imageName, familyName string) bool { return true } + if suppressCosFamilyDiff(imageName, familyName) { + return true + } + if suppressWindowsSqlFamilyDiff(imageName, familyName) { return true } @@ -144,6 +148,19 @@ func suppressCanonicalFamilyDiff(imageName, familyName string) bool { return false } +// e.g. image: cos-NN-*, family: cos-NN-lts +func suppressCosFamilyDiff(imageName, familyName string) bool { + parts := cosLtsImage.FindStringSubmatch(imageName) + if len(parts) == 2 { + f := fmt.Sprintf("cos-%s-lts", parts[1]) + if f == familyName { + return true + } + } + + return false +} + // e.g. image: sql-2017-standard-windows-2016-dc-v20180109, family: sql-std-2017-win-2016 // e.g. image: sql-2017-express-windows-2012-r2-dc-v20180109, family: sql-exp-2017-win-2012-r2 func suppressWindowsSqlFamilyDiff(imageName, familyName string) bool { diff --git a/mmv1/third_party/terraform/tests/resource_compute_disk_test.go.erb b/mmv1/third_party/terraform/tests/resource_compute_disk_test.go.erb index e7ce12c1bba6..d313a9b13d45 100644 --- a/mmv1/third_party/terraform/tests/resource_compute_disk_test.go.erb +++ b/mmv1/third_party/terraform/tests/resource_compute_disk_test.go.erb @@ -127,6 +127,11 @@ func TestDiskImageDiffSuppress(t *testing.T) { New: "ubuntu-minimal-1804-lts", ExpectDiffSuppress: true, }, + "matching unconventional image family - cos": { + Old: "https://www.googleapis.com/compute/v1/projects/cos-cloud/global/images/cos-85-13310-1209-17", + New: "cos-85-lts", + ExpectDiffSuppress: true, + }, "different image family": { Old: "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-8-jessie-v20171213", New: "family/debian-7", diff --git a/mmv1/third_party/terraform/utils/image.go b/mmv1/third_party/terraform/utils/image.go index 61ac117dc9e7..ad90c55cef83 100644 --- a/mmv1/third_party/terraform/utils/image.go +++ b/mmv1/third_party/terraform/utils/image.go @@ -27,6 +27,7 @@ var ( windowsSqlImage = regexp.MustCompile("^sql-(?:server-)?([0-9]{4})-([a-z]+)-windows-(?:server-)?([0-9]{4})(?:-r([0-9]+))?-dc-v[0-9]+$") canonicalUbuntuLtsImage = regexp.MustCompile("^ubuntu-(minimal-)?([0-9]+)-") + cosLtsImage = regexp.MustCompile("^cos-([0-9]+)-") ) // built-in projects to look for images/families containing the string