如何使用 terraform 将 cloud-init 脚本发送到 gcp 实例?
Documentation围绕这个话题非常稀疏。
最佳答案
您需要具备以下条件:
cloud-init 文件(例如“conf.yaml”)
#cloud-config
# Create an empty file on the system
write_files:
- path: /root/CLOUD_INIT_WAS_HERE
cloudinit_config数据源
gzip
和 base64_encode
必须设置为 false
(它们默认为 true
)。
data "cloudinit_config" "conf" {
gzip = false
base64_encode = false
part {
content_type = "text/cloud-config"
content = file("conf.yaml")
filename = "conf.yaml"
}
}
google_compute_instance 资源下的元数据部分
metadata = {
user-data = "${data.cloudinit_config.conf.rendered}"
}
关于google-cloud-platform - 使用 terraform 将 cloud-init 脚本发送到 gcp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70176647/