Skip to content
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

Add DiffSuppressFunc to GKE cluster networks #419

Merged
merged 2 commits into from
Sep 14, 2017

Conversation

danawillow
Copy link
Contributor

TestAccContainerCluster_network was failing with a perma-diff after #391 because GKE returns the network as a name only, but we allow users to set it to the URL. Add a DiffSuppressFunc to fix the test:

$ make testacc TEST=./google TESTARGS='-run=TestAccContainerCluster_network'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./google -v -run=TestAccContainerCluster_network -timeout 120m
=== RUN   TestAccContainerCluster_network
--- PASS: TestAccContainerCluster_network (348.82s)
PASS
ok  	github.com/terraform-providers/terraform-provider-google/google	348.976s

@danawillow danawillow requested a review from rosbo September 13, 2017 10:07
Optional: true,
Default: "default",
ForceNew: true,
DiffSuppressFunc: linkDiffSuppress,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use compareSelfLinkOrResourceName.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum. This method assume that the API always return a self-link... It wouldn't work and updating linkDiffSuppress is dangerous because moving a resource to a different zone wouldn't trigger a diff like explained below.

You can either create a new method. Or when you store the network in the Read method, you can generate the relative part of the network and use compareSelfLinkOrResourceName.

google/utils.go Outdated
@@ -251,8 +251,9 @@ func isConflictError(err error) bool {
}

func linkDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
parts := strings.Split(old, "/")
if parts[len(parts)-1] == new {
oldParts := strings.Split(old, "/")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with updating this method is that this will cause issue for zonal or regional self-link

If field was "regions/us-east1/someResource/myResource" and now is "regions/us-west1/someResource/myResource" this would suppress the diff.

I wouldn't update this method and use the other more robust compareSelfLinkOrResourceName

@danawillow
Copy link
Contributor Author

All right, I solved it in a slightly different way from your suggestion (used a StateFunc instead), let me know what you think.

$ make testacc TEST=./google TESTARGS='-run=TestAccContainerCluster_network'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./google -v -run=TestAccContainerCluster_network -timeout 120m
=== RUN   TestAccContainerCluster_network
--- PASS: TestAccContainerCluster_network (402.15s)
PASS
ok  	github.com/terraform-providers/terraform-provider-google/google	402.316sv

(if you're happy with this feel free to merge instead of waiting for me since time zones / travel and whatnot)

@rosbo rosbo merged commit 5f86f52 into hashicorp:master Sep 14, 2017
negz pushed a commit to negz/terraform-provider-google that referenced this pull request Oct 17, 2017
* fix gke network test
* use a state func to store the resource name
@danawillow danawillow deleted the gke-network-link branch June 11, 2018 20:27
@ghost
Copy link

ghost commented Nov 18, 2018

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Nov 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants