2017-11-04 18:57:12 +01:00
|
|
|
# Regional managed instance group maintains a homogeneous set of workers that
|
|
|
|
# span the zones in the region.
|
|
|
|
resource "google_compute_region_instance_group_manager" "workers" {
|
2017-06-27 06:55:39 +02:00
|
|
|
name = "${var.cluster_name}-worker-group"
|
|
|
|
description = "Compute instance group of ${var.cluster_name} workers"
|
|
|
|
|
2017-11-04 18:57:12 +01:00
|
|
|
# instance name prefix for instances in the group
|
2017-06-27 06:55:39 +02:00
|
|
|
base_instance_name = "${var.cluster_name}-worker"
|
|
|
|
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}"
|
|
|
|
|
|
|
|
# target pool to which instances in the group should be added
|
2017-06-27 06:55:39 +02:00
|
|
|
target_pools = [
|
|
|
|
"${google_compute_target_pool.workers.self_link}",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2017-07-25 04:37:27 +02:00
|
|
|
# Worker Container Linux Config
|
2017-06-27 06:55:39 +02:00
|
|
|
data "template_file" "worker_config" {
|
2017-07-25 04:37:27 +02:00
|
|
|
template = "${file("${path.module}/cl/worker.yaml.tmpl")}"
|
2017-06-27 06:55:39 +02:00
|
|
|
|
|
|
|
vars = {
|
|
|
|
k8s_dns_service_ip = "${cidrhost(var.service_cidr, 10)}"
|
|
|
|
k8s_etcd_service_ip = "${cidrhost(var.service_cidr, 15)}"
|
|
|
|
ssh_authorized_key = "${var.ssh_authorized_key}"
|
|
|
|
kubeconfig_ca_cert = "${var.kubeconfig_ca_cert}"
|
|
|
|
kubeconfig_kubelet_cert = "${var.kubeconfig_kubelet_cert}"
|
|
|
|
kubeconfig_kubelet_key = "${var.kubeconfig_kubelet_key}"
|
|
|
|
kubeconfig_server = "${var.kubeconfig_server}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data "ct_config" "worker_ign" {
|
|
|
|
content = "${data.template_file.worker_config.rendered}"
|
|
|
|
pretty_print = false
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_instance_template" "worker" {
|
|
|
|
name_prefix = "${var.cluster_name}-worker-"
|
2017-07-25 04:37:27 +02:00
|
|
|
description = "Worker Instance template"
|
2017-06-27 06:55:39 +02:00
|
|
|
machine_type = "${var.machine_type}"
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
user-data = "${data.ct_config.worker_ign.rendered}"
|
|
|
|
}
|
|
|
|
|
|
|
|
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}"
|
2017-10-16 10:32:25 +02:00
|
|
|
|
2017-10-12 03:04:39 +02:00
|
|
|
// Set explicit name to match the new default name set by the API.
|
|
|
|
// https://github.com/terraform-providers/terraform-provider-google/issues/574
|
|
|
|
device_name = "persistent-disk-0"
|
2017-06-27 06:55:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "${var.network}"
|
|
|
|
|
|
|
|
# Ephemeral external IP
|
|
|
|
access_config = {}
|
|
|
|
}
|
|
|
|
|
|
|
|
can_ip_forward = true
|
|
|
|
|
|
|
|
tags = ["worker"]
|
|
|
|
|
|
|
|
lifecycle {
|
|
|
|
# To update an Instance Template, Terraform should replace the existing resource
|
|
|
|
create_before_destroy = true
|
|
|
|
}
|
|
|
|
}
|