Reputation: 11
I'm getting started on using Terraform to spin up AWS EC2 machines. I see some resources online pointing to the use of template_file resources, which I'm not sure what it really does compared to cloudinit.
From my understanding, cloud-init is for bootstrapping, where you load up multiple scripts from your local machine into the /var/lib/instance/scripts
directory on the EC2 instances, where they will be ran automatically using whatever interpreter you specified. Then, what do we need to render in template_file
?
Also, another question I have is are we only allowed to run bash scripts as part of cloud-init, or is python interpreter allowed as well?
Upvotes: 1
Views: 2653
Reputation: 6636
template_file
is handy in situations when you want to render bash script with values from other resources in Terraform configuration and pass it as user-data when launching EC2 instance. Only shell scripts and cloud-init directives are allowed, as it says below:
When you launch an instance in Amazon EC2, you have the option of passing user data to the instance that can be used to perform common automated configuration tasks and even run scripts after the instance starts. You can pass two types of user data to Amazon EC2: shell scripts and cloud-init directives. You can also pass this data into the launch wizard as plain text, as a file (this is useful for launching instances via the command line tools), or as base64-encoded text (for API calls).
More info: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html
Upvotes: 1