【问题标题】:Send cloud-init script to gcp with terraform使用 terraform 将 cloud-init 脚本发送到 gcp
【发布时间】:2022-01-07 14:21:48
【问题描述】:

如何使用 terraform 将 cloud-init 脚本发送到 gcp 实例?

Documentation 在这个话题上很少见。

【问题讨论】:

    标签: google-cloud-platform terraform-provider-gcp


    【解决方案1】:

    您需要以下内容:

    一个 cloud-init 文件(比如“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}"
      }
    

    【讨论】:

      猜你喜欢
      • 2021-01-14
      • 1970-01-01
      • 2016-11-25
      • 2019-11-04
      • 1970-01-01
      • 1970-01-01
      • 2020-11-25
      • 1970-01-01
      • 2023-03-28
      相关资源
      最近更新 更多