terraform test: enable deferrals in Terraform Test with the specified flag #37370
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.
This PR adds the
-allow-deferral
flag to Terraform Test, essentially enabling deferrals during Terraform Test executions.My test case exposed an edge case in the Terraform evaluation context, which I've fixed in this PR. Previously, if a resource was being created for the first time (so is not already in state) and was deferred the evaluation context was actually entering the
rs == nil
branch of the evaluation process, because deferred resources are not added to the internal state as they are built. This was then triggering the error branch and returning acty.DynamicVal
. We weren't picking this up previously, and this is actually a valid value to be returned for a deferred resource but the test case I wrote was validating the returned object and detecting that it was unknown.I've refactored so it checks the deferred resources first, before consulting the state. Now, if the state doesn't have any values, it still uses the values from the deferred set of resources instead of just giving up.
Target Release
Same as whatever release the rest of deferred actions will go out in
Rollback Plan
Changes to Security Controls
Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.
CHANGELOG entry
Deferred actions in general hasn't been released yet, and is still protected behind an experiment. We don't need a CHANGELOG entry.