google-cloud-platform - 使用 terraform 将 cloud-init 脚本发送到 gcp

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

如何使用 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数据源

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

关于google-cloud-platform - 使用 terraform 将 cloud-init 脚本发送到 gcp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70176647/

相关文章:

Terraform - 迭代嵌套 map

ubuntu-server - Raspberry pi 4 上的 Ubuntu Focal headless 设置 - 首次重启前的 cloud init wifi 初始化

amazon-web-services - 如何阻止 cloud-init 覆盖我在 AWS (CentOS) 上的主机名

google-cloud-platform - 在 GCP 中创建 IAM 成员会引发错误策略大小太大

google-cloud-platform - 运行 pytorch/xla 时缺少 XLA 配置

kubernetes - Google kubernetes引擎上的Pod正在等待?

google-cloud-platform - 如何列出整个 GCP Assets 中具有特定角色的所有资源?

terraform - 将配置从外部文件加载到 terraform

yaml - 云配置中 write_files 指令的正确语法?

google-cloud-platform - 如何使 Ansible Dynamic Inventory 与 Google Cloud Platform (Google Compute Engine)、GCP 一起使用