Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

469
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda