2016-03-15 18:49:44 +00:00
|
|
|
resource "google_compute_instance" "consul" {
|
2018-10-24 15:02:38 +00:00
|
|
|
count = "${var.servers}"
|
2016-03-15 18:49:44 +00:00
|
|
|
|
2018-10-24 15:02:38 +00:00
|
|
|
name = "consul-${count.index}"
|
|
|
|
zone = "${var.region_zone}"
|
|
|
|
tags = ["${var.tag_name}"]
|
2016-03-15 18:49:44 +00:00
|
|
|
|
2018-10-24 15:02:38 +00:00
|
|
|
machine_type = "${var.machine_type}"
|
2016-03-15 18:49:44 +00:00
|
|
|
|
2018-10-24 15:02:38 +00:00
|
|
|
disk {
|
|
|
|
image = "${lookup(var.machine_image, var.platform)}"
|
|
|
|
}
|
2016-03-15 18:49:44 +00:00
|
|
|
|
2018-10-24 15:02:38 +00:00
|
|
|
network_interface {
|
|
|
|
network = "default"
|
2016-03-15 18:49:44 +00:00
|
|
|
|
2018-10-24 15:02:38 +00:00
|
|
|
access_config {
|
|
|
|
# Ephemeral
|
2016-03-15 18:49:44 +00:00
|
|
|
}
|
2018-10-24 15:02:38 +00:00
|
|
|
}
|
2016-03-15 18:49:44 +00:00
|
|
|
|
2018-10-24 15:02:38 +00:00
|
|
|
service_account {
|
|
|
|
scopes = ["https://www.googleapis.com/auth/compute.readonly"]
|
|
|
|
}
|
2016-03-15 18:49:44 +00:00
|
|
|
|
2018-10-24 15:02:38 +00:00
|
|
|
connection {
|
|
|
|
user = "${lookup(var.user, var.platform)}"
|
|
|
|
private_key = "${file("${var.key_path}")}"
|
|
|
|
}
|
2016-03-15 18:49:44 +00:00
|
|
|
|
2018-10-24 15:02:38 +00:00
|
|
|
provisioner "file" {
|
|
|
|
source = "${path.module}/../shared/scripts/${lookup(var.service_conf, var.platform)}"
|
|
|
|
destination = "/tmp/${lookup(var.service_conf_dest, var.platform)}"
|
|
|
|
}
|
2016-03-15 18:49:44 +00:00
|
|
|
|
2018-10-24 15:02:38 +00:00
|
|
|
provisioner "remote-exec" {
|
|
|
|
inline = [
|
|
|
|
"echo ${var.servers} > /tmp/consul-server-count",
|
|
|
|
"echo ${google_compute_instance.consul.0.network_interface.0.address} > /tmp/consul-server-addr",
|
|
|
|
]
|
|
|
|
}
|
2016-03-15 18:49:44 +00:00
|
|
|
|
2018-10-24 15:02:38 +00:00
|
|
|
provisioner "remote-exec" {
|
|
|
|
scripts = [
|
|
|
|
"${path.module}/../shared/scripts/install.sh",
|
|
|
|
"${path.module}/../shared/scripts/service.sh",
|
|
|
|
"${path.module}/../shared/scripts/ip_tables.sh",
|
|
|
|
]
|
|
|
|
}
|
2016-03-15 18:49:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_firewall" "consul_ingress" {
|
2018-10-24 15:02:38 +00:00
|
|
|
name = "consul-internal-access"
|
|
|
|
network = "default"
|
2016-03-15 18:49:44 +00:00
|
|
|
|
2018-10-24 15:02:38 +00:00
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
|
|
|
|
ports = [
|
|
|
|
"8300", # Server RPC
|
|
|
|
"8301", # Serf LAN
|
|
|
|
"8302", # Serf WAN
|
|
|
|
"8400", # RPC
|
|
|
|
]
|
|
|
|
}
|
2016-03-15 18:49:44 +00:00
|
|
|
|
2018-10-24 15:02:38 +00:00
|
|
|
source_tags = ["${var.tag_name}"]
|
|
|
|
target_tags = ["${var.tag_name}"]
|
2016-03-15 18:49:44 +00:00
|
|
|
}
|