github.com/adrian-bl/terraform@v0.7.0-rc2.0.20160705220747-de0a34fc3517/examples/google-two-tier/main.tf (about) 1 # See https://cloud.google.com/compute/docs/load-balancing/network/example 2 3 provider "google" { 4 region = "${var.region}" 5 project = "${var.project_name}" 6 credentials = "${file("${var.credentials_file_path}")}" 7 } 8 9 resource "google_compute_http_health_check" "default" { 10 name = "tf-www-basic-check" 11 request_path = "/" 12 check_interval_sec = 1 13 healthy_threshold = 1 14 unhealthy_threshold = 10 15 timeout_sec = 1 16 } 17 18 resource "google_compute_target_pool" "default" { 19 name = "tf-www-target-pool" 20 instances = ["${google_compute_instance.www.*.self_link}"] 21 health_checks = ["${google_compute_http_health_check.default.name}"] 22 } 23 24 resource "google_compute_forwarding_rule" "default" { 25 name = "tf-www-forwarding-rule" 26 target = "${google_compute_target_pool.default.self_link}" 27 port_range = "80" 28 } 29 30 resource "google_compute_instance" "www" { 31 count = 3 32 33 name = "tf-www-${count.index}" 34 machine_type = "f1-micro" 35 zone = "${var.region_zone}" 36 tags = ["www-node"] 37 38 disk { 39 image = "ubuntu-os-cloud/ubuntu-1404-trusty-v20160602" 40 } 41 42 network_interface { 43 network = "default" 44 access_config { 45 # Ephemeral 46 } 47 } 48 49 metadata { 50 ssh-keys = "root:${file("${var.public_key_path}")}" 51 } 52 53 provisioner "file" { 54 source = "${var.install_script_src_path}" 55 destination = "${var.install_script_dest_path}" 56 connection { 57 type = "ssh" 58 user = "root" 59 private_key = "${file("${var.private_key_path}")}" 60 agent = false 61 } 62 } 63 64 provisioner "remote-exec" { 65 connection { 66 type = "ssh" 67 user = "root" 68 private_key = "${file("${var.private_key_path}")}" 69 agent = false 70 } 71 inline = [ 72 "chmod +x ${var.install_script_dest_path}", 73 "sudo ${var.install_script_dest_path} ${count.index}" 74 ] 75 } 76 77 service_account { 78 scopes = ["https://www.googleapis.com/auth/compute.readonly"] 79 } 80 } 81 82 resource "google_compute_firewall" "default" { 83 name = "tf-www-firewall" 84 network = "default" 85 86 allow { 87 protocol = "tcp" 88 ports = ["80"] 89 } 90 91 source_ranges = ["0.0.0.0/0"] 92 target_tags = ["www-node"] 93 }