title: Terraform: can't remote-exec on a compute engine VM with generated SSH key
body: <p>I am trying to remotely execute some commands on a freshly provisioned Google Cloud Platform Compute Engine VM using ssh keys with Terraform. Here's my code:</p>
  
  <pre><code>resource "tls_private_key" "ssh-key" {
    algorithm = "RSA"
    rsa_bits  = 4096
  }
  
  resource "google_compute_instance" "static-content" {
  
    # ...
  
    metadata {
      sshKeys = "root:${tls_private_key.ssh-key.public_key_openssh}"
    }
  
    connection {
      type = "ssh"
      user = "root"
      private_key = "${tls_private_key.ssh-key.private_key_pem}"
    }
  
    provisioner "remote-exec" {
      inline = [
        "curl -L https://github.com/aelsabbahy/goss/releases/download/v0.3.6/goss-linux-amd64 -o ~/goss",
        "chmod +x ~/goss",
        "~/goss -g ~/gossfile.yml validate",
      ]
    }
  
  }
  </code></pre>
  
  <p>The output I get in the Terraform apply is</p>
  
  <pre><code>google_compute_instance.static-content: Still creating... (2m10s elapsed)
  google_compute_instance.static-content (remote-exec): Connecting to remote host via SSH...
  google_compute_instance.static-content (remote-exec):   Host: 35.198.166.131
  google_compute_instance.static-content (remote-exec):   User: root
  google_compute_instance.static-content (remote-exec):   Password: false
  google_compute_instance.static-content (remote-exec):   Private key: true
  google_compute_instance.static-content (remote-exec):   SSH Agent: false
  google_compute_instance.static-content (remote-exec):   Checking Host Key: false
  </code></pre>
  
  <p>So it seems like the ssh key is not properly propagated to the VM. Any hints why this doesn't work?</p>