2018-05-07 08:21:53 +02:00
|
|
|
# Regional managed instance group of workers
|
2017-11-04 18:57:12 +01:00
|
|
|
resource "google_compute_region_instance_group_manager" "workers" {
|
2018-03-04 01:21:38 +01:00
|
|
|
name = "${var.name}-worker-group"
|
|
|
|
description = "Compute instance group of ${var.name} workers"
|
2017-06-27 06:55:39 +02:00
|
|
|
|
2017-11-04 18:57:12 +01:00
|
|
|
# instance name prefix for instances in the group
|
2018-03-04 01:21:38 +01:00
|
|
|
base_instance_name = "${var.name}-worker"
|
2017-06-27 06:55:39 +02:00
|
|
|
instance_template = "${google_compute_instance_template.worker.self_link}"
|
2017-11-04 18:57:12 +01:00
|
|
|
region = "${var.region}"
|
2017-06-27 06:55:39 +02:00
|
|
|
|
2017-11-04 18:57:12 +01:00
|
|
|
target_size = "${var.count}"
|
|
|
|
|
2018-05-07 08:21:53 +02:00
|
|
|
named_port {
|
|
|
|
name = "http"
|
|
|
|
port = "80"
|
2017-06-27 06:55:39 +02:00
|
|
|
}
|
|
|
|
|
2018-05-07 08:21:53 +02:00
|
|
|
named_port {
|
|
|
|
name = "https"
|
|
|
|
port = "443"
|
|
|
|
}
|
2017-06-27 06:55:39 +02:00
|
|
|
}
|
|
|
|
|
2018-05-07 08:21:53 +02:00
|
|
|
# Worker instance template
|
2017-06-27 06:55:39 +02:00
|
|
|
resource "google_compute_instance_template" "worker" {
|
2019-03-28 03:45:10 +01:00
|
|
|
name_prefix = "${var.name}-worker-"
|
|
|
|
description = "Worker Instance template"
|
|
|
|
machine_type = "${var.machine_type}"
|
2017-06-27 06:55:39 +02:00
|
|
|
|
2019-03-12 09:19:54 +01:00
|
|
|
metadata = {
|
2018-08-22 07:36:42 +02:00
|
|
|
user-data = "${data.ct_config.worker-ignition.rendered}"
|
2017-06-27 06:55:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
scheduling {
|
|
|
|
automatic_restart = "${var.preemptible ? false : true}"
|
|
|
|
preemptible = "${var.preemptible}"
|
|
|
|
}
|
|
|
|
|
|
|
|
disk {
|
|
|
|
auto_delete = true
|
|
|
|
boot = true
|
|
|
|
source_image = "${var.os_image}"
|
|
|
|
disk_size_gb = "${var.disk_size}"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "${var.network}"
|
|
|
|
|
|
|
|
# Ephemeral external IP
|
|
|
|
access_config = {}
|
|
|
|
}
|
|
|
|
|
|
|
|
can_ip_forward = true
|
2018-02-20 17:36:21 +01:00
|
|
|
tags = ["worker", "${var.cluster_name}-worker", "${var.name}-worker"]
|
2017-06-27 06:55:39 +02:00
|
|
|
|
2018-03-03 02:26:51 +01:00
|
|
|
guest_accelerator {
|
|
|
|
count = "${var.accelerator_count}"
|
2018-02-20 17:36:21 +01:00
|
|
|
type = "${var.accelerator_type}"
|
2018-03-03 02:26:51 +01:00
|
|
|
}
|
|
|
|
|
2017-06-27 06:55:39 +02:00
|
|
|
lifecycle {
|
|
|
|
# To update an Instance Template, Terraform should replace the existing resource
|
|
|
|
create_before_destroy = true
|
|
|
|
}
|
|
|
|
}
|
2018-05-07 08:21:53 +02:00
|
|
|
|
2018-08-22 07:36:42 +02:00
|
|
|
# Worker Ignition config
|
|
|
|
data "ct_config" "worker-ignition" {
|
|
|
|
content = "${data.template_file.worker-config.rendered}"
|
|
|
|
pretty_print = false
|
|
|
|
snippets = ["${var.clc_snippets}"]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Worker Container Linux config
|
|
|
|
data "template_file" "worker-config" {
|
2018-05-07 08:21:53 +02:00
|
|
|
template = "${file("${path.module}/cl/worker.yaml.tmpl")}"
|
|
|
|
|
|
|
|
vars = {
|
2019-01-05 22:32:03 +01:00
|
|
|
kubeconfig = "${indent(10, var.kubeconfig)}"
|
|
|
|
ssh_authorized_key = "${var.ssh_authorized_key}"
|
|
|
|
cluster_dns_service_ip = "${cidrhost(var.service_cidr, 10)}"
|
|
|
|
cluster_domain_suffix = "${var.cluster_domain_suffix}"
|
2018-05-07 08:21:53 +02:00
|
|
|
}
|
|
|
|
}
|