terraform-provider-aws: region is not picked up from the AWS profile
Community Note
- Please vote on this issue by adding a π reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave β+1β or βme tooβ comments, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Terraform Version
Terraform v0.11.11
+ provider.aws v1.60.0
Terraform Configuration Files
AWS config files on disk
~/.aws/credentials
[myprofile]
aws_access_key_id=<my access key>
aws_secret_access_key=<my secret key>
~/.aws/config
[profile myprofile]
region=eu-west-1
output=json
scenario 1: profile set via the provider block.
provider "aws" {
version = "~> 1.60"
profile = "myprofile"
}
scenario 2: profile set via the environment variable
provider "aws" {
version = "~> 1.60"
}
with
$ export AWS_PROFILE=myprofile
Expected Behavior
The Argument Reference docs state this about region:
region - (Required) This is the AWS region. It must be provided, but it can also be sourced from the AWS_DEFAULT_REGION environment variables, or via a shared credentials file if profile is specified.
When running terraform plan, I expect the region to be picked up via the myprofile section in ~/.aws/config.
Actual Behavior
Terraform asks for the region value:
$ terraform plan
provider.aws.region
The region where AWS operations will take place. Examples
are us-east-1, us-west-2, etc.
Default: us-east-1
Enter a value:
Steps to Reproduce
terraform initterraform plan
Arguments
The reason this fails is because region is a Required attribute for the AWS provider. The code only retrieves the value from the 2 environment variables when not specified in HCL. This is clearly not as documented with via a shared credentials file if profile is specified.
The AWS SDK, like it does for credentials, searches for region via environment variables and profile when not specified explicitly:
It probably needs a bit more testing, but I would suggest making region an Optional attribute and remove the DefaultFunc initialization on the AWS provider side.
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 40
- Comments: 16 (4 by maintainers)
Can confirm here, always asking for region.
Any update on this?
I am seeing this in terraform v0.12.20
My shared config: (just using the default profile)
when I run
terraform plani get:Everything works if I explicitly export the
AWS_DEFAULT_REGIONvar. My credentials are being picked up from the file properly, but not the region for some reason.Any help would be appreciated!
Confirming this is still an issue in v0.15.5.
Confirming this is still an issue in v0.15.3.