boltops-tools / terraspace

Terraspace: The Terraform Framework
https://terraspace.cloud
Apache License 2.0
678 stars 46 forks source link

provider.tf is read but not used for region and profile #278

Open baitoz opened 1 year ago

baitoz commented 1 year ago

Used terraform example code to test: terraspace new project infra --plugin aws --examples

Updated provider.tf provider 'aws' with a region and profile.

When either region or provider are not set, but environment var AWS_REGION or "AWS_PROFILE" are set, then terraspace reports the setting is not set.

ie. no env variables, and no provider.tf (region and profile) reports that these settings are missing. but adding the settings to provider.tf does not work for either setting.

Adding 'default_tags' in provider.tf does work in the provider section, as such I conclude the issue with with profile and region specifically.

My Environment

Software Version
Operating System Ubuntu 20.04.2 LTS
Terraform 0.14.7
Terraspace 2.2.2
Ruby 3.0.3p157

Expected Behaviour

The provider.tf must be read for profile specifically. Cannot expect environment vars to be correct for multi AWS environments.

Current Behavior

The profile and region settings in provider.tf are not used.

Step-by-step reproduction instructions

Output log:

~/terraspace/infra$ terraspace up demo

Building .terraspace-cache/dev/stacks/demo
Current directory: .terraspace-cache/dev/stacks/demo

Exception Aws::Errors::InvalidRegionError: Invalid `:region` option was provided.

* Not every service is available in every region.
* Never suffix region names with availability zones.
  Use "us-east-1", not "us-east-1a"
Known AWS regions include (not specific to this service):

...
ap-southeast-2
...

Code Sample

export AWS_PROFILE="dev" ; export AWS_REGION="ap-southeast-2"

vs

provider "aws" {
  region = "ap-southeast-2"
  profile = "dev"

  // These are tags added to all objects created by the scripts
  default_tags {
    tags = {
      Environment = "devenv"
    }
  }
}

Solution Suggestion

None. Tried removing spaces and padding and uppercase/lowercase.

ORuessel commented 1 year ago

Hello @baitoz , in a normal way as standard terraspace read your local ~/.aws/config and ~/.aws/credentials file. in this file there are the predefined variables AWS_REGION and AWS_PROFILE. these elements existing in your environment ?