tfutils/tfscaffold

Region specified with -r not fully honoured in bootstrapping

Opened this issue · 2 comments

When bootstrapping for the first time, it's possible to get into a state where the S3 state bucket when initially created has the correct name but is placed in the wrong region.

When the region is specified via -r <region> the expectation is that this is honoured throughout all areas of the bootstrap.

However, if you have a different region specified in any of the .tfvars file within etc (such as global.tfvars) the S3 bootstrapping bucket ends up associated to this region, not the region that was specified by -r flag.

I would have the expectation that the -r flag overrides any other regions it adopts from .tfvars as an explicit value and overrides any picked up through vars.

The bucket is placed in the expected region if the -r value and any it finds in .tfvars matches up

Tested in version:

  • v1.7.0

Steps to reproduce:

  • Edit ./etc/global.tfvars and amend the value for region to region = eu-west-1
  • Run bootstrapping command ./bin/terraform.sh --bootstrap -r us-east-1 -p myproject -a plan

Expected:

  • S3 bucket for storing state is created in the region specified by -r - us-east-1

Actual:

  • S3 bucket for storing state is created in the region specified in .tfvars files picked up in the project - eu-west-1
  • S3 bucket name created does however have the expected name ending in us-east-1

I'm not sure whether the -r argument is there just for naming of the bucket? If so, would it be better for the region variable to be taken from the tfvars file rather than the argument passed in with -r?

Would it be fine to override whatever is in the var files? We could pass -var "region=" so this mismatch wouldn't ever happen - is there a use case for mismatching regions between the two?