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

602
Vistas
Why does terraform aws code fail to render?

Terraform version = 0.12

resource "aws_instance" "bespin-ec2-web" {
  ami = "ami-0bea7fd38fabe821a"
  instance_type = "t2.micro"
  vpc_security_group_ids = [aws_security_group.bespin-sg.id]
  subnet_id = aws_subnet.bespin-subnet-public-a.id
  associate_public_ip_address = true
  tags = {
    Name = "bespin-ec2-web-a"
  }
  user_data = data.template_file.user_data.rendered
}

data "template_file" "user_data" {
template = file("${path.module}/userdata.sh")
}

userdata.sh file

 #!/bin/bash
   USERS="bespin"
   GROUP="bespin"
   for i in $USERS; do
   /usr/sbin/adduser ${i};
   /bin/echo ${i}:${i}1! | chpasswd;
   done

   cp -a /etc/ssh/sshd_config /etc/ssh/sshd_config_old
   sed -i 's/PasswordAuthentication no/#PasswordAuthentication no/' /etc/ssh/sshd_config
   sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config
   systemctl restart sshd

terraform plan result

Error: failed to render : <template_file>:5,24-25: Unknown variable; There is no variable named "i"., and 2 other di
agnostic(s)

  on instance.tf line 13, in data "template_file" "user_data":
  13: data "template_file" "user_data" {

Why am I getting an error?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The template argument in the template_file data source is processed as Terraform template syntax.

In this syntax, using ${...} has a special meaning, that the ... part will be injected by some var that is passed into the template.

Bash also allows this syntax, for getting the values of variables as your intending to use it.

To reconcile this, you'll need to escape the $ character so that the terraform template compiler will leave it be, which you can do by doubling up the character: $${i} in all cases.

https://www.terraform.io/docs/configuration/expressions.html#string-templates

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