gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 16:22:07 26 4
gpt4 key购买 nike

在我的 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 中定义的凭据?

最佳答案

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.
...

我现在能想到的方法是使用环境变量(我是这样使用的)。
$ 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.

关于Terraform aws 提供程序 - 如何使用 ~/.aws/config 中的默认区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60404243/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com