Default Region Configuration Breaks Tests
Opened this issue · 2 comments
Summary
Using an AWS default region configured in the terminal context breaks randomized AWS region selection.
Problem Analysis
Using
data "aws_region" "current" {}
references to the AWS_DEFAULT_REGION
configured in the current terminal context, if one is configured.
The tests are written in a way to randomize the region selection, e.g.
awsRegion := aws.GetRandomRegion(t, nil, []string{"eu-north-1"})
.
This leads to the side effect, that the AMI is created with packer using the random awsRegion
and terraform infrastructure rollout is using the pre-configured AWS_DEFAULT_REGION
.
I am a bit confused since the region is configured for terraform as well:
terraformOptions := &terraform.Options{
TerraformDir: exampleFolder,
Vars: terraformVars,
EnvVars: map[string]string{
AWS_DEFAULT_REGION_ENV_VAR: awsRegion,
},
}
The problem seems to be this line in the terratest code.
It reads the environment variables from the current execution context. In this case the AWS_DEFAULT_REGION
is configured twice.
Solution
The following possibilities to tackle the issue come to my mind:
- Avoid using
data "aws_region" "current" {}
and inject the region using a variable. - Changing the behavior of terratest to ignore default region.
- Rewriting the tests to use with the default region configured.
- Document the issue and warn about the use of default region
Hard to tell which one is the most suitable solution. Currently I am more leaning towards option 4.
Would be happy to support independent of the option.
Hm, are you saying that environment variables defined in your terminal are overriding the environment variables defined in the EnvVars
param of terraform.Options
?
The behavior looks like this, but it makes no sense... I want to debug into it a bit more.
My setup:
- using aws-vault which provides temporary AWS credentials
- having a default region configured in
~/.aws/config
- zsh
- MacOSX
Current workaround:
- Removing the configured default region.