diff --git a/google/image.go b/google/image.go index dc0c0f56..3d733e47 100644 --- a/google/image.go +++ b/google/image.go @@ -26,7 +26,7 @@ var ( resolveImageLink = regexp.MustCompile(fmt.Sprintf("^https://www.googleapis.com/compute/[a-z0-9]+/projects/(%s)/global/images/(%s)", ProjectRegex, resolveImageImageRegex)) windowsSqlImage = regexp.MustCompile("^sql-([0-9]{4})-([a-z]+)-windows-([0-9]{4})(?:-r([0-9]+))?-dc-v[0-9]+$") - canonicalUbuntuLtsImage = regexp.MustCompile("^ubuntu-([0-9]+)-") + canonicalUbuntuLtsImage = regexp.MustCompile("^ubuntu-(minimal-)?([0-9]+)-") ) // built-in projects to look for images/families containing the string diff --git a/google/resource_compute_disk.go b/google/resource_compute_disk.go index 0f910cfe..502d5e21 100644 --- a/google/resource_compute_disk.go +++ b/google/resource_compute_disk.go @@ -49,6 +49,13 @@ func isDiskShrinkage(old, new, _ interface{}) bool { // We cannot suppress the diff for the case when family name is not part of the image name since we can't // make a network call in a DiffSuppressFunc. func diskImageDiffSuppress(_, old, new string, _ *schema.ResourceData) bool { + // Understand that this function solves a messy problem ("how do we tell if the diff between two images + // is 'ForceNew-worthy', without making a network call?") in the best way we can: through a series of special + // cases and regexes. If you find yourself here because you are trying to add a new special case, + // you are probably looking for the diskImageFamilyEquals function and its subfunctions. + // In order to keep this maintainable, we need to ensure that the positive and negative examples + // in resource_compute_disk_test.go are as complete as possible. + // 'old' is read from the API. // It always has the format 'https://www.googleapis.com/compute/v1/projects/(%s)/global/images/(%s)' matches := resolveImageLink.FindStringSubmatch(old) @@ -166,8 +173,8 @@ func diskImageFamilyEquals(imageName, familyName string) bool { // e.g. image: ubuntu-1404-trusty-v20180122, family: ubuntu-1404-lts func suppressCanonicalFamilyDiff(imageName, familyName string) bool { parts := canonicalUbuntuLtsImage.FindStringSubmatch(imageName) - if len(parts) == 2 { - f := fmt.Sprintf("ubuntu-%s-lts", parts[1]) + if len(parts) == 3 { + f := fmt.Sprintf("ubuntu-%s%s-lts", parts[1], parts[2]) if f == familyName { return true } diff --git a/google/resource_compute_disk_test.go b/google/resource_compute_disk_test.go index 5ae0f430..ba6769c3 100644 --- a/google/resource_compute_disk_test.go +++ b/google/resource_compute_disk_test.go @@ -122,6 +122,11 @@ func TestDiskImageDiffSuppress(t *testing.T) { New: "ubuntu-os-cloud/ubuntu-1404-lts", ExpectDiffSuppress: true, }, + "matching unconventional image family - minimal": { + Old: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-minimal-1804-bionic-v20180705", + New: "ubuntu-minimal-1804-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",