github.com/clly/consul@v1.4.5/terraform/google/consul.tf (about) 1 resource "google_compute_instance" "consul" { 2 count = "${var.servers}" 3 4 name = "consul-${count.index}" 5 zone = "${var.region_zone}" 6 tags = ["${var.tag_name}"] 7 8 machine_type = "${var.machine_type}" 9 10 disk { 11 image = "${lookup(var.machine_image, var.platform)}" 12 } 13 14 network_interface { 15 network = "default" 16 17 access_config { 18 # Ephemeral 19 } 20 } 21 22 service_account { 23 scopes = ["https://www.googleapis.com/auth/compute.readonly"] 24 } 25 26 connection { 27 user = "${lookup(var.user, var.platform)}" 28 private_key = "${file("${var.key_path}")}" 29 } 30 31 provisioner "file" { 32 source = "${path.module}/../shared/scripts/${lookup(var.service_conf, var.platform)}" 33 destination = "/tmp/${lookup(var.service_conf_dest, var.platform)}" 34 } 35 36 provisioner "remote-exec" { 37 inline = [ 38 "echo ${var.servers} > /tmp/consul-server-count", 39 "echo ${google_compute_instance.consul.0.network_interface.0.address} > /tmp/consul-server-addr", 40 ] 41 } 42 43 provisioner "remote-exec" { 44 scripts = [ 45 "${path.module}/../shared/scripts/install.sh", 46 "${path.module}/../shared/scripts/service.sh", 47 "${path.module}/../shared/scripts/ip_tables.sh", 48 ] 49 } 50 } 51 52 resource "google_compute_firewall" "consul_ingress" { 53 name = "consul-internal-access" 54 network = "default" 55 56 allow { 57 protocol = "tcp" 58 59 ports = [ 60 "8300", # Server RPC 61 "8301", # Serf LAN 62 "8302", # Serf WAN 63 "8400", # RPC 64 ] 65 } 66 67 source_tags = ["${var.tag_name}"] 68 target_tags = ["${var.tag_name}"] 69 }