2
respostas

No valid credential sources found for AWS Provider.

Após migrar para o Terraform Cloud, estou recebendo este erro ao executar "terraform apply".

remote-state.tf

# Using a single workspace:
terraform {
  backend "remote" {
    hostname = "app.terraform.io"
    organization = "grgouveia"

    workspaces {
      name = "aws-grgouvei"
    }
  }
}

main.tf

# Configure the AWS Provider
provider "aws" {  
  version = "~> 2.0"
  region  = "sa-east-1"
}

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

resource "aws_s3_bucket" "dip" {
  bucket = "grgouveia-dip"
  acl    = "private"

  tags = {
    Name = "dip"
  }
}

resource "aws_instance" "k8s-master" {
    ami = "${var.amis["sa-east-1"]}"
    instance_type = "t2.micro"

    # each region must have its own key pairs
    key_name = "${var.key_name}"

    tags = {
        Name = "k8s-master"
    }

    # Bind ssh security group refering the security group name's variable "allow-ssh"
    vpc_security_group_ids = ["${aws_security_group.allow-ssh.id}"]

    depends_on = ["aws_s3_bucket.dip", "aws_dynamodb_table.dynamodb-homologation"]
}   

resource "aws_instance" "worker-nodes" {
    count = 2
    ami = "${var.amis["sa-east-1"]}"
    instance_type = "t2.micro"

    # each region must have its own key pairs
    key_name = "${var.key_name}"

    tags = {
        Name = "node${count.index}"
    }

    # Bind ssh security group refering the security group name's variable "allow-ssh"
    vpc_security_group_ids = ["${aws_security_group.allow-ssh.id}"]

    depends_on = ["aws_s3_bucket.dip"]
}   


resource "aws_instance" "ansible" {
    provider = "aws.us-east-1"

    ami = "${var.amis["us-east-1"]}"
    instance_type = "t2.micro"

    # each region must have its own key pairs
    key_name = "${var.key_name}"

    tags = {
        Name = "ansible"
    }

    # Bind ssh security group refering the security group name's variable "allow-ssh"
    vpc_security_group_ids = ["${aws_security_group.allow-ssh-us-east-1.id}"]

    depends_on = ["aws_s3_bucket.dip"]
}   

resource "aws_dynamodb_table" "dynamodb-homologation" {
  name           = "DIP"
  billing_mode   = "PAY_PER_REQUEST"
  hash_key       = "UserId"
  range_key      = "GameTitle"

  attribute {
    name = "UserId"
    type = "S"
  }

  attribute {
    name = "GameTitle"
    type = "S"
  }

  attribute {
    name = "TopScore"
    type = "N"
  }

  ttl {
    attribute_name = "TimeToExist"
    enabled        = false
  }

  global_secondary_index {
    name               = "GameTitleIndex"
    hash_key           = "GameTitle"
    range_key          = "TopScore"
    write_capacity     = 10
    read_capacity      = 10
    projection_type    = "INCLUDE"
    non_key_attributes = ["UserId"]
  }

  tags = {
    Name = "dynamodb-dip-1"
  }
}

outputs.tf

output "k8s-master-ip" {
    value = "${aws_instance.k8s-master.public_ip}"
}

output "node1-ip" {
  value = "${aws_instance.worker-nodes[0].public_ip}"
}

output "node2-ip" {
  value = "${aws_instance.worker-nodes[1].public_ip}"
}

output "ansible-ip" {
  value = "${aws_instance.ansible.public_ip}"
}

vars.tf

output "k8s-master-ip" {
    value = "${aws_instance.k8s-master.public_ip}"
}

output "node1-ip" {
  value = "${aws_instance.worker-nodes[0].public_ip}"
}

output "node2-ip" {
  value = "${aws_instance.worker-nodes[1].public_ip}"
}

output "ansible-ip" {
  value = "${aws_instance.ansible.public_ip}"
}
2 respostas

O backend "remote" do Terraform Cloud roda as instruções remotamente e não na máquina local, então é necessário configurar as credenciais no workspace do Terraform Cloud.

https://www.terraform.io/docs/cloud/workspaces/variables.html

Olá Guilherme, tudo bem? É isso mesmo, também passei pelo mesmo problema, o erro acontece porque precisamos definir as credencias de acesso a AWS no Terraform Cloud, porque ele é quem faz a executação das instruções, então ele precisa ter o acesso a AWS, para isso precisamos definir a AWS_ACCESS_KEY_ID e a AWS_SECRET_ACCESS_KEY nas variáveis de ambiente do Terraform Cloud, muito legal que você informou a solução aqui na comunidade. Continue assim e bons estudos!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software