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-05-28 06:14:25 +02:00
|
|
|
rrdatas = [element(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-03-28 03:45:10 +01:00
|
|
|
name = "${var.cluster_name}-controller-${count.index}"
|
2019-05-28 06:14:25 +02:00
|
|
|
zone = element(local.zones, count.index)
|
|
|
|
machine_type = var.controller_type
|
2017-06-27 06:55:39 +02:00
|
|
|
|
2019-03-12 09:19:54 +01:00
|
|
|
metadata = {
|
2019-05-28 06:14:25 +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 {
|
2019-05-28 06:14:25 +02:00
|
|
|
image = var.os_image
|
|
|
|
size = var.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 {
|
2019-05-28 06:14:25 +02:00
|
|
|
ignore_changes = [metadata]
|
2018-10-28 23:11:47 +01:00
|
|
|
}
|
2017-11-05 20:01:50 +01:00
|
|
|
}
|
|
|
|
|
2018-08-22 07:36:42 +02:00
|
|
|
# Controller Ignition configs
|
|
|
|
data "ct_config" "controller-ignitions" {
|
2019-05-28 06:14:25 +02:00
|
|
|
count = var.controller_count
|
|
|
|
content = element(
|
|
|
|
data.template_file.controller-configs.*.rendered,
|
|
|
|
count.index,
|
|
|
|
)
|
2018-08-22 07:36:42 +02:00
|
|
|
pretty_print = false
|
2019-05-28 06:14:25 +02:00
|
|
|
snippets = var.controller_clc_snippets
|
2018-08-22 07:36:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Controller Container Linux configs
|
|
|
|
data "template_file" "controller-configs" {
|
2019-05-28 06:14:25 +02:00
|
|
|
count = var.controller_count
|
2017-11-05 20:01:50 +01:00
|
|
|
|
2019-05-28 06:14:25 +02:00
|
|
|
template = file("${path.module}/cl/controller.yaml.tmpl")
|
2017-11-05 20:01:50 +01:00
|
|
|
|
|
|
|
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}"
|
|
|
|
# etcd0=https://cluster-etcd0.example.com,etcd1=https://cluster-etcd1.example.com,...
|
2019-05-28 06:14:25 +02:00
|
|
|
etcd_initial_cluster = join(",", data.template_file.etcds.*.rendered)
|
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
|
2017-11-05 20:01:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-22 07:36:42 +02:00
|
|
|
data "template_file" "etcds" {
|
2019-05-28 06:14:25 +02:00
|
|
|
count = var.controller_count
|
2018-08-22 07:36:42 +02:00
|
|
|
template = "etcd$${index}=https://$${cluster_name}-etcd$${index}.$${dns_zone}:2380"
|
2017-11-05 20:01:50 +01:00
|
|
|
|
2019-03-12 09:19:54 +01:00
|
|
|
vars = {
|
2019-05-28 06:14:25 +02:00
|
|
|
index = count.index
|
|
|
|
cluster_name = var.cluster_name
|
|
|
|
dns_zone = var.dns_zone
|
2017-06-27 06:55:39 +02:00
|
|
|
}
|
|
|
|
}
|
2019-05-28 06:14:25 +02:00
|
|
|
|