-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Allow providers defined in test files to reference variables and other providers #34007
Description
Terraform Version
Terraform v1.6.0Use Cases
In a regular Terraform file it is possible to write something like this:
provider "vault" {}
data "vault_generic_secret" "aws_creds" {
path = "some/path/to/secret"
}
provider "aws" {
access_key_id = data.vault_generic_secret.vault_secrets_automation.data["aws_access_key_id"]
secret_access_key = data.vault_generic_secret.vault_secrets_automation.data["aws_secret_access_key"]
}You can't do this for providers defined in Terraform test files currently. In fact, you can't even pass in variables to the provider configurations currently, which is something else we could support.
Attempted Solutions
You can wrap the module you want to test up in another module, define the providers within the module in the same way you would normally, and then test that module. You lose access to validate things about the module under test (like resources and data blocks) with this, but you can still make sure the module actually executes.
Proposal
There are a couple of approaches I can think of. Currently terraform test kind of side loads the provider configuration into the configuration under test during the run block, and then the providers get initialised in the graph along with everything else. We could also just push the data blocks and any additional variables in alongside that. That might lead to clashes with other data blocks, and might allow someone to use a variable that is only defined within a test file but we can add checks for that.
Another idea is to initialise providers outside the Terraform graph, and then pass in the already running providers. The providers would be shared by all the run blocks this way, and that way can do a bit of a load and execute for data blocks and providers in the test file before the run blocks execute.