简体   繁体   English

配置 Terraform AWS 提供程序时出错 - Linux

[英]Error configuring Terraform AWS Provider - Linux

[----------------------- UPDATE --------------------------] [ - - - - - - - - - - - - 更新 - - - - - - - - - - - - - -]

I have tried a tutorial to integrate terraform with s3 now.我现在尝试了一个将 terraform 与 s3 集成的教程。 The S3 bucket is created and I have created an IAM user, and I am using its Access key and secret key.创建了 S3 存储桶,我创建了一个 IAM 用户,我正在使用它的访问密钥和秘密密钥。 Nonetheless I keep getting errors regarding the providers after terraform init :尽管如此,在terraform init之后,我不断收到有关提供程序的错误:

backend.tf后端.tf

terraform {
  required_version = ">=0.12.0"
  backend "s3" {
    region  = "us-east-1"
    key     = "terraform.tfstate"
    profile = "tu"
    bucket  = "terraformstatebucket3107"
  }
}

config file in .aws folder .aws 文件夹中的配置文件

[tu]
region = us-east-1
output = json

credentials file in .aws folder .aws 文件夹中的凭证文件

[tu]
aws_access_key_id = AKIA*****************
aws_secret_access_key = nn3M1*****************

Error:错误:

Initializing the backend...

Error: error configuring S3 Backend: no valid credential sources for S3 Backend found.

Please see https://www.terraform.io/docs/backends/types/s3.html
for more information about providing credentials.

Error: NoCredentialProviders: no valid providers in chain. Deprecated.
    For verbose messaging see aws.Config.CredentialsChainVerboseErrors

So, I have tried every solution that was suggested here, but unfortunately none of them solved my issue.所以,我已经尝试了这里建议的所有解决方案,但不幸的是,它们都没有解决我的问题。 After some digging, I found a solution that worked for me.经过一番挖掘,我找到了一个适合我的解决方案。 That was executing the terraform init command with the -backend-config option like this:那是使用-backend-config选项执行terraform init命令,如下所示:

terraform init -backend-config="access_key=<your access key>" -backend-config="secret_key=<your secret key>"

This is the question where I found this solution: Error while configuring Terraform S3 Backend这是我找到此解决方案的问题: 配置 Terraform S3 后端时出错

There are couple of things you need to check.您需要检查几件事。

  1. There should be a file under .aws folder with name credentials and content of that file should be having access key and secret key. .aws文件夹下应该有一个带有名称凭据的文件,并且该文件的内容应该具有访问密钥和密钥。

     [tu] aws_access_key_id = *************** aws_secret_access_key = ************************
  2. If the above file is present with correct keys, and still same error is coming then I will suggest you should mention access key and secret key in your provider block like this如果上述文件存在正确的密钥,并且仍然出现相同的错误,那么我建议您应该在提供程序块中提及访问密钥和秘密密钥,如下所示

     provider "aws" { access_key = var.aws_access_key secret_key = var.aws_secret_key region = var.region }

And store the above variables values in .tfvars file并将上述变量值存储在.tfvars文件中

aws_access_key ="****your access key****"
aws_secret_key = "***your secret key****"

Hope with these settings it should work and even after this issue persist, then I see in your .aws/config you have mentioned mfa arn .希望通过这些设置它应该可以工作,即使这个问题仍然存在,然后我在你的 .aws/config 中看到你提到了mfa arn

If Multi-factor Authentication is enabled then try adding mfa session token in backend.tf file as well along with provider block that I have mentioned above如果启用了多因素身份验证,则尝试在backend.tf文件中添加mfa 会话令牌以及我上面提到的提供程序块

terraform {
  required_version = ">=0.12.0"
  backend "s3" {
    region  = "us-east-1"
    key     = "terraform.tfstate"
    bucket  = "terraformstatebucket3107"
    token   = "*****Your MFA SessionToken*****"
  }
}

To get the MFA SessionToken please check here要获取 MFA SessionToken,请在此处查看

运行terraform init您必须为您的凭据(aws 密钥)添加-backend-config选项。

Ran into this issue when trying to run using Terraform Cloud as the backend store for state.尝试使用 Terraform Cloud 作为状态的后端存储运行时遇到了这个问题。

Make sure to either set the Environment variables in Terraform Cloud or to set the Execution Mode to "Local" so your local system is used.确保在 Terraform Cloud 中设置环境变量或将执行模式设置为“本地”,以便使用本地系统。

I spent a while troubleshooting the profile not being found since I had set it to run "Remote" and everything else was actually correct.由于我已将其设置为运行“远程”并且其他所有内容实际上都是正确的,因此我花了一段时间对未找到的配置文件进行故障排除。

Screenshot of Terraform Cloud Execution Mode Options Terraform 云执行模式选项的屏幕截图

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

相关问题 AWS Terraform:│ 错误:配置 Terraform AWS 提供商时出错:验证提供商凭证时出错:调用 sts:GetCallerIdentity 时出错: - AWS Terraform: │ Error: error configuring Terraform AWS Provider: error validating provider credentials: error calling sts:GetCallerIdentity: Terraform 抛出错误:错误配置 Terraform AWS Provider:系统找不到指定的路径 - Terraform throwing error:error configuring Terraform AWS Provider: The system cannot find the path specified AWS Codebuild Terraform提供程序 - AWS Codebuild terraform provider 在Terraform中创建接口类型VPC端点时出错(AWS提供程序) - Error while creating interface type vpc endpoint in terraform (aws provider) 使用 AWS 和 Kubernetes 提供商的 Terraform 周期 - Terraform cycle with AWS and Kubernetes provider 使用 terraform 插件配置 intellij 以连接到 aws - configuring intellij with terraform plugin to connect to aws 为什么使用 Terraform 创建存储桶会抛出“提供者 provider.aws 不支持资源类型“aws_s3””错误? - Why does creating a bucket with Terraform throw "The provider provider.aws does not support resource type "aws_s3"" error? 配置AWS后出现错误 - Error after configuring aws 使用 terraform 的 AWS ECS 容量提供程序 - AWS ECS capacity provider using terraform 在具有SAML提供程序的AWS中使用Terraform创建ROLE - Create ROLE with Terraform in AWS with SAML provider attached
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM