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

Fix google_compute_disk created from snapshot, forces new resource then apply once more #238

Merged
merged 4 commits into from
Aug 15, 2017

Conversation

z1nkum
Copy link

@z1nkum z1nkum commented Jul 25, 2017

fix issue with recreation loop:
#218

@grubernaut grubernaut added the bug label Jul 26, 2017
Copy link
Contributor

@paddycarver paddycarver left a comment

Choose a reason for hiding this comment

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

Hi @z1nkum! Thanks so much for the PR. Overall, this solution seems like it would work, but I think there's a way we could do this that has a few nicer properties.

If we use a DiffSuppressFunc on the snapshot property, it lets us store the full URL of the snapshot, but doesn't consider it different from just the name being used in the config.

If the DiffSuppressFunc uses a similar Split strategy on what's in the config, as well, then the config can accept either the full URL or the name, which is sometimes beneficial.

What do you think of these two changes? If you have questions or need help, I'm happy to assist however I can. And thanks for contributing to Terraform!

@z1nkum
Copy link
Author

z1nkum commented Aug 5, 2017

@paddycarver please, take a look. Maybe I did not quite understand the idea.

Copy link
Contributor

@paddycarver paddycarver left a comment

Choose a reason for hiding this comment

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

This is great @z1nkum, looks perfect!

Last thing I see before this can be merged is just adding a test case that fails without the fix but passes with the fix. google/resource_compute_disk_test.go should have plenty of examples you can use as a template, but if you get lost or confused, please don't hesitate to shout and I'll help you get this pushed over the finish line.

Super excited to have this fix in Terraform. Thanks!

@z1nkum
Copy link
Author

z1nkum commented Aug 8, 2017

I really tried to figure out how to trigger and then catch ForceNew event in tests - but unsuccessfully
Test TestAccComputeDisk_fromSnapshotURI (google/resource_compute_disk_test.go) looks like suitable for this case. Perhaps we should add here one more resource.TestStep with the same config. But I can not imagine what should be inside ComposeTestCheckFunc test :(
Could you please help me with it, @paddycarver ?

I've already built provider with fix and check against config (#218) - works fine (at least, does not attempt to recreate the disk)

@rosbo rosbo changed the title fix issue #218 Fix google_compute_disk created from snapshot, forces new resource then apply once more Aug 10, 2017
@paddycarver
Copy link
Contributor

Hey @z1nkum, absolutely no worries. There are a lot of tools in the test framework, and it's not documented as well as it could be.

In this case, I don't think the bug is that it's ForceNew--and that doesn't look like it's changing in your code. So I'd forget about trying to verify the ForceNew aspect of it, and rather just try to verify that there isn't a diff after the apply.

Fortunately, the test framework does that for us automatically; it will run another plan after all your test steps are run, and if there's a diff, it fails the test. So a good way to test this would be to use the snapshot name (the input that was causing the problem) in a test. If the test passes, things are good, and that's all it takes! If you want to be extra sure, run the test against the master branch (without the fix applied) and make sure it fails, with something like "non-empty plan" or "non-empty diff". Then you know you've recreated the problem, and fixed it.

You could even copy & paste the current snapshot test (https://github.com/terraform-providers/terraform-provider-google/blob/ff8bdc9b52f379b7cb42a2c2fe6dcb49e0c130c3/google/resource_compute_disk_test.go#L63-L85) and update the copy to use just the name, instead of the full URL. That would demonstrate that the problem was resolved. And having it automated means if the API ever changes, or we ever break Terraform's framework in a way that breaks this, or we ever introduce a regression, we'll know about it. :)

Thanks for all the hard work!

@z1nkum
Copy link
Author

z1nkum commented Aug 12, 2017

Thank you, @paddycarver - I've got it.

I wrote test (actually, update TestAccComputeDisk_fromSnapshotURI) and tested it against master/branch. As expected, test passed on branch and fail on master:

--- FAIL: TestAccComputeDisk_fromSnapshot (152.56s)
        testing.go:428: Step 1 error: After applying this step, the plan was not empty:

@z1nkum
Copy link
Author

z1nkum commented Aug 15, 2017

😱 sorry, I just wanted to rebase branch from upstream/master

@paddycarver
Copy link
Contributor

No worries! I've created a fixed branch (terraform-providers:paddy_z1nkum_238) that is up-to-date with master. You can:

  • pull that, mirror it to your repo, and use it as the basis of the PR
  • pull that, force push it to the z1nkum:snapshot-fix-url-to-name branch you opened this PR from, which will update this PR
  • just redo the steps I did to make that branch on your branch and force push it, which will update this PR:
    1. git checkout snapshot-fix-url-to-name
    2. git checkout d0b7fbc
    3. git merge master
    4. git push -f

Note that using the branch I created or the steps above will both delete anything you've done on the branch since d0b7fbc, which (as far as I can tell) is the last intentional commit. :)

@z1nkum z1nkum force-pushed the snapshot-fix-url-to-name branch from 633a86a to d0b7fbc Compare August 15, 2017 20:14
@z1nkum
Copy link
Author

z1nkum commented Aug 15, 2017

Thanks a lot! Now it seems all right

Copy link
Contributor

@paddycarver paddycarver left a comment

Choose a reason for hiding this comment

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

I think the way the ref selector was done for the test isn't ideal, and would probably be better as something like a boolean. That being said, I don't think it's a big enough issue to hold this fix over, so I'd say let's merge it. :)

Thanks for the hard work, the patience, and for contributing to Terraform! Really appreciate you tackling this bug for us. Great job!

@paddycarver paddycarver merged commit f792923 into hashicorp:master Aug 15, 2017
negz pushed a commit to negz/terraform-provider-google that referenced this pull request Oct 17, 2017
Fix google_compute_disk created from snapshot, forces new resource then apply once more
luis-silva pushed a commit to luis-silva/terraform-provider-google that referenced this pull request May 21, 2019
@ghost
Copy link

ghost commented Mar 31, 2020

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 👉 hashibot-feedback@hashicorp.com. Thanks!

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

Successfully merging this pull request may close these issues.

3 participants