Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Default Region Configuration Breaks Tests #201

Open
MatthiasScholz opened this issue Jan 12, 2021 · 2 comments
Open

Default Region Configuration Breaks Tests #201

MatthiasScholz opened this issue Jan 12, 2021 · 2 comments
Labels

Comments

@MatthiasScholz
Copy link

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:

  1. Avoid using data "aws_region" "current" {} and inject the region using a variable.
  2. Changing the behavior of terratest to ignore default region.
  3. Rewriting the tests to use with the default region configured.
  4. 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.

@brikis98
Copy link
Collaborator

Hm, are you saying that environment variables defined in your terminal are overriding the environment variables defined in the EnvVars param of terraform.Options?

@MatthiasScholz
Copy link
Author

MatthiasScholz commented Jan 22, 2021

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants