配置 Terraform AWS 提供商时出错 - Linux

5 amazon-s3 amazon-web-services docker terraform terraform-provider-aws

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

我现在已经尝试了将 terraform 与 s3 集成的教程。S3 存储桶已创建,我已创建 IAM 用户,并且正在使用其访问密钥和秘密密钥。尽管如此,我在之后仍然收到有关提供商的错误terraform init

后端.tf

terraform {
  required_version = ">=0.12.0"
  backend "s3" {
    region  = "us-east-1"
    key     = "terraform.tfstate"
    profile = "tu"
    bucket  = "terraformstatebucket3107"
  }
}
Run Code Online (Sandbox Code Playgroud)

.aws 文件夹中的配置文件

[tu]
region = us-east-1
output = json
Run Code Online (Sandbox Code Playgroud)

.aws 文件夹中的凭证文件

[tu]
aws_access_key_id = AKIA*****************
aws_secret_access_key = nn3M1*****************
Run Code Online (Sandbox Code Playgroud)

错误:

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
Run Code Online (Sandbox Code Playgroud)

小智 2

因此,我尝试了这里建议的所有解决方案,但不幸的是它们都没有解决我的问题。经过一番挖掘,我找到了一个适合我的解决方案。这是terraform init使用-backend-config如下选项执行命令:

terraform init -backend-config="access_key=<your access key>" -backend-config="secret_key=<your secret key>"
Run Code Online (Sandbox Code Playgroud)

这是我找到此解决方案的问题: Error while Configuration Terraform S3 Backend