terraform test: add variable definitions to test files#37195
Merged
liamcervante merged 2 commits intomainfrom Jun 3, 2025
Merged
terraform test: add variable definitions to test files#37195liamcervante merged 2 commits intomainfrom
liamcervante merged 2 commits intomainfrom
Conversation
20a9b59 to
b2026d7
Compare
564adfe to
a1f7832
Compare
b2026d7 to
eb0de9b
Compare
a1f7832 to
9fbeebc
Compare
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.
9fbeebc to
9d6a0d7
Compare
dsa0x
previously approved these changes
Jun 3, 2025
| } | ||
| } | ||
|
|
||
| // Finally, we're going to give these variables a value. They'll be |
Member
There was a problem hiding this comment.
I think this comment is now out of date
dsa0x
approved these changes
Jun 3, 2025
Contributor
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Currently,
terraform testattempts 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
VariableCachesobject / file. Previously, we cached variables at therunblock 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.