Skip to content

Conversation

@liamcervante
Copy link
Contributor

Currently, terraform test attempts to work out the type of any external variables by delaying evaluation until each run block executes so it can use the definitions within the run blocks's module. This means that the values of variables can technically change between run blocks which isn't ideal.

This commit is the first in a chain which will move the evaluation of variables into the terraform test graph. We need to give the users the option of specifying the type for external variables within the file as these variables are now going to be assessed outside of the context of a run block. To do this, we introduce the optional variable blocks that are added by this commit. The optional variable block means that users can specify the intended type of variables that should be provided externally (ie. from the CLI or an external file) and are used within the test file.

The driving change here is to the VariableCaches object / file. Previously, we cached variables at the run block level. Each run block had it's own cache and definition of variables as they were interpreted based on the config of the current run block. Now, we just evaluate the variables once, so the variable cache has changed from a map of run blocks to caches, just into an individual run block.

@liamcervante liamcervante requested a review from a team as a code owner June 2, 2025 13:24
@liamcervante liamcervante force-pushed the liamcervante/test/transform-config branch from 20a9b59 to b2026d7 Compare June 2, 2025 13:25
@liamcervante liamcervante force-pushed the liamcervante/test/variables branch from 564adfe to a1f7832 Compare June 2, 2025 13:29
@liamcervante liamcervante force-pushed the liamcervante/test/transform-config branch from b2026d7 to eb0de9b Compare June 2, 2025 13:39
@liamcervante liamcervante force-pushed the liamcervante/test/variables branch from a1f7832 to 9fbeebc Compare June 2, 2025 13:40
Base automatically changed from liamcervante/test/transform-config to main June 3, 2025 07:10
Currently, `terraform test` attempts to work out the type of any external variables by delaying evaluation until each run block executes so it can use the definitions within the run blocks's module. This means that the values of variables can technically change between run blocks which isn't ideal.

This commit is the first in a chain which will move the evaluation of variables into the terraform test graph. We need to give the users the option of specifying the type for external variables within the file as these variables are now going to be assessed outside of the context of a run block. To do this, we introduce the optional variable blocks that are added by this commit.
@liamcervante liamcervante force-pushed the liamcervante/test/variables branch from 9fbeebc to 9d6a0d7 Compare June 3, 2025 07:17
dsa0x
dsa0x previously approved these changes Jun 3, 2025
Copy link
Member

@dsa0x dsa0x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!.

}
}

// Finally, we're going to give these variables a value. They'll be
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment is now out of date

@liamcervante liamcervante enabled auto-merge (squash) June 3, 2025 07:46
@liamcervante liamcervante merged commit f80762d into main Jun 3, 2025
8 checks passed
@liamcervante liamcervante deleted the liamcervante/test/variables branch June 3, 2025 07:47
@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2025

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 Jul 4, 2025
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.

2 participants