我希望为Terraform执行MFA,这意味着每次terraform [command]
都需要从我的虚拟MFA设备请求6位令牌。在阅读文档之后:cli-roles terraform mfa 我创建了一个角色:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::[ACCOUNT_ID]:user/testuser"
},
"Action": "sts:AssumeRole",
"Condition": {
"Bool": {
"aws:MultiFactorAuthPresent": "true"
}
}
}
]
}
该用户默认需要使用多因素身份验证,我已为他配置了虚拟多因素身份验证设备。
~/.aws/credentials:
[default]
...
[terraform_role]
role_arn = arn:aws:iam::[ACCOUNT_ID]:role/terraform-test-role
source_profile = default
mfa_serial = arn:aws:iam::[ACCOUNT_ID]:mfa/testuser
在我的 Terraform 环境中,我放置了以下内容:
provider "aws" {
profile = "terraform_role"
}
但是当我运行
terraform plan
时,它会抛出一个错误:Error refreshing state: 1 error(s) occurred:
* provider.aws: No valid credential sources found for AWS Provider.
Please see https://terraform.io/docs/providers/aws/index.html for more information on
providing credentials for the AWS Provider
.config
的文件,其中包含有关配置文件的信息。 - Malice~/.aws/config
文件中,我只有以下内容[default] region = us-east-1 output = json
。 - Alexander Nekrasovterraform_role
创建一个新的配置文件。 - Maliceterraform-role
语句在~/.aws/credentials
文件中是对该配置文件的声明。 - Alexander Nekrasov