You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on a 'complex' module requiring a number of resources pre-creation involving multiple but common variables.
In this case I have 2 modules:
test-setup (pre-create a few resources)
networking (module under test)
Both modules take a network_config variable as input, and in our case the variable cannot be hardcoded in the test and is given dynamically through terraform.tfvars (file that is generated before the test is run).
Attempted Solutions
I need to pass a variable from local terraform.tfvars file, to the test-setup module that is not the module under test at the moment, and there is no way to refer to dynamically loaded variables in the tftest file.
# file: tests/issue.tftest.hcl# NOTE: variable `network_config` is auto-loaded from local tfvars filerun"setup" {
module {
source="../test-setup"
}
variables {
# Not specifying the variable doesn't auto-pass it from tfvars (since this is for another module, not the one under test).# And specifying it I have no way to reference auto-loaded var.network_config=var.network_config# This does NOT currently work (saying `var.network_config` doesn't exist)
}
}
run"do-test" {
# variable `network_config` is auto-passed to the module under test# NOTE: If we could reference auto-loaded vars it would be interesting to transform the variable for a specific testvariables {
# This does NOT currently work (saying `var.network_config` doesn't exist)network_config=merge(var.network_config, {
# For this call, change the vnet name but keep the generated subnet_cidr
vnet_name ="some-other-vnet"
})
}
}
Proposal
Allow tftest files to reference auto-loaded variables.
For declarative-like approach it might be interesting to allow tftest files to declare external variables that are auto-loaded, so the evaluator / checker knows a given variable actually exists?
References
Might be related to #34534 for the ability to reference variables in variables block.
The text was updated successfully, but these errors were encountered:
Thanks for this feature request! If you are viewing this issue and would like to indicate your interest, please use the 👍 reaction on the issue description to upvote this issue. We also welcome additional use case descriptions. Thanks again!
+1, I believe I'm running into a similar issue (defined in this GitHub Issue - #34584 I created), but in my case Terraform itself is crashing (not sure if that's the same issue OP is describing). Will try again with hardcoded values
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.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Terraform Version
Use Cases
I'm working on a 'complex' module requiring a number of resources pre-creation involving multiple but common variables.
In this case I have 2 modules:
test-setup
(pre-create a few resources)networking
(module under test)Both modules take a
network_config
variable as input, and in our case the variable cannot be hardcoded in the test and is given dynamically throughterraform.tfvars
(file that is generated before the test is run).Attempted Solutions
I need to pass a variable from local
terraform.tfvars
file, to thetest-setup
module that is not the module under test at the moment, and there is no way to refer to dynamically loaded variables in the tftest file.You can see the issue here:
Proposal
Allow tftest files to reference auto-loaded variables.
For declarative-like approach it might be interesting to allow tftest files to declare external variables that are auto-loaded, so the evaluator / checker knows a given variable actually exists?
References
Might be related to #34534 for the ability to reference variables in variables block.
The text was updated successfully, but these errors were encountered: