Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

473
Visualizações
terraform :An input variable with the name "AMI" has not been declared. This variable can be declared with a variable "AMI" {} block

I am new to terraform. I was trying my bit on terrafrom

I have this bit in var.tfvars

variable "AWS_REGION" {    
default = "me-south-1"
}
variable "AMI" {
    type = "map"
    
    default ={
        me-south-1 = "ami-01b735b798*******"
        us-east-1 = "ami-0c2a1acae666******"
    }
}

and I am trying to create an ec2 in VPC by

resource "aws_instance" "terraform-web" {
ami = "${lookup(var.AMI, var.AWS_REGION)}"
instance_type = "t3.micro"

which is giving me the above-mentioned error.

Could anyone help me out with this ?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The way terraform works is:

variables.tf -- all variables are declared in this file

vars.tfvars -- all values are passed via this file. Name can be anything. should end with tfvars.

You don't need to use lookup just var.<variable_name> is enough!

ec2.tf:

    resource "aws_instance" "terraform-web" {
    ami = var.ami_id
    instance_type = "t3.micro"
}

variables.tf

variable "ami_id" {
    type = "string"
    default = "xxxx"

}

vars.tfvars

ami_id = "yyyyy"
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda