2017-11-06 07:36:50 +01:00
|
|
|
# Discrete DNS records for each controller's private IPv4 for etcd usage
|
2017-11-05 20:01:50 +01:00
|
|
|
resource "google_dns_record_set" "etcds" {
|
2018-04-12 08:19:35 +02:00
|
|
|
count = "${var.controller_count}"
|
2017-06-27 06:55:39 +02:00
|
|
|
|
2017-11-05 20:01:50 +01:00
|
|
|
# DNS Zone name where record should be created
|
|
|
|
managed_zone = "${var.dns_zone_name}"
|
2017-06-27 06:55:39 +02:00
|
|
|
|
2017-11-05 20:01:50 +01:00
|
|
|
# DNS record
|
|
|
|
name = "${format("%s-etcd%d.%s.", var.cluster_name, count.index, var.dns_zone)}"
|
|
|
|
type = "A"
|
|
|
|
ttl = 300
|
2017-06-27 06:55:39 +02:00
|
|
|
|
2017-11-05 20:01:50 +01:00
|
|
|
# private IPv4 address for etcd
|
|
|
|
rrdatas = ["${element(google_compute_instance.controllers.*.network_interface.0.address, count.index)}"]
|
2017-06-27 06:55:39 +02:00
|
|
|
}
|
|
|
|
|
2017-11-05 20:09:03 +01:00
|
|
|
# Zones in the region
|
2017-11-06 09:51:20 +01:00
|
|
|
data "google_compute_zones" "all" {
|
2017-11-05 20:09:03 +01:00
|
|
|
region = "${var.region}"
|
|
|
|
}
|
|
|
|
|
2018-04-15 09:50:43 +02:00
|
|
|
locals {
|
|
|
|
# TCP proxy load balancers require a fixed number of zonal backends. Spread
|
|
|
|
# controllers over up to 3 zones, since all GCP regions have at least 3.
|
|
|
|
zones = "${slice(data.google_compute_zones.all.names, 0, 3)}"
|
2018-05-02 06:41:22 +02:00
|
|
|
|
2018-04-15 09:50:43 +02:00
|
|
|
controllers_ipv4_public = ["${google_compute_instance.controllers.*.network_interface.0.access_config.0.assigned_nat_ip}"]
|
|
|
|
}
|
|
|
|
|
2017-11-05 20:01:50 +01:00
|
|
|
# Controller instances
|
|
|
|
resource "google_compute_instance" "controllers" {
|
2018-04-12 08:19:35 +02:00
|
|
|
count = "${var.controller_count}"
|
2017-11-05 20:01:50 +01:00
|
|
|
|
|
|
|
name = "${var.cluster_name}-controller-${count.index}"
|
2018-04-15 09:50:43 +02:00
|
|
|
zone = "${element(local.zones, count.index)}"
|
2018-04-12 08:19:35 +02:00
|
|
|
machine_type = "${var.controller_type}"
|
2017-06-27 06:55:39 +02:00
|
|
|
|
|
|
|
metadata {
|
2018-08-22 07:36:42 +02:00
|
|
|
user-data = "${element(data.ct_config.controller-ignitions.*.rendered, count.index)}"
|
2017-06-27 06:55:39 +02:00
|
|
|
}
|
|
|
|
|
2017-11-05 20:01:50 +01:00
|
|
|
boot_disk {
|
|
|
|
auto_delete = true
|
|
|
|
|
|
|
|
initialize_params {
|
|
|
|
image = "${var.os_image}"
|
|
|
|
size = "${var.disk_size}"
|
|
|
|
}
|
2017-06-27 06:55:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
2018-04-12 08:19:35 +02:00
|
|
|
network = "${google_compute_network.network.name}"
|
2017-06-27 06:55:39 +02:00
|
|
|
|
|
|
|
# Ephemeral external IP
|
|
|
|
access_config = {}
|
|
|
|
}
|
|
|
|
|
|
|
|
can_ip_forward = true
|
2018-02-11 00:18:27 +01:00
|
|
|
tags = ["${var.cluster_name}-controller"]
|
2018-10-28 23:11:47 +01:00
|
|
|
|
|
|
|
lifecycle {
|
|
|
|
ignore_changes = [
|
|
|
|
"metadata",
|
|
|
|
]
|
|
|
|
}
|
2017-11-05 20:01:50 +01:00
|
|
|
}
|
|
|
|
|
2018-08-22 07:36:42 +02:00
|
|
|
# Controller Ignition configs
|
|
|
|
data "ct_config" "controller-ignitions" {
|
|
|
|
count = "${var.controller_count}"
|
|
|
|
content = "${element(data.template_file.controller-configs.*.rendered, count.index)}"
|
|
|
|
pretty_print = false
|
|
|
|
snippets = ["${var.controller_clc_snippets}"]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Controller Container Linux configs
|
|
|
|
data "template_file" "controller-configs" {
|
2018-04-12 08:19:35 +02:00
|
|
|
count = "${var.controller_count}"
|
2017-11-05 20:01:50 +01:00
|
|
|
|
|
|
|
template = "${file("${path.module}/cl/controller.yaml.tmpl")}"
|
|
|
|
|
|
|
|
vars = {
|
|
|
|
# Cannot use cyclic dependencies on controllers or their DNS records
|
|
|
|
etcd_name = "etcd${count.index}"
|
|
|
|
etcd_domain = "${var.cluster_name}-etcd${count.index}.${var.dns_zone}"
|
2017-06-27 06:55:39 +02:00
|
|
|
|
2017-11-05 20:01:50 +01:00
|
|
|
# etcd0=https://cluster-etcd0.example.com,etcd1=https://cluster-etcd1.example.com,...
|
2018-08-22 07:36:42 +02:00
|
|
|
etcd_initial_cluster = "${join(",", data.template_file.etcds.*.rendered)}"
|
2017-11-05 20:01:50 +01:00
|
|
|
|
2019-01-05 22:32:03 +01:00
|
|
|
kubeconfig = "${indent(10, module.bootkube.kubeconfig-kubelet)}"
|
|
|
|
ssh_authorized_key = "${var.ssh_authorized_key}"
|
|
|
|
cluster_dns_service_ip = "${cidrhost(var.service_cidr, 10)}"
|
|
|
|
cluster_domain_suffix = "${var.cluster_domain_suffix}"
|
2017-11-05 20:01:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-22 07:36:42 +02:00
|
|
|
data "template_file" "etcds" {
|
|
|
|
count = "${var.controller_count}"
|
|
|
|
template = "etcd$${index}=https://$${cluster_name}-etcd$${index}.$${dns_zone}:2380"
|
2017-11-05 20:01:50 +01:00
|
|
|
|
2018-08-22 07:36:42 +02:00
|
|
|
vars {
|
|
|
|
index = "${count.index}"
|
|
|
|
cluster_name = "${var.cluster_name}"
|
|
|
|
dns_zone = "${var.dns_zone}"
|
2017-06-27 06:55:39 +02:00
|
|
|
}
|
|
|
|
}
|