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

terraform test: rearrange the order of destroy operations #34293

Merged
merged 1 commit into from Nov 29, 2023

Conversation

liamcervante
Copy link
Member

This is my second attempt at this, see #34285.

I think I overcomplicated this logic initially. Previously, we'd destroy the main state first, and then iterate through the remaining states from alternate modules in reverse order. We had documentation advising users not to create dependencies on the main state so this ordering should have been safe. I hadn't considered data sources requiring read operations during the pre-destroy refresh which leads to the referenced bug.

After this PR, we just destroy in reverse ordering with the documentation updated to simply say don't create references into later run blocks (eg. don't make a resource that depends on the creation of an earlier run block, and then reference the underlying module of that earlier run block later). I think this is actually acceptable given the way people are using the testing framework - it's much simpler this way and easier to explain. It also gives more control to the users - they can simply do a plan only run block against a module to tweak the destroy order.

A complicated extension to this would be to not only destroy during the destroy operation, but to essentially rollback states to previous run blocks until you find the first time they are created, at which point you could destroy them. I think this would be overkill for what we're trying to solve here but we could revisit that idea if this solution is inadequate.

I'm not sure if we can backport this change (given the change in the docs) but also this is quite advanced and I doubt many (if any) users will have created test configurations at the required complexity for this to be an issue yet. So maybe we could backport it? If not, we can fix this as part of the upcoming 1.7 release.

Fixes #34280

Target Release

1.7.0 or 1.6.5 - I'm not sure.

Draft CHANGELOG entry

UPGRADE NOTES

  • terraform test: Simplify the ordering of destroy operations during test cleanup to simple reverse run block order.

@liamcervante liamcervante requested a review from a team November 23, 2023 09:24
@liamcervante
Copy link
Member Author

I realise there is another consideration - we have an example in the docs doing exactly what the user has tried to do. It works sometimes depending on the provider so maybe we want to backport this to make the example in the docs work all the time or put another PR together that we do backport that updates the docs to add some caveats to the example.

@jbardin
Copy link
Member

jbardin commented Nov 29, 2023

It might be a little late in the cycle for a backport the whole into v1.6. We could just classify the case in the existing docs as a bug that will be fixed via the v1.7 release along with the updated behavior. If anything, maybe we just remove the incorrect usage from the v1.6 docs?

@liamcervante liamcervante merged commit 6670ab4 into main Nov 29, 2023
7 checks passed
Copy link

Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch.

Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, 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 Dec 30, 2023
@liamcervante liamcervante deleted the liamcervante/34280 branch February 23, 2024 13:14
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.

Terraform Test: helper module data sources returns error while tearing down
2 participants