Terraform aws 提供程序 - 如何使用 ~/.aws/config 中的默认区域

Ber*_*enz 6 terraform aws-regions terraform-provider-aws

在我的main.tf我定义了一个空的 aws 提供程序

provider aws {}
Run Code Online (Sandbox Code Playgroud)

在没有环境变量的情况下,aws 提供程序[default]~/.aws/credentials. 但是我仍然被提示输入该区域:

>terraform plan
provider.aws.region
  The region where AWS operations will take place. Examples
  are us-east-1, us-west-2, etc.

  Enter a value: 
Run Code Online (Sandbox Code Playgroud)

我怎样才能让 aws 提供者自动选择对应的区域到[default]中定义的凭证~/.aws/config

mon*_*mon 6

AWS 提供商具有配置文件属性,但它不会从 .aws/config 中选择区域。

$ cat main.tf
provider aws {
     profile="default"
}

$ terraform plan
provider.aws.region
  The region where AWS operations will take place. Examples
  are us-east-1, us-west-2, etc.
...
Run Code Online (Sandbox Code Playgroud)

我现在能想到的方法是使用环境变量(我是这样使用的)。

$ export AWS_DEFAULT_REGION=$(aws configure get region --profile default)
$ terraform plan
Refreshing Terraform state in-memory prior to plan...
...

------------------------------------------------------------------------

No changes. Infrastructure is up-to-date.
Run Code Online (Sandbox Code Playgroud)