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)}"
|
|
|
|
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 {
|
2017-11-05 20:01:50 +01:00
|
|
|
user-data = "${element(data.ct_config.controller_ign.*.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"]
|
2017-11-05 20:01:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Controller Container Linux Config
|
|
|
|
data "template_file" "controller_config" {
|
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,...
|
|
|
|
etcd_initial_cluster = "${join(",", formatlist("%s=https://%s:2380", null_resource.repeat.*.triggers.name, null_resource.repeat.*.triggers.domain))}"
|
|
|
|
|
2018-04-12 08:19:35 +02:00
|
|
|
kubeconfig = "${indent(10, module.bootkube.kubeconfig)}"
|
2018-03-26 09:01:47 +02:00
|
|
|
ssh_authorized_key = "${var.ssh_authorized_key}"
|
2018-02-26 21:17:42 +01:00
|
|
|
k8s_dns_service_ip = "${cidrhost(var.service_cidr, 10)}"
|
|
|
|
cluster_domain_suffix = "${var.cluster_domain_suffix}"
|
2017-11-05 20:01:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Horrible hack to generate a Terraform list of a desired length without dependencies.
|
|
|
|
# Ideal ${repeat("etcd", 3) -> ["etcd", "etcd", "etcd"]}
|
|
|
|
resource null_resource "repeat" {
|
2018-04-12 08:19:35 +02:00
|
|
|
count = "${var.controller_count}"
|
2017-11-05 20:01:50 +01:00
|
|
|
|
|
|
|
triggers {
|
|
|
|
name = "etcd${count.index}"
|
|
|
|
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
|
|
|
|
|
|
|
data "ct_config" "controller_ign" {
|
2018-04-12 08:19:35 +02:00
|
|
|
count = "${var.controller_count}"
|
2017-11-05 20:01:50 +01:00
|
|
|
content = "${element(data.template_file.controller_config.*.rendered, count.index)}"
|
|
|
|
pretty_print = false
|
2018-04-12 08:19:35 +02:00
|
|
|
snippets = ["${var.controller_clc_snippets}"]
|
2017-11-05 20:01:50 +01:00
|
|
|
}
|