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

Core FR: Check that only an 'update' occurred in a test #61

Closed
danawillow opened this issue Jun 6, 2017 · 6 comments · Fixed by #63
Closed

Core FR: Check that only an 'update' occurred in a test #61

danawillow opened this issue Jun 6, 2017 · 6 comments · Fixed by #63
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@danawillow
Copy link

In hashicorp/terraform#15101 and hashicorp/terraform#15102, it was discovered that tests that we thought were testing update were actually just doing a destroy and recreate. It would be great to have another option in TestStep that would confirm that no resources were destroyed or created in a step, only updated. In this particular scenario, if the test had been written correctly, it would have caught the bug leading to hashicorp/terraform#15056 potentially before it was caught by a user.

@nat-henderson
Copy link

+1!

The workaround for this, right now, is to manually examine the debug output for every single test every time we write any code which touches Update. That's time-consuming, and it'd be awesome to have a ValidatePlanFunc or something like that. Accidentally deleting / recreating someone's infrastructure when they just wanted it updated can be unrecoverably destructive, and it'd be rad to have unit tests that prove we aren't going to do that.

@apparentlymart
Copy link
Contributor

Another possible workaround here would be to save the value of some id attribute that changes when the object is replaced in the prior step, and then in the subsequent check step verify that the two ids match. This will, of course, work only if there is some id attribute on the object that remains static on update and changes on replace.

I agree that it'd be more ergonomic to either assert against the planned changes or to declare in the test step that it should contain no replace actions.

I'm sorry for the long silence here. I've updated the labels on this issue to put it on the radar of the team that is responsible for the provider SDK (helper/schema, etc), but they are currently focused elsewhere and so will likely return to this at a later date, in conjunction with other related improvements.

@nat-henderson
Copy link

Unfortunately that's not usually the case in GCP, but I can see how it might be elsewhere, which would definitely make this a lower-priority improvement. Thanks for the update!

@pdecat
Copy link

pdecat commented Feb 19, 2020

Hi, I've submitted hashicorp/terraform-plugin-sdk#329 which should address this issue (and hashicorp/terraform-plugin-sdk#222 which looks very similar).

@austinvalle
Copy link
Member

austinvalle commented Mar 22, 2023

Hello longtime subscribers of this issue 👋🏻 ,

We've recently released Plan Checks with terraform-plugin-testing v1.2.0 and more specifically, plancheck.ExpectResourceAction that should satisfy the original feature request in this issue.

https://developer.hashicorp.com/terraform/plugin/testing/acceptance-tests/plan-checks#examples-using-plancheck-expectresourceaction

There is an example of how to use this plan check in the linked documentation on the developer portal, but please open a new issue if you run into problems, or open a post on our discuss board for other questions.

@bflad bflad added this to the v1.2.0 milestone Mar 22, 2023
@github-actions
Copy link

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.