使用Terraform将cloud-init脚本发送到GCP

4
我该如何使用terraform向gcp实例发送cloud-init脚本?
相关文档非常稀少。请参考文档
1个回答

5
你需要以下内容:

一个云初始化文件(比如'conf.yaml')

#cloud-config

# Create an empty file on the system
write_files:
- path: /root/CLOUD_INIT_WAS_HERE

cloudinit_config数据源

gzipbase64_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}"
  }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接