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
Can be assigned to me, I would just like some feedback on the issue / approach first.
It would be good to specify and override values for Terraform variables when testing.
Currently we don't see a good way to do this with pytest-terraform.
Apparent options:
Setting os.environ[TF_VAR_x] = "foo" before the test seems to work in some cases and not in others. It's a bit flaky.
Writing terraform.tfvars to the tests/terraform/my_test folder and exclude it from source control. This works but is a bit clunky as we need to ensure variable values are written correctly to the file, eg if they are of complex type.
The specific use case we have involves providing at least a value for the AWS profile that the Terraform AWS provider needs to use at run time, so that we can authenticate to the correct environment.
pytest --profile my_ci_account_profile
=> We add a fixture called "profile" to read in this value
=> We write terraform.tfvars with profile = "my_ci_account_profile"
Our terraform test code:
# variables.tf:
variable "profile" {
description = "AWS profile"
type = string
}
# providers.tf:
provider "aws" {
region = "us-east-1"
profile = var.profile # Dynamically use an AWS profile at runtime
}
My particular use case is complicated because the profile is only known at runtime.
Perhaps something like this could work, for our use case:
variables support sounds great. re options listed, env vars should work, we typically straight pass through with some augmentation (plugin cache, data dir, in automation TF env vars) on each subprocess. I'm curious what your seeing here wrt to flakey. wrt to write out of variable files, we do keep a separate work dir for state that we could drop variables file into rather than dealing with source code exclusion.
re first steps mod'ing tf runner to accept variables for apply & plan with var file write out to temp dir seems like a good option. and then updating the decorator to support passing in values sounds good. re parameterize support, sounds cool, although there might be a rabbit hole there.
Can be assigned to me, I would just like some feedback on the issue / approach first.
It would be good to specify and override values for Terraform variables when testing.
Currently we don't see a good way to do this with
pytest-terraform
.Apparent options:
os.environ[TF_VAR_x] = "foo"
before the test seems to work in some cases and not in others. It's a bit flaky.terraform.tfvars
to thetests/terraform/my_test
folder and exclude it from source control. This works but is a bit clunky as we need to ensure variable values are written correctly to the file, eg if they are of complex type.The specific use case we have involves providing at least a value for the AWS profile that the Terraform AWS provider needs to use at run time, so that we can authenticate to the correct environment.
pytest --profile my_ci_account_profile
=> We add a fixture called "profile" to read in this value
=> We write
terraform.tfvars
withprofile = "my_ci_account_profile"
Our terraform test code:
My particular use case is complicated because the profile is only known at runtime.
Perhaps something like this could work, for our use case:
@terraform("main", scope="session", variables={profile=os.environ.get["profile"]})
Perhaps this feature could even use pytest parameterize to iteratively test values of variables under different scenarios.
The text was updated successfully, but these errors were encountered: