找不到 Terraform AWS 提供商的有效凭证源

ti_*_*key 4 credentials amazon-web-services terraform

我正在将shared_cred_file用于aws提供商。以 aws 提供程序版本 3.63 为例,terraform plan 效果很好。

\n

当我使用 aws 提供程序 4.0 时,它提示我对共享凭证文件使用应用更改设置。修改后没有报错,但还是第二个错误

\n

可能是什么问题呢?

\n
Warning: Argument is deprecated\n\xe2\x94\x82\n\xe2\x94\x82   with provider[\xe2\x80\x9cregistry.terraform.io/hashicorp/aws\xe2\x80\x9d],\n\xe2\x94\x82   on main.tf line 15, in provider \xe2\x80\x9caws\xe2\x80\x9d:\n\xe2\x94\x82   15:   shared_credentials_file = \xe2\x80\x9c~/.aws/credentials\xe2\x80\x9d\n\xe2\x94\x82\n\xe2\x94\x82 Use shared_credentials_files instead.\n\xe2\x94\x82\n\xe2\x94\x82 (and one more similar warning elsewhere)\n\xe2\x95\xb5\n\xe2\x95\xb7\n\xe2\x94\x82 Error: error configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found.\n\xe2\x94\x82\n\xe2\x94\x82 Please see https://registry.terraform.io/providers/hashicorp/aws\n\xe2\x94\x82 for more information about providing credentials.\n\xe2\x94\x82\n\xe2\x94\x82 Error: no EC2 IMDS role found, operation error ec2imds: GetMetadata, canceled, context deadline exceeded\n\xe2\x94\x82\n\xe2\x94\x82\n\xe2\x94\x82   with provider[\xe2\x80\x9cregistry.terraform.io/hashicorp/aws\xe2\x80\x9d],\n\xe2\x94\x82   on main.tf line 13, in provider \xe2\x80\x9caws\xe2\x80\x9d:\n\xe2\x94\x82   13: provider \xe2\x80\x9caws\xe2\x80\x9d {\n\xe2\x94\x82\n
Run Code Online (Sandbox Code Playgroud)\n
///////////////////////////////\n// Infrastructure init\nterraform {\n  backend "s3" {\n    bucket                  = "monitoring-********-infrastructure"\n    key                     = "tfstates/********-non-prod-rds-info.tfstate"\n    profile                 = "test-prof"\n    region                  = "eu-west-2"\n    shared_credentials_file = "~/.aws/credentials"\n  }\n}\n\n    provider "aws" {\n      profile                 = "test-prof"\n      shared_credentials_files = ["~/.aws/credentials"]\n      region                  = "eu-west-2"\n    }\n
Run Code Online (Sandbox Code Playgroud)\n
    Error: error configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found.\n        \xe2\x94\x82\n        \xe2\x94\x82 Please see https://registry.terraform.io/providers/hashicorp/aws\n        \xe2\x94\x82 for more information about providing credentials.\n        \xe2\x94\x82\n        \xe2\x94\x82 Error: no EC2 IMDS role found, operation error ec2imds: GetMetadata, canceled, context deadline exceeded\n        \xe2\x94\x82\n        \xe2\x94\x82\n        \xe2\x94\x82   with provider["registry.terraform.io/hashicorp/aws"],\n        \xe2\x94\x82   on main.tf line 13, in provider "aws":\n        \xe2\x94\x82   13: provider "aws" {\n\n
Run Code Online (Sandbox Code Playgroud)\n

猫配置

\n
[test-prof]\noutput = json\nregion = eu-west-2\n
Run Code Online (Sandbox Code Playgroud)\n

猫凭证

\n
[test-prof]\naws_access_key_id = ****************\naws_secret_access_key = ******************\n
Run Code Online (Sandbox Code Playgroud)\n

小智 5

根据最新的 Terraform 文档,这就是它的工作方式,

provider "aws" {
  region                    = "us-east-1"
  shared_credentials_files  = ["%USERPROFILE%/.aws/credentials"]
  profile                   = "customprofile"
}
Run Code Online (Sandbox Code Playgroud)

我遇到了同样的问题,这件事对我有用。