title: How to use cloud-init with a debian-based image on Google Cloud?
body: <p>Following terraform <a href="https://github.com/hashicorp/terraform/blob/f6e648cc8b4e34242c5f5df144778614b98c6ef8/website/docs/provisioners/index.html.markdown#passing-data-into-virtual-machines-and-other-compute-resources" rel="noreferrer">best practice</a> for bootstrapping instances, I'm working on a <code>cloud-init</code> config in order to bootstrap my instance. My only need is to install a specific package.</p>
  
  <p>My terraform config looks like this:</p>
  
  <pre><code>resource "google_compute_instance" "bastion" {
    name         = "my-first-instance"
    machine_type = "n1-standard-1"
    zone         = "europe-west1-b"
  
    boot_disk {
      initialize_params {
        image = "debian-cloud/debian-9"
      }
    }
  
    network_interface {
      network = "default"
  
      access_config {
        // Ephemeral IP
      }
    }
  
    metadata = {
      ssh-keys = "eugene:${file("/Users/eugene/.ssh/id_rsa.pub")}"
      user-data = file("my_cloud_init.conf")
    }
  }
  </code></pre>
  
  <p>Following <a href="https://cloudinit.readthedocs.io/en/latest/topics/examples.html#install-arbitrary-packages" rel="noreferrer">example</a> for installing packages from <code>cloud-init</code> docs, here's the contents of <code>my_cloud_init.conf</code>:</p>
  
  <pre><code>#cloud-config
  
  packages:
   - kubectl
  </code></pre>
  
  <p>After running <code>terraform plan -out myplan</code> and <code>terraform apply myplan</code>, I ssh onto the node only to find <code>kubectl</code> not available. Moreover, there's no evidence that <code>cloud-init</code> was run or that it exists on the node:</p>
  
  <pre><code>$ which -a cloud-init
  $ cat /var/log/cloud-init
  cat: /var/log/cloud-init: No such file or directory
  </code></pre>
  
  <p>Looking for clues about usage of <code>cloud-init</code> with Google Cloud Compute instances wasn't fruitful:</p>
  
  <ul>
  <li>"<a href="https://cloudinit.readthedocs.io/en/latest/topics/datasources/gce.html" rel="noreferrer">Google Cloud Engine</a>" page from <code>cloud-init</code> docs suggests settings <code>user-data</code> to a <code>cloud-init</code> config should be enough,</li>
  <li>I see a <code>cloud-init</code> <a href="https://cloud.google.com/container-optimized-os/docs/how-to/create-configure-instance#using_cloud-init" rel="noreferrer">tutorial</a>, but it's for <code>Container Optimized OS</code>,</li>
  <li>there are <a href="https://github.com/GoogleCloudPlatform/compute-image-packages/search?q=%22cloud-init%22&amp;unscoped_q=%22cloud-init%22&amp;type=Issues" rel="noreferrer">some clues</a> about <code>cloud-init</code> on other images, but nothing indicates <code>cloud-init</code> is available on <code>debian-cloud/debian-9</code>,</li>
  <li>there's "<a href="https://cloud.google.com/compute/docs/startupscript" rel="noreferrer">Running startup scripts</a>", but it has no mention of <code>cloud-init</code>.</li>
  </ul>
  
  <p>I don't mind using another image, as long as it's Debian or Ubuntu and I don't have to make an image template myself.</p>
  
  <p><strong>How to use <code>cloud-init</code> with a debian-based image on Google Cloud? What am I missing?</strong></p>