Send cloud-init script to gcp with terraform
Asked Answered
H

1

5

How do I send cloud-init script to a gcp instance using terraform?

Documentation is very sparse around this topic.

Hillary answered 30/11, 2021 at 21:58 Comment(0)
H
8

You need the following:

A cloud-init file (say 'conf.yaml')

#cloud-config

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

cloudinit_config data source

gzip and base64_encode must be set to false (they are true by default).

data "cloudinit_config" "conf" {
  gzip = false
  base64_encode = false

  part {
    content_type = "text/cloud-config"
    content = file("conf.yaml")
    filename = "conf.yaml"
  }
}

A metadata section under the google_compute_instance resource

  metadata = {
    user-data = "${data.cloudinit_config.conf.rendered}"
  }
Hillary answered 30/11, 2021 at 21:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.