简体   繁体   中英

Error configuring Terraform AWS Provider - Linux

[----------------------- UPDATE --------------------------]

I have tried a tutorial to integrate terraform with s3 now. The S3 bucket is created and I have created an IAM user, and I am using its Access key and secret key. Nonetheless I keep getting errors regarding the providers after terraform init :

backend.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

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

credentials file in .aws folder

[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:

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

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.

     [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

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 .

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

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

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

Ran into this issue when trying to run using Terraform Cloud as the backend store for state.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM