Solucionado (ver solução)
Solucionado
(ver solução)
7
respostas

Erro ao executar Terraform plan

Terraform\terraform> terraform init

Initializing the backend...

Initializing provider plugins...
- Finding latest version of hashicorp/us-west-2...
- Reusing previous version of hashicorp/aws from the dependency lock file
- Using previously-installed hashicorp/aws v2.70.0
╷
│ Warning: Version constraints inside provider configuration blocks are deprecated
│
│   on main.tf line 3, in provider "aws":
│    3:     version = "~> 2.0"
│
│ Terraform 0.13 and earlier allowed provider version constraints inside the provider configuration block, but that is now deprecated and will be removed in a future version of Terraform. To silence this warning, move the provider       
│ version constraint into the required_providers block.
│
│ (and one more similar warning elsewhere)
╵

╷
│ Warning: Quoted references are deprecated
│
│   on main.tf line 58, in resource "aws_instance" "dev6":
│   58:     depends_on = ["aws_dynamodb_table.dynamodb-homologação"]
│
│ In this context, references are expected literally rather than in quotes. Terraform 0.11 and earlier required quotes, but quoted references are now deprecated and will be removed in a future version of Terraform. Remove the quotes     
│ surrounding this reference to silence this warning.
│
│ (and 2 more similar warnings elsewhere)
╵

╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/us-west-2: provider registry registry.terraform.io does not have a provider named registry.terraform.io/hashicorp/us-west-2
│
│ All modules should specify their required_providers so that external consumers will get the correct providers when using a module. To see which modules are currently depending on hashicorp/us-west-2, run the following command:
│     terraform providers
╵

terraform> terraform plan
╷
│ Warning: Version constraints inside provider configuration blocks are deprecated
│
│   on main.tf line 3, in provider "aws":
│    3:     version = "~> 2.0"
│
│ Terraform 0.13 and earlier allowed provider version constraints inside the provider configuration block, but that is now deprecated and will be removed in a future version of Terraform. To silence this warning, move the provider       
│ version constraint into the required_providers block.
│
│ (and one more similar warning elsewhere)
╵
╷
│ Warning: Quoted references are deprecated
│
│   on main.tf line 58, in resource "aws_instance" "dev6":
│   58:     depends_on = ["aws_dynamodb_table.dynamodb-homologação"]
│
│ In this context, references are expected literally rather than in quotes. Terraform 0.11 and earlier required quotes, but quoted references are now deprecated and will be removed in a future version of Terraform. Remove the quotes     
│ surrounding this reference to silence this warning.
│
│ (and 2 more similar warnings elsewhere)
╵
╷
│ Error: Could not load plugin
│
│
│ Plugin reinitialization required. Please run "terraform init".
│
│ Plugins are external binaries that Terraform uses to access and manipulate
│ resources. The configuration provided requires plugins which can't be located,
│ don't satisfy the version constraints, or are otherwise incompatible.
│
│ Terraform automatically discovers provider requirements from your
│ configuration, including providers used in child modules. To see the
│ requirements and constraints, run "terraform providers".
│
│ failed to instantiate provider "registry.terraform.io/hashicorp/us-west-2" to obtain schema: unknown provider "registry.terraform.io/hashicorp/us-west-2"
│
╵
7 respostas

Oi Felipe

Envia o código do seu arquivo terraform aqui, por favor

Bom dia.

#Preparando o ambiente na AWS
provider "aws" {
    version = "~> 2.0"
    region = "us-east-2"
}

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


#Preparando Instancia AWS
resource "aws_instance" "dev" {
    count = 3
    ami = "ami-0b9064170e32bde34"
    instance_type = "t2.micro"
    key_name = "terraform-aws"
    tags = {
        Name = "dev${count.index}"
    }
    vpc_security_group_ids = ["${aws_security_group.acesso-ssh.id}"]
}

resource "aws_instance" "dev4" {

    ami = "ami-0b9064170e32bde34"
    instance_type = "t2.micro"
    key_name = "terraform-aws"
    tags = {
        Name = "dev4"
    }
    vpc_security_group_ids = ["${aws_security_group.acesso-ssh.id}"]
    #Chamando o Bucket
    depends_on = [aws_s3_bucket.dev4]

}

resource "aws_instance" "dev5" {
    ami = "ami-0b9064170e32bde34"
    instance_type = "t2.micro"
    key_name = "terraform-aws"
    tags = {
        Name = "dev5"
    }
    vpc_security_group_ids = ["${aws_security_group.acesso-ssh.id}"]
}

resource "aws_instance" "dev6" {
    ami = "ami-087c17d1fe0178315"
    instance_type = "t2.micro"
    key_name = "terraform-aws"
    tags = {
        Name = "dev6"
    }
    vpc_security_group_ids = ["${aws_security_group.acesso-ssh-us-west-2.id}"]
    depends_on = ["aws_dynamodb_table.dynamodb-homologação"]
}

#Criação de Bucket
resource "aws_s3_bucket" "dev4" {
  bucket = "lab-terraform-dev4"
  acl    = "private"

  tags = {
    Name = "lab-terraform-dev4"
  }
}

#Criação de DB
resource "aws_dynamodb_table" "dynamodb-homologação" {
  provider       = "us-west-2"
  name           = "GameScores"
  billing_mode   = "PAY_PER_REQUEST"
  hash_key       = "UserId"
  range_key      = "GameTitle"

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

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

Oi Felipe,

Por que você colocou provider como "us-west-2" no dynamodb-homologação?

resource "aws_dynamodb_table" "dynamodb-homologação" {
  provider       = "us-west-2"

Não encontrei nada na documentação sobre esse campo: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/dynamodb_table

Otávio, bom dia.

É por que estou provisionando uma outra máquina e banco na região aws.us-west-2, no qual esta chamada de dev. De acordo com o video abaixo.

https://cursos.alura.com.br/course/terraform/task/59909

solução!
Could not retrieve the list of available versions for provider hashicorp/us-west-2: provider registry registry.terraform.io does not have a provider named registry.terraform.io/hashicorp/us-west-2

Pela mensagem de erro, esse provider não existe:

resource "aws_dynamodb_table" "dynamodb-homologação" {
  provider       = "us-west-2"

tenta arrumar o alias abaixo

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

para

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

Olá tudo bem?

Eu acredito que seja a versão do terraform (atualmente 1.0.8, acredito que versão usada nesse curso seja 0.11) + versão do provider ...

Recomendo fazer o seguinte, primeiro usar um gerenciador de versão como o https://asdf-vm.com/ em seguida instalar o plugin terraform no asdf asdf plugin add terraform depois listar as versões disponíveis asdf list all terraform e instalar e ativar a versão exata que é utilizada no curso (para saber como trabalhar com múltiplas versões de ferramenta https://asdf-vm.com/manage/versions.html#install-version).

Usar a mesma versão do curso + as correções que o Otávio sugeriu sobre provider, eu acredito que vai certo.

Um abraço e bons estudos.

Boa noite.

Acabei refazendo novamente o passo a passo, no qual o mesmo foi executado com sucesso.

Muito obrigado pela ajuda.