How do I use the file provisioner with google_compute_instance_template?
<p>Using Terraform, I need to copy files to Google Compute Engine instance templates. For this I normally use the <a href="https://www.terraform.io/docs/provisioners/file.html" rel="noreferrer">file provisioner</a>, but it doesn't work since it depends on <a href="https://www.terraform.io/docs/provisioners/connection.html" rel="noreferrer">SSH connections</a>, which fail due to requiring externally accessible host addresses. Due to the dynamic nature of instance templates, I don't know how to assign externally accessible host addresses to instances.</p>

<p>How can I implement copying of files to GCE instances created through instance templates (via Terraform)?</p>

<h2>Example Terraform google_compute_instance_template Definition</h2>

<pre><code>resource "google_compute_instance_template" "node" {
  name = "kubernetes-node-template"
  machine_type = "g1-small"
  can_ip_forward = true
  tags = ["staging", "node"]

  network_interface {
    network = "default"
  }

  provisioner "file" {
    source = "worker/assets/kubelet.service"
    destination = "/etc/systemd/system/kubelet.service"
  }

  connection {
    user = "core"
    type = "ssh"
    private_key = "${file("~/.ssh/id_rsa")}"
  }
}
</code></pre>