Terraform - 我应该使用 user_data 还是 Provisioner 来引导资源? [英] Terraform - should I use user_data or provisioner to bootstrap a resource?
问题描述
似乎我可以使用带有模板文件的 user_data
或带有内联命令的remote-exec" provisioner
来引导.那么哪一个被认为更惯用呢?
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?
推荐答案
你应该使用 user_data
.user data 字段是惯用的,因为它是 AWS 原生的,而 remote-exec 配置器是特定于 Terraform 的,这只是调用 AWS API 的众多方法之一.
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.
此外,用户数据可在 AWS 控制台中查看,这通常是在 AWS 中使用 Auto Scaling 组的重要部分,您希望每个 EC2 实例在启动时执行相同的配置代码.使用 Terraform 的 remote-exec 配置器无法做到这一点.
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.
这篇关于Terraform - 我应该使用 user_data 还是 Provisioner 来引导资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!