5

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

Documentation is very sparse around this topic.

1 Answer 1

10

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}"
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.