Basic support for provisioners in "removed" blocks #34753
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
During the apply phase, we'll check if there are provisioners either in the matching
resource
block or the matchingremoved
block -- whichever of the two is present -- and execute the destroy-time subset of them either way.This also establishes a standard way to attach a
removed
block to aNodeResourceAbstract
when one is defined, which is likely to be useful for supporting other resource-related meta arguments inremoved
blocks in future.This code is currently accessible only to modules that opt in to the
removed_provisioners
language experiment, and therefore only available in alpha releases.One known limitation and design question from this initial implementation is:
How should
each.key
,each.value
, andcount.index
behave when used as part of aprovisioner
configuration in aremoved
block?This is a tricky question because whereas a
resource
block allows us to determine from the configuration whether we're usingcount
,for_each
, or neither -- and treat invalid references as an error --removed
blocks must accept whatever happens to be in the state and so in unusual cases there might even be a mixture of numeric instance keys and string instance keys for the same resource, making it impossible to write a provisioner configuration that would work with both.Other notes/questions for future work:
destroy = false
? Or should that instead mean "run the provisioner just before forgetting the object"?terraform rm aws_instance.example
that would automatically replace theresource "aws_instance" "example"
block with a matchingremoved
block, and copy over its destroy-time provisioners, to avoid the need to migrate them over manually?This is motivated by #34711 and part of #13549 .