I'm trying to read the content for a user_data from a file.
resource "aws_launch_configuration" "webfarm" {
name = "web_config"
image_id = "ami-c5b7d8b2"
instance_type = "t2.micro"
security_groups = ["${aws_security_group.web-instance.id}"]
user_data = ${file("user-data.web")}
}
when running terraform plan I get the error:
Error loading config: Error parsing /home/patrick/dev/tf/main.tf: Line 616, column 16: syntax error
Uncommenting this syntax makes the error go away.
I feel it must be something trivial ... maybe file is not the correct directive, but template is?
"${file("user-data.web")}" or "${file('user-data.web')}"user_data worksUsing a template seems to work fine, so I have a workaround.
Maybe it's just the description in the doc on file and old examples that put me on the wrong foot.
file(path) - Reads the contents of a file into the string. Variables in this file are not interpolated. The contents of the file are read as-is.
resource "template_file" "web-userdata" {
filename = "user-data.web"
}
resource "aws_launch_configuration" "webfarm" {
name = "web_config"
image_id = "ami-c5b7d8b2"
instance_type = "t2.micro"
security_groups = ["${aws_security_group.web-instance.id}"]
user_data = "${template_file.web-userdata.rendered}"
//user_data = ${file("user-data.web")}
}
This change should work:
- user_data = ${file("user-data.web")}
+ user_data = "${file("user-data.web")}"
But I see you already tried that. All I can add is that I use the exact same syntax, and that one is working for me:
resource "aws_instance" "..." {
user_data = "${file("../../tmp/aws/userdata.sh")}"
...
}
I am using the latest HEAD version (built using make dev), but this functionality has been present for a while now, so I doubt that could be the solution.
Also, my use-case is with aws_instance, instead of aws_launch_configuration, so perhaps these work differently.
@JeanMertz guess I wasn't as observant , "${file("user-data.web")}" works "${file('user-data.web')}".
closing the issue here.
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
This change should work:
But I see you already tried that. All I can add is that I use the exact same syntax, and that one is working for me:
I am using the latest HEAD version (built using
make dev), but this functionality has been present for a while now, so I doubt that could be the solution.Also, my use-case is with
aws_instance, instead ofaws_launch_configuration, so perhaps these work differently.