Skip to content

Instantly share code, notes, and snippets.

@janosgyerik
Created June 13, 2019 06:05
Show Gist options
  • Save janosgyerik/047decfd5d05afa2cac214ce628c412f to your computer and use it in GitHub Desktop.
Save janosgyerik/047decfd5d05afa2cac214ce628c412f to your computer and use it in GitHub Desktop.
provider "google" {
region = "${var.region}"
project = "${var.project_name}"
credentials = "${file("${var.credentials_file_path}")}"
}
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 "file" {
source = "terraform-gcp.json"
destination = "terraform-gcp.json"
connection {
host = "${self.network_interface.0.access_config.0.nat_ip}"
type = "ssh"
user = "root"
agent = true
}
}
provisioner "remote-exec" {
connection {
host = "${self.network_interface.0.access_config.0.nat_ip}"
type = "ssh"
user = "root"
agent = true
#private_key = file("${var.private_key_path}")
}
inline = [
"curl -sSL https://get.docker.com/ | sh",
"usermod -aG docker `echo $USER`",
"docker login -u _json_key --password-stdin https://gcr.io < terraform-gcp.json",
"docker pull gcr.io/capture-the-flag-243417/stripe1:v2",
"docker run -it -p 8022:22 -p 8002:8002 -p 8004:8004 gcr.io/capture-the-flag-243417/stripe1:v2"
]
}
service_account {
scopes = ["https://www.googleapis.com/auth/compute.readonly"]
}
}
resource "google_compute_firewall" "default" {
name = "tf-www-firewall"
network = "default"
allow {
protocol = "tcp"
ports = ["8022", "8002", "8005"]
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["docker-node"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment