1. ホーム
  2. amazon-web-services

[解決済み] Terraform AWS Provider の有効なクレデンシャルソースが見つかりません。

2022-03-03 21:58:19

質問

awsプロバイダでshared_cred_fileを使用しています。awsプロバイダのバージョンが3.63の場合、terraformプランが正常に動作しています。

awsプロバイダー4.0を使用すると、shared_credentials_filesの変更した設定を適用するように促されます。変更後、エラーは発生しませんが、2つ目のエラーが残っています。

何が問題なのでしょうか?

Warning: Argument is deprecated
│
│   with provider[“registry.terraform.io/hashicorp/aws”],
│   on main.tf line 15, in provider “aws”:
│   15:   shared_credentials_file = “~/.aws/credentials”
│
│ Use shared_credentials_files instead.
│
│ (and one more similar warning elsewhere)
╵
╷
│ Error: error configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found.
│
│ Please see https://registry.terraform.io/providers/hashicorp/aws
│ for more information about providing credentials.
│
│ Error: no EC2 IMDS role found, operation error ec2imds: GetMetadata, canceled, context deadline exceeded
│
│
│   with provider[“registry.terraform.io/hashicorp/aws”],
│   on main.tf line 13, in provider “aws”:
│   13: provider “aws” {
│

///////////////////////////////
// Infrastructure init
terraform {
  backend "s3" {
    bucket                  = "monitoring-********-infrastructure"
    key                     = "tfstates/********-non-prod-rds-info.tfstate"
    profile                 = "test-prof"
    region                  = "eu-west-2"
    shared_credentials_file = "~/.aws/credentials"
  }
}

    provider "aws" {
      profile                 = "test-prof"
      shared_credentials_files = ["~/.aws/credentials"]
      region                  = "eu-west-2"
    }

    Error: error configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found.
        │
        │ Please see https://registry.terraform.io/providers/hashicorp/aws
        │ for more information about providing credentials.
        │
        │ Error: no EC2 IMDS role found, operation error ec2imds: GetMetadata, canceled, context deadline exceeded
        │
        │
        │   with provider["registry.terraform.io/hashicorp/aws"],
        │   on main.tf line 13, in provider "aws":
        │   13: provider "aws" {


猫コンフィグ

[test-prof]
output = json
region = eu-west-2

認証情報

[test-prof]
aws_access_key_id = ****************
aws_secret_access_key = ******************

解決方法は?

変更する

provider "aws" {
  shared_credentials_file = "$HOME/.aws/credentials"
  profile                 = "default"
  region                  = "us-east-1"
}

になります。

provider "aws" {
  shared_credentials_file = "/Users/me/.aws/credentials"
  profile                 = "default"
  region                  = "us-east-1"
}

が動作しました。