Skip to content

Suppress diff for ubuntu-minimal as well as ubuntu. #1870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion google/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions google/resource_compute_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions google/resource_compute_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down