Request for Testing: Reference variable and run block outputs in provider configurations during `terraform test`

We just released a alpha for v1.7 yesterday.

In the alpha you can reference variables and outputs from run blocks in your provider configurations. This should allow you to create a setup module that uses one provider, load credentials or configuration you need for a second provider from the first provider, and then pass the required data into the second provider.

For example:

# testing/setup/main.tf

data "vault_generic_secret" "aws_credentials" {
  path = "some/path/to/secret"
}

output "aws_access_key_id" {
  sensitive = true
  value = data.vault_generic_secret.aws_credentials.data["AWS_ACCESS_KEY_ID"]
}

output "aws_secret_access_key" {
  sensitive = true
  value = data.vault_generic_secret.aws_credentials.data["AWS_SECRET_ACCESS_KEY"]
}
# tests/main.tftest.hcl

provider "vault" {
  // ... some configuration ...
}

provider "aws" {
  region     = "us-west-2"
  access_key = run.setup.aws_access_key_id
  secret_key = run.setup.aws_secret_access_key
}

run "setup" {
  module {
    source = "./testing/setup"
  }
}

run "test" {
  // ... a normal testing block ...
}

This should make it possible to chain provider configurations together.

We are looking for feedback on this feature, and for anyone who has any provider configuration in tests requirements not met by this feature!

Thanks!

Hi Liam, I finally got round to testing this after you helped me out on How do I pass provider information to tests? - #7 by jamiekt

It works great in 1.7 (as I’m sure you already know). I’m able to get rid of “wrapper” module that I had to introduce to get around the limitation in 1.6

Thank you for doing this.

1 Like