在我的main.tf中,我定义了一个空的亚马逊网络服务提供商
provider aws {}在没有环境变量的情况下,亚马逊网络服务提供商从~/.aws/credentials中挑选[default]凭证。但是,我仍然会收到输入区域的提示:
>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/config中定义的[default]凭据的对应区域
发布于 2020-02-27 07:09:16
亚马逊网络服务提供商具有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.发布于 2020-11-01 01:39:13
如果拥有provider块的唯一原因是为了在代码中引用区域,那么您可以简单地使用aws_region data source,它允许您引用当前区域,而不是拥有provider块(在这种情况下,区域应该从默认配置文件中选取)
data "aws_region" "current-region" {}
// Then get the region using
data.aws_region.current-region.name https://stackoverflow.com/questions/60404243
复制相似问题