2 Answers
- Newest
- Most votes
- Most comments
0
maybe try this way:
resource "aws_instance" "example" {
# other instance configuration...
user_data = base64encode(local.user_data_script)
}
locals {
user_data_script = <<EOF
#!/bin/bash
apt update -y
apt install -y apache2
systemctl enable apache2
systemctl start apache2
echo "<h1>Welcome to Structure AWS with Terraform </h1>" > /var/www/html/index.html
EOF
}
answered 10 months ago
0
Place your UserData into a Shell script file and then reference it instead of placing it in the Raw terraform:-
/script.sh
#!/bin/bash
apt update -y
apt install -y apache2
systemctl enable apache2
systemctl start apache2
echo "<h1>Welcome to Structure AWS with Terraform </h1>" | tee /var/www/html/index.html
resource "aws_instance" "web" {
ami = var.image_id
instance_type = var.instance_type
key_name = aws_key_pair.key-tf.key_name
vpc_security_group_ids = ["${aws_security_group.allow_tls.id}"]
tags = {
Name = "first-tf-instance"
}
user_data = file("${path.module}/script.sh")
}
Relevant content
- asked 5 months ago
- asked 4 months ago
- asked a year ago
- asked 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
Change user_data to user_data_base64 if its base64 encoded as per your example