-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
terraform test
Consistently Crashing
#34584
Comments
terraform test
Consistently Crashing
For additional context, as shown in the config I am using Here's the tree:
|
More info - if I replace all the locals with hardcoded strings (e.g. |
Hi @novekm, unfortunately you can't reference configuration locals from within the test file. The test files and their variables are evaluated outside of the Terraform context that the locals and other parts of the configuration are available within. Locals and internal variables could rely on parts of the configuration that are only available during / after a plan or apply operation, while the test file has to make all the inputs available at the beginning of each operation, so that kind of workflow is unfortunately not possible. However, the crash itself is definitely a bug - you should be getting an error message explaining why it's failing at the very least. I see you are running v1.7.0, if you upgrade to v1.7.1 is it still crashing. I think we fixed the crash within #34531, which was released in v1.7.1 last week. Thanks! |
Terraform test would pick up variables defined within a |
Ok gotcha, thank you! So to recap - variables are fine as long as they're in a I'm creating an AWS workshop about how to use this new feature of Terraform within the context of an AWS environment, so I want to make sure I have the correct messaging about what is currently supported 😃 I'll re-run the tests with v1.7.1 and keep you posted on if it crashes again. Thanks! |
I'll try and summarise things a bit more verbosely here. Hopefully it's helpful! Referencing
For example: # main.auto.tfvars
# This is variable file, it only contains static definitions for variables.
global_value = "hello" # main.tftest.hcl
# This is our test file.
variables {
# This is a file-level variables block. We can provide more static definitions for variables here.
bad_value = var.global_value # Wrong! You can't refer to other variables from this context.
good_value = "hello"
}
run "test" {
variables {
# This is a run-level variables block. We can provide more static definitions here, and we can
# refer to other variables here as well.
local_value = "hello"
run_good_value = var.good_value # Right! We can reference the variables defined at the file level.
run_global_value = var.global_value # Right! We can reference the variables from the files here as well.
}
} That's a snapshot of the current set of available features. The linked feature request related to this line:
When we implement the linked feature request, we will allow referencing "global" variables (variables defined externally to the test file such as in variable files or on the CLI) within file-level variables blocks. Similar to how you can reference earlier variables from within run-level variables. Hope this makes sense! |
I'm going to close this issue, as I think this has been fixed in the latest versions. |
Hi @liamcervante sorry the delay. Yes, I have tested in v1.7.2 and this is now resolved. It throws a correct error mentioning that the local cannot be used:
Thank you so much for all of the help and the detailed explanation! The code sample helped clear up everything for me. Thanks again 🙏🏾 |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Terraform Version
Terraform Configuration Files
main.tftest.hcl
Debug Output
Expected Behavior
Not crash
Actual Behavior
Crashing every single time
Steps to Reproduce
terraform init
terraform test
Additional Context
This appears to be the same issue that was identified in this GitHub Issue - #33780 that was closed.
References
terraform test
crash on multiple run blocks in file #33780The text was updated successfully, but these errors were encountered: