I am launching a aws_launch_configuration
instance using terraform.
I\'m using a shell script for the user_data
variable, like so:
For people coming here since Terraform 0.12 and later, the templatefile function should be used instead of using template_file resource, so for the example in the question, it would be something like
locals {
vars = {
some_address = aws_instance.some.private_ip
}
}
user-data = templatefile("router-init.sh", vars)
You can do this using a template_file data source:
data "template_file" "init" {
template = "${file("router-init.sh.tpl")}"
vars = {
some_address = "${aws_instance.some.private_ip}"
}
}
Then reference it inside the template like:
#!/bin/bash
echo "SOME_ADDRESS = ${some_address}" > /tmp/
Then use that for the user_data
:
user_data = ${data.template_file.init.rendered}