Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
google_compute_instance.docker[0]: Creating...
google_compute_instance.docker[0]: Still creating... [10s elapsed]
google_compute_instance.docker[0]: Still creating... [20s elapsed]
google_compute_instance.docker[0]: Provisioning with 'remote-exec'...


Error: Failed to parse ssh private key: ssh: cannot decode encrypted private keys
resource "google_compute_instance" "docker" {
  count = 1

  name         = "tf-docker-${count.index}"
  machine_type = "f1-micro"
  zone         = "${var.region_zone}"
  tags         = ["docker-node"]

  boot_disk {
    initialize_params {
      image = "ubuntu-os-cloud/ubuntu-1404-trusty-v20160602"
    }
  }

  network_interface {
    network = "default"

    access_config {
      # Ephemeral
    }
  }

  metadata = {
    ssh-keys = "root:${file("${var.public_key_path}")}"
  }

  provisioner "remote-exec" {
    connection {
      host        = "${self.network_interface.0.access_config.0.nat_ip}"
      type        = "ssh"
      user        = "root"
      agent       = false
      private_key = file("${var.private_key_path}")
    }

    inline = [
      "sudo curl -sSL https://get.docker.com/ | sh",
      "sudo usermod -aG docker `echo $USER`",
      "sudo docker run -d -p 80:80 nginx"
    ]
  }

  service_account {
    scopes = ["https://www.googleapis.com/auth/compute.readonly"]
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.