Terraform - should I use user_data or provisioner to bootstrap a resource?

点点圈 提交于 2019-12-06 21:19:10

问题


It seems like I can use either user_data with a template file or a "remote-exec" provisioner with inline commands to bootstrap. So which one is considered more idiomatic?


回答1:


You should use user_data. The user data field is idiomatic because it's native to AWS, whereas the remote-exec provisioner is specific to Terraform, which is just one of many ways to call the AWS API.

Also, the user-data is viewable in the AWS console, and often an important part of using Auto Scaling Groups in AWS, where you want each EC2 Instance to execute the same config code when it launches. It's not possible to do that with Terraform's remote-exec provisioner.




回答2:


Though I do agree with Josh, if there are no run time changes to the instance you can use packer to build an ami and then use that in the launch config. That way you don't have to wait for user-data to run.

Packer is part of the Hashicorp family of tools

https://www.packer.io/docs/builders/amazon-ebs.html



来源:https://stackoverflow.com/questions/44378064/terraform-should-i-use-user-data-or-provisioner-to-bootstrap-a-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!