github.com/emc-cmd/terraform@v0.7.8-0.20161101145618-f16309630e7c/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  
    45      access_config {
    46        # Ephemeral
    47      }
    48    }
    49  
    50    metadata {
    51      ssh-keys = "root:${file("${var.public_key_path}")}"
    52    }
    53  
    54    provisioner "file" {
    55      source      = "${var.install_script_src_path}"
    56      destination = "${var.install_script_dest_path}"
    57  
    58      connection {
    59        type        = "ssh"
    60        user        = "root"
    61        private_key = "${file("${var.private_key_path}")}"
    62        agent       = false
    63      }
    64    }
    65  
    66    provisioner "remote-exec" {
    67      connection {
    68        type        = "ssh"
    69        user        = "root"
    70        private_key = "${file("${var.private_key_path}")}"
    71        agent       = false
    72      }
    73  
    74      inline = [
    75        "chmod +x ${var.install_script_dest_path}",
    76        "sudo ${var.install_script_dest_path} ${count.index}",
    77      ]
    78    }
    79  
    80    service_account {
    81      scopes = ["https://www.googleapis.com/auth/compute.readonly"]
    82    }
    83  }
    84  
    85  resource "google_compute_firewall" "default" {
    86    name    = "tf-www-firewall"
    87    network = "default"
    88  
    89    allow {
    90      protocol = "tcp"
    91      ports    = ["80"]
    92    }
    93  
    94    source_ranges = ["0.0.0.0/0"]
    95    target_tags   = ["www-node"]
    96  }