I need to create an AWS instance with user-data using terraform. I'm using terraform 0.10.0
.
ec2.tf
data "template_file" "user_data" {
template = "userdata.tpl"
}
resource "aws_instance" "fluentd-web" {
ami = "${lookup(var.amis, var.aws_region)}"
instance_type = "t2.micro"
subnet_id = "${var.subnet_id}"
user_data = "${data.template_file.user_data.rendered}"
security_groups =[ "${aws_security_group.ec2_sg.id}" ]
connection {
***
}
}
userdata.tpl
#! /bin/bash
apt install <**>
On applying the terraform, It shows no error. But the contents of the file is not getting populated as user-data. It just shows the file name as user-data.
How can I get the contents of the file as user-data?
Set the template as below:
template = "${file("${path.module}/userdata.tpl")}"
Here we use ${path.module}
to get a module-relative path.
Reference: https://www.terraform.io/docs/modules/create.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With