Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

600
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!