hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.8k stars 9.15k forks source link

[Bug]: "provider" argument "region" is not read from shared config file #30488

Open slabstone opened 1 year ago

slabstone commented 1 year ago

Terraform Core Version

1.4.4

AWS Provider Version

4.61.0

Affected Resource(s)

provider itself (provider "aws" configuration block)

Expected Behavior

region is set via a shared config file parameter region if profile is used, as described in https://registry.terraform.io/providers/hashicorp/aws/latest/docs#region

Actual Behavior

Error: <...> failed to resolve service endpoint, an AWS region is required, but was not found

Relevant Error/Panic Output Snippet

Error: configuring Terraform AWS Provider: validating provider credentials: retrieving caller identity from STS: operation error STS: GetCallerIdentity, failed to resolve service endpoint, an AWS region is required, but was not found

Terraform Configuration Files

terraform {
  required_version = "1.4.4"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "4.61.0"
    }

    local = {
      source  = "hashicorp/local"
      version = "2.4.0"
    }
  }
}

locals {
  shared_config_filepath = "${path.module}/config/shared_config"
}

resource "local_file" "shared_config" {
  content = <<EOF
[profile bugreport]
region = us-east-1
EOF

  filename = local.shared_config_filepath
}

provider "aws" {
  access_key = "access-key"
  secret_key = "secret-key"

  shared_config_files = [local.shared_config_filepath]

  profile = "bugreport"
}

resource "aws_iam_user" "dummy" {
  name = "dummy"
}

Steps to Reproduce

terraform apply -auto-approve -target=local_file.shared_config
terraform plan -target=aws_iam_user.dummy

Debug Output

Error: configuring Terraform AWS Provider: validating provider credentials: retrieving caller identity from STS: operation error STS: GetCallerIdentity, failed to resolve service endpoint, an AWS region is required, but was not found

Panic Output

No response

Important Factoids

No response

References

https://registry.terraform.io/providers/hashicorp/aws/latest/docs#region

Would you like to implement a fix?

No

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue