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" {
|
2019-05-28 06:14:25 +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
|
2019-05-28 06:14:25 +02:00
|
|
|
managed_zone = var.dns_zone_name
|
2017-06-27 06:55:39 +02:00
|
|
|
|
2017-11-05 20:01:50 +01:00
|
|
|
# DNS record
|
2019-05-28 06:14:25 +02:00
|
|
|
name = format("%s-etcd%d.%s.", var.cluster_name, count.index, var.dns_zone)
|
2017-11-05 20:01:50 +01:00
|
|
|
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
|
2019-12-28 21:07:10 +01:00
|
|
|
rrdatas = [google_compute_instance.controllers.*.network_interface.0.network_ip[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" {
|
2019-05-28 06:14:25 +02:00
|
|
|
region = var.region
|
2017-11-05 20:09:03 +01:00
|
|
|
}
|
|
|
|
|
2018-04-15 09:50:43 +02:00
|
|
|
locals {
|
2019-07-06 04:21:05 +02:00
|
|
|
zones = data.google_compute_zones.all.names
|
2018-05-02 06:41:22 +02:00
|
|
|
|
2019-05-28 06:14:25 +02:00
|
|
|
controllers_ipv4_public = google_compute_instance.controllers.*.network_interface.0.access_config.0.nat_ip
|
2018-04-15 09:50:43 +02:00
|
|
|
}
|
|
|
|
|
2017-11-05 20:01:50 +01:00
|
|
|
# Controller instances
|
|
|
|
resource "google_compute_instance" "controllers" {
|
2019-05-28 06:14:25 +02:00
|
|
|
count = var.controller_count
|
2017-11-05 20:01:50 +01:00
|
|
|
|
2019-12-28 21:07:10 +01:00
|
|
|
name = "${var.cluster_name}-controller-${count.index}"
|
|
|
|
# use a zone in the region and wrap around (e.g. controllers > zones)
|
2024-05-13 06:03:40 +02:00
|
|
|
zone = element(local.zones, count.index)
|
|
|
|
machine_type = var.controller_type
|
2024-03-22 19:23:00 +01:00
|
|
|
allow_stopping_for_update = true
|
2017-06-27 06:55:39 +02:00
|
|
|
|
2019-03-12 09:19:54 +01:00
|
|
|
metadata = {
|
2022-08-03 03:15:03 +02:00
|
|
|
user-data = data.ct_config.controllers.*.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 {
|
2022-01-29 05:59:15 +01:00
|
|
|
image = data.google_compute_image.flatcar-linux.self_link
|
2024-08-02 19:08:32 +02:00
|
|
|
size = var.controller_disk_size
|
2017-11-05 20:01:50 +01:00
|
|
|
}
|
2017-06-27 06:55:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
2019-05-28 06:14:25 +02:00
|
|
|
network = google_compute_network.network.name
|
2017-06-27 06:55:39 +02:00
|
|
|
|
|
|
|
# Ephemeral external IP
|
2019-05-28 06:14:25 +02:00
|
|
|
access_config {
|
|
|
|
}
|
2017-06-27 06:55:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2022-04-21 03:53:00 +02:00
|
|
|
ignore_changes = [
|
|
|
|
metadata,
|
|
|
|
boot_disk[0].initialize_params
|
|
|
|
]
|
2018-10-28 23:11:47 +01:00
|
|
|
}
|
2017-11-05 20:01:50 +01:00
|
|
|
}
|
|
|
|
|
2022-08-03 03:15:03 +02:00
|
|
|
# Flatcar Linux controllers
|
|
|
|
data "ct_config" "controllers" {
|
2019-05-28 06:14:25 +02:00
|
|
|
count = var.controller_count
|
2022-08-03 03:12:37 +02:00
|
|
|
content = templatefile("${path.module}/butane/controller.yaml", {
|
2017-11-05 20:01:50 +01:00
|
|
|
# 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}"
|
|
|
|
# etcd0=https://cluster-etcd0.example.com,etcd1=https://cluster-etcd1.example.com,...
|
2022-08-03 03:15:03 +02:00
|
|
|
etcd_initial_cluster = join(",", [
|
|
|
|
for i in range(var.controller_count) : "etcd${i}=https://${var.cluster_name}-etcd${i}.${var.dns_zone}:2380"
|
|
|
|
])
|
2019-09-15 01:24:32 +02:00
|
|
|
kubeconfig = indent(10, module.bootstrap.kubeconfig-kubelet)
|
2019-05-28 06:14:25 +02:00
|
|
|
ssh_authorized_key = var.ssh_authorized_key
|
|
|
|
cluster_dns_service_ip = cidrhost(var.service_cidr, 10)
|
|
|
|
cluster_domain_suffix = var.cluster_domain_suffix
|
2022-08-03 03:15:03 +02:00
|
|
|
})
|
|
|
|
strict = true
|
|
|
|
snippets = var.controller_snippets
|
2017-06-27 06:55:39 +02:00
|
|
|
}
|