mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-05 17:52:38 +00:00
Suppress diff for ubuntu-minimal-lts as well as ubuntu-lts. (#1870)
This commit is contained in:
parent
27f434ddf1
commit
4408183c9f
|
@ -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))
|
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]+$")
|
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
|
// built-in projects to look for images/families containing the string
|
||||||
|
|
|
@ -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
|
// 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.
|
// make a network call in a DiffSuppressFunc.
|
||||||
func diskImageDiffSuppress(_, old, new string, _ *schema.ResourceData) bool {
|
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.
|
// 'old' is read from the API.
|
||||||
// It always has the format 'https://www.googleapis.com/compute/v1/projects/(%s)/global/images/(%s)'
|
// It always has the format 'https://www.googleapis.com/compute/v1/projects/(%s)/global/images/(%s)'
|
||||||
matches := resolveImageLink.FindStringSubmatch(old)
|
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
|
// e.g. image: ubuntu-1404-trusty-v20180122, family: ubuntu-1404-lts
|
||||||
func suppressCanonicalFamilyDiff(imageName, familyName string) bool {
|
func suppressCanonicalFamilyDiff(imageName, familyName string) bool {
|
||||||
parts := canonicalUbuntuLtsImage.FindStringSubmatch(imageName)
|
parts := canonicalUbuntuLtsImage.FindStringSubmatch(imageName)
|
||||||
if len(parts) == 2 {
|
if len(parts) == 3 {
|
||||||
f := fmt.Sprintf("ubuntu-%s-lts", parts[1])
|
f := fmt.Sprintf("ubuntu-%s%s-lts", parts[1], parts[2])
|
||||||
if f == familyName {
|
if f == familyName {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,6 +122,11 @@ func TestDiskImageDiffSuppress(t *testing.T) {
|
||||||
New: "ubuntu-os-cloud/ubuntu-1404-lts",
|
New: "ubuntu-os-cloud/ubuntu-1404-lts",
|
||||||
ExpectDiffSuppress: true,
|
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": {
|
"different image family": {
|
||||||
Old: "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-8-jessie-v20171213",
|
Old: "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-8-jessie-v20171213",
|
||||||
New: "family/debian-7",
|
New: "family/debian-7",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user