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-private-a.id
associate_public_ip_address = true
tags = {
Name = "bespin-ec2-web-a"
}
user_data = <<EOF
#!/bin/bash
USERS="bespin"
GROUP="bespin"
for i in $USERS; do
adduser ${i} -g ${GROUP};
echo ${i}:${i}1! | chpasswd;
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
EOF
}
Why do I get an error when running terraform plan?
Error: Invalid reference
on instance.tf line 15, in resource "aws_instance" "bespin-ec2-web": 15: adduser ${i} -g ${GROUP};
A reference to a resource type must be followed by at least one attribute access, specifying the resource name.
Error: Invalid reference
on instance.tf line 15, in resource "aws_instance" "bespin-ec2-web": 15: adduser ${i} -g ${GROUP};
A reference to a resource type must be followed by at least one attribute access, specifying the resource name.
${}
with another$
if you wanted to keep it inline. Also you shouldn't indent inside a HEREDOC. – ydaetskcoR