在我的main.tf
中,我定义了一个空的AWS提供商
provider aws {}
在没有环境变量的情况下,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:
我如何让aws提供者按照[default]
中的定义自动获取~/.aws/config
凭据的相应区域?
答案 0 :(得分:5)
AWS提供程序具有 profile 属性,但是它没有从.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.
...
我现在想到的方式是使用环境变量(我使用这种方式)。
$ 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.
答案 1 :(得分:0)
如果拥有provider
块的唯一原因是引用代码中的区域,则可以简单地使用aws_region data source,它允许您引用当前区域而不是使用{{ 1}}屏蔽(我认为在这种情况下,应该从默认配置文件中拾取该区域)
provider