Terraform: AWS bucket

Hello I am doing a terraform course and I came across an error that I am not able to pass. I created a container in docker with terraform and it has the following files main.tf,ec2.tf,output.tf,variable.tf. I created an IAM on aws and gave the administrator access permission for it, inside the container export my key and secret key, also create a bucket on aws and ta how I publish the permissions of it. When inside the container I am giving the command terraform init so it is giving this error:

Initializing the backend... Error refreshing state: AllAccessDisabled: All access to this object has been disabled status code: 403, request id: 63C2B2B19AFF684C, host id: N33 / aFmFs5JfC3BZcWazaotlEjp+wKk5kfR3Pq1Kg7NG1soDv06wyJTK9Jbxkwajnd215ppku50 =

provider "aws" {
  region  = "us-east-2"
  version = "~> 2.0"
}

terraform {
  backend "s3" {
    # Lembre de trocar o bucket para o seu, não pode ser o mesmo nome
    bucket = "terraformgerson"
    key    = "terraform-test.tfstate"
    region = "us-east-2"
    encrypt = "true"
    dynamodb_table = "terraform-state-lock-dynamo"
  }
} 

The buccket I created on aws is named terraformgerson

Author: Krismorte, 2020-03-25

2 answers

The Code is not wrong, its own error message is very clear, not being able to connect to the bucket for lack of permission...

May be declaring wrong node "access_key and secret_key", Where Are You declaring? tries to do by environment variable (recommended way) than direct in provider.

 0
Author: danilo ferreira, 2020-04-13 16:24:39

When you are inside the container you must use the command below followed by your AWS credentials.

export AWS_ACCESS_KEY=AQUI_A_SUA_CHAVE_DE_ACESS0
export AWS_SECRET_ACCESS_KEY=AQUI_A_SUA_CHAVE_SECRETA_DE_ACESS0

Then just send terrafom init

 0
Author: Yassui Kimura, 2020-08-07 15:09:02