繁体   English   中英

未找到 Terraform AWS 凭证文件

[英]Terraform AWS credentials file not found

在阅读 Terraform 上的文档时,它说有 3 个选项可以找到 AWS 凭证:

  1. 静态凭据(嵌入在源文件中)
  2. 环境变量。
  3. 从 AWS 凭证文件

我试图让我的设置只使用凭证文件。 我已经检查过环境变量是否已清除,并将 Terraform 中的相关变量留空。

当我这样做并运行“Terraform Plan”时,我收到错误消息:

未找到适用于 AWS 提供商的有效凭证源。

我什至尝试将我的凭据文件的位置添加到我的 provider 块中,但这也无济于事:

provider "aws" {
    region  = "${var.region}"
    profile = "${var.profile}"
    shared_credentials_file = "/Users/david/.aws/credentials"
    profile = "testing"
}

我是否缺少让 Terraform 读取此文件而不需要环境变量的东西?

我使用Terraform v0.6.15进行了测试,并且工作正常。

问题必须与profile 检查以下内容。

1. 从您的提供商中删除 2 个profile标签。

provider "aws" {
  region  = "${var.region}"
  shared_credentials_file = "/Users/david/.aws/credentials"
  profile = "testing"
}

2. 确保您的凭证文件/Users/david/.aws/credentials采用以下格式,其中testing是您在provider "aws"中指定的profile

[testing]
aws_access_key_id = *****
aws_secret_access_key = *****

要让多个配置文件与 Terraform 一起使用,请确保提供

aws_access_key_id 

一块到您的个人资料声明。 每个配置文件应如下所示:

[profile_name]
aws_access_key=*****
aws_secret_access_key****
aws_access_key_id=*****

从技术上讲,您甚至不需要 aws_access_key,因为 id 版本似乎是底层 aws cli 所需要的。 也许是我,但在我阅读的文件中从来没有明确过这一点。

我刚刚在 terraform aws provider (2.12.0) 上遇到了同样的问题,这就是我解决的方法。

在我的情况下,提供商无法处理$HOME/.aws/credentials默认配置文件没有我的访问密钥和机密,但它有一个“source_profile”。 似乎 terraform aws 提供商无法处理这个问题(但这对 Java SDK 和 AWS CLI 很好用,因为我已经有一段时间了)。

这是我所拥有的不起作用的东西,请注意默认配置文件有一个 role_arn 和 source_profile:

[default]
role_arn = arn:aws:iam::<ACCT_ID>:role/readonly
source_profile = account
region = us-east-1

[other-profile]
role_arn = arn:aws:iam::<ACCT_ID>:role/other-role
source_profile = account
region = us-east-1

[account]
region = us-east-1
aws_access_key_id=****
aws_secret_access_key=****

我将其更改为以下内容,这导致 aws 提供程序为我工作。 请注意,我将两个配置文件合并到“默认”配置文件中:

[other-profile]
role_arn = arn:aws:iam::<ACCT_ID>:role/other-role
source_profile = default
region = us-east-1

[default]
region = us-east-1
aws_access_key_id=****
aws_secret_access_key=****
role_arn = arn:aws:iam::<ACCT_ID>:role/readonly
source_profile = default

这似乎适用于 AWS CLI(默认为只读角色并支持切换到“other-profile”)以及允许 terraform 正确读取凭证。

请为实例分配管理员角色,然后它将正常工作

(Terraform v0.14.2,macOS 11.0.1)

我需要做:

AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY=... terraform plan

这对我来说很奇怪,因为我的 ~/.aws 是有序的,我的 .tf-s 也是如此。 ¯_(ツ)_/¯

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM