-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unclear how to add user_data to an aws_instance #145
Comments
I wonder if you can provide a full path, that would be pretty helpful if using #cloud-init for example |
I would personally prefer HERDOC style, multi-line string, rather than a path to a file. That way I can just create a variable with my cloud-init as a default and include it in whatever instances I would like. What would be cool is some kind of import syntax which would allow a file to be imported into a variable, which would keep the abstraction for the user_data (it is just a string after all), but the also allow any string in the system to be read from a file (which could be good if I run a packer command, i could output the image id to a file in my terraform directory for example). |
@mattsoftware Looks like the reason you cant provide a base64 encoded string yourself is because on line 339 (https://github.com/mitchellh/goamz/blob/2e353d54f19f99fa67b93cddc3b9d86ede74f566/ec2/ec2.go#L339) the userdata gets base64 encoded. Which would mean your string user_data = "bGluZSBvbmUKbGluZSB0d28KbGluZSB0aHJlZQo=" would actually translate to user_data = "YkdsdVpTQnZibVVLYkdsdVpTQjBkMjhLYkdsdVpTQjBhSEpsWlFvPQo=" before it gets passed to the Amazon API |
This is definitely failing at the configuration load phase, Not the aws instance creation phase. |
I was sure that it was possible to read in a file in terraform, but now I can't find the section. |
perfect. Perhaps that could be a great example for the aws_instance page :) |
@vertis Thank You This can essentially be closed as the following works: Create a multiline user_data file (example.txt):
Then in your example.tf
|
When I run the following:
The resulting user data in the created instance is:
Am I missing something? |
What is the output of terraform apply? |
|
Im getting the same thing. Seems the Interpolation isnt behaving correctly I tried both
Which yielded
and
which yielded
seems user_data is being taken as a String Literal and not getting Interpolated |
This looks like a bug, tagged, thanks! |
Fixed, thanks for finding this. |
I'm having this issue on 0.1.1, which should include this hash. I have a lunch configuration with Build succeeds with
The userdata in the LC is Same effect with:
|
I know this is closed, but this was not working for me either. I "fixed" this by backing out commit ba68be5 I don't know what that even does, but it was causing the user data to not be processed correctly at all. Without it, it works. |
Failed to load root config module: Error parsing /root/Terraform/test.tf: At 25:15: illegal char Line 25: |
@naul11 |
I must leave my 2cents here:
|
This worked for me, though I could have sworn I didn't need to do this before:
|
How can you pass to a user_data's script some arguments? Something like: user_data = "${file("user-data.ps1") -Arg1 ${var.variable}}" |
@Daniel96 : take a look at the template resource |
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. |
I have been trying to add user_data to my aws instance. Things I tried before getting some success....
user_data = "line one
line two
line three"
user_data = [
"line one",
"line two",
"line three"
]
user_data = "bGluZSBvbmUKbGluZSB0d28KbGluZSB0aHJlZQo="
user_data = "line one\nline two\nline three\n"
I think this needs to be clearer in the documentation, or providing other ways of providing the information (if there isn't already, i.e., can we do multi-line strings within the syntax of the config file?) There doesn't seem to be any mention of multi-line string values on the syntax page to give any hints either.
The text was updated successfully, but these errors were encountered: