-
Notifications
You must be signed in to change notification settings - Fork 10.2k
terraform test: add variable definitions to test files #37195
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
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
left a comment
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
|
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. |
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.