Commit 3cbe8301 authored by John Jarvis's avatar John Jarvis

Automatically create instance groups for all service vms.

parent d68ca547
......@@ -89,8 +89,10 @@ module "web" {
project = "${var.project}"
public_ports = "${var.public_ports["web"]}"
region = "${var.region}"
source = "../../modules/google/generic-sv"
source = "../../modules/google/generic-sv-with-group"
tier = "sv"
health_check = "tcp"
service_port = 443
vpc = "${module.network.self_link}"
}
......@@ -113,7 +115,9 @@ module "api" {
project = "${var.project}"
public_ports = "${var.public_ports["api"]}"
region = "${var.region}"
source = "../../modules/google/generic-sv"
source = "../../modules/google/generic-sv-with-group"
health_check = "tcp"
service_port = 443
tier = "sv"
vpc = "${module.network.self_link}"
}
......@@ -137,7 +141,9 @@ module "git" {
project = "${var.project}"
public_ports = "${var.public_ports["git"]}"
region = "${var.region}"
source = "../../modules/google/generic-sv"
source = "../../modules/google/generic-sv-with-group"
health_check = "tcp"
service_port = 22
tier = "sv"
vpc = "${module.network.self_link}"
}
......@@ -161,7 +167,9 @@ module "registry" {
project = "${var.project}"
public_ports = "${var.public_ports["registry"]}"
region = "${var.region}"
source = "../../modules/google/generic-sv"
source = "../../modules/google/generic-sv-with-group"
health_check = "tcp"
service_port = 22
tier = "sv"
vpc = "${module.network.self_link}"
}
......@@ -206,9 +214,11 @@ module "pg-bouncer" {
public_ports = "${var.public_ports["pgb"]}"
region = "${var.region}"
source = "../../modules/google/generic-sv"
tier = "db"
vpc = "${module.network.self_link}"
source = "../../modules/google/generic-sv-with-group"
health_check = "tcp"
service_port = 22
tier = "db"
vpc = "${module.network.self_link}"
}
module "geo-postgres" {
......@@ -336,7 +346,9 @@ module "mailroom" {
project = "${var.project}"
public_ports = "${var.public_ports["mailroom"]}"
region = "${var.region}"
source = "../../modules/google/generic-sv"
source = "../../modules/google/generic-sv-with-group"
health_check = "tcp"
service_port = 22
tier = "sv"
vpc = "${module.network.self_link}"
}
......@@ -733,7 +745,9 @@ module "deploy" {
project = "${var.project}"
public_ports = "${var.public_ports["deploy"]}"
region = "${var.region}"
source = "../../modules/google/generic-sv"
source = "../../modules/google/generic-sv-with-group"
health_check = "tcp"
service_port = 22
tier = "sv"
vpc = "${module.network.self_link}"
}
......@@ -757,7 +771,9 @@ module "runner" {
project = "${var.project}"
public_ports = "${var.public_ports["runner"]}"
region = "${var.region}"
source = "../../modules/google/generic-sv"
source = "../../modules/google/generic-sv-with-group"
health_check = "tcp"
service_port = 22
tier = "sv"
vpc = "${module.network.self_link}"
}
......
resource "google_compute_instance" "instance_without_attached_disk" {
resource "google_compute_backend_service" "default" {
count = "${length(data.google_compute_zones.available.names)}"
name = "${format("%v-%v-%v", var.environment, var.name, data.google_compute_zones.available.names[count.index])}"
protocol = "${var.backend_protocol}"
port_name = "${var.name}"
backend {
group = "${google_compute_instance_group.default.*.self_link[count.index]}"
}
health_checks = ["${var.health_check == "http" ? google_compute_health_check.http.self_link : google_compute_health_check.tcp.self_link }"]
}
resource "google_compute_health_check" "tcp" {
name = "${format("%v-%v-tcp", var.environment, var.name)}"
tcp_health_check {
port = "${var.service_port}"
}
}
resource "google_compute_health_check" "http" {
name = "${format("%v-%v-http", var.environment, var.name)}"
http_health_check {
port = "${var.service_port}"
request_path = "${var.service_path}"
}
}
# Add one instance group per zone
# and only select the appropriate instances
# for each one
resource "google_compute_instance_group" "default" {
count = "${length(data.google_compute_zones.available.names)}"
name = "${format("%v-%v-%v", var.environment, var.name, data.google_compute_zones.available.names[count.index])}"
description = "Instance group for monitoring VM."
zone = "${data.google_compute_zones.available.names[count.index]}"
named_port {
name = "${var.name}"
port = "${var.service_port}"
}
# This filters the full set of instances to only ones for the appropriate zone.
instances = ["${matchkeys(google_compute_instance.default.*.self_link, google_compute_instance.default.*.zone, list(data.google_compute_zones.available.names[count.index]))}"]
}
resource "google_compute_instance" "default" {
count = "${var.node_count}"
name = "${format("%v-%02d-%v-%v", var.name, count.index + 1, var.tier, var.environment)}"
machine_type = "${var.machine_type}"
......
output "instances_self_link" {
value = "${google_compute_instance.default.*.self_link}"
}
output "instance_groups_self_link" {
value = "${google_compute_instance_group.default.*.self_link}"
}
variable "backend_protocol" {
default = "HTTP"
}
variable "health_check" {
default = "http"
}
variable "service_port" {}
variable "service_path" {
default = "/"
}
variable "bootstrap_version" {
description = "version of the bootstrap script"
default = 1
......
output "instances_without_attached_disk_self_link" {
value = "${google_compute_instance.instance_without_attached_disk.*.self_link}"
}
  • John Jarvis @jarv

    mentioned in commit e511b80a

    By John Jarvis on 2018-04-03T16:58:28 (imported from GitLab project)

    ·

    mentioned in commit e511b80a

    By John Jarvis on 2018-04-03T16:58:28 (imported from GitLab project)

    Toggle commit list
  • John Jarvis @jarv

    mentioned in merge request !301 (closed)

    By John Jarvis on 2018-04-03T16:58:36 (imported from GitLab project)

    ·

    mentioned in merge request !301 (closed)

    By John Jarvis on 2018-04-03T16:58:36 (imported from GitLab project)

    Toggle commit list
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment