Skip to content

terraform test: enable deferrals in Terraform Test with the specified flag #37370

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

Merged
merged 2 commits into from
Jul 30, 2025

Conversation

liamcervante
Copy link
Member

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 a cty.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

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

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.

@liamcervante liamcervante requested a review from a team as a code owner July 24, 2025 14:59
@liamcervante liamcervante added the no-changelog-needed Add this to your PR if the change does not require a changelog entry label Jul 24, 2025
dsa0x
dsa0x previously approved these changes Jul 25, 2025
@liamcervante liamcervante merged commit dec0edf into main Jul 30, 2025
8 checks passed
@liamcervante liamcervante deleted the liamcervante/test-deferrals branch July 30, 2025 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog-needed Add this to your PR if the change does not require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants