2017-11-06 07:36:50 +01:00
|
|
|
# Discrete DNS records for each controller's private IPv4 for etcd usage
|
|
|
|
resource "aws_route53_record" "etcds" {
|
2019-05-28 05:42:48 +02:00
|
|
|
count = var.controller_count
|
2017-09-18 06:40:33 +02:00
|
|
|
|
2017-11-06 07:36:50 +01:00
|
|
|
# DNS Zone where record should be created
|
2019-05-28 05:42:48 +02:00
|
|
|
zone_id = var.dns_zone_id
|
2017-09-18 06:40:33 +02:00
|
|
|
|
2019-05-28 05:42:48 +02:00
|
|
|
name = format("%s-etcd%d.%s.", var.cluster_name, count.index, var.dns_zone)
|
2017-11-06 07:36:50 +01:00
|
|
|
type = "A"
|
|
|
|
ttl = 300
|
2017-09-18 06:40:33 +02:00
|
|
|
|
2017-11-06 07:36:50 +01:00
|
|
|
# private IPv4 address for etcd
|
2019-12-28 21:07:10 +01:00
|
|
|
records = [aws_instance.controllers.*.private_ip[count.index]]
|
2017-11-06 07:36:50 +01:00
|
|
|
}
|
2017-09-18 06:40:33 +02:00
|
|
|
|
2017-11-06 07:36:50 +01:00
|
|
|
# Controller instances
|
|
|
|
resource "aws_instance" "controllers" {
|
2019-05-28 05:42:48 +02:00
|
|
|
count = var.controller_count
|
2017-09-18 06:40:33 +02:00
|
|
|
|
2017-11-06 07:36:50 +01:00
|
|
|
tags = {
|
|
|
|
Name = "${var.cluster_name}-controller-${count.index}"
|
|
|
|
}
|
2017-09-18 06:40:33 +02:00
|
|
|
|
2019-05-28 05:42:48 +02:00
|
|
|
instance_type = var.controller_type
|
2017-09-18 06:40:33 +02:00
|
|
|
|
2019-05-28 05:42:48 +02:00
|
|
|
ami = local.ami_id
|
2019-12-28 21:07:10 +01:00
|
|
|
user_data = data.ct_config.controller-ignitions.*.rendered[count.index]
|
2017-09-18 06:40:33 +02:00
|
|
|
|
|
|
|
# storage
|
|
|
|
root_block_device {
|
2019-05-28 05:42:48 +02:00
|
|
|
volume_type = var.disk_type
|
|
|
|
volume_size = var.disk_size
|
|
|
|
iops = var.disk_iops
|
2019-08-08 05:56:55 +02:00
|
|
|
encrypted = true
|
2017-09-18 06:40:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# network
|
|
|
|
associate_public_ip_address = true
|
2019-12-28 21:07:10 +01:00
|
|
|
subnet_id = aws_subnet.public.*.id[count.index]
|
2019-05-28 05:42:48 +02:00
|
|
|
vpc_security_group_ids = [aws_security_group.controller.id]
|
2018-02-16 00:33:02 +01:00
|
|
|
|
|
|
|
lifecycle {
|
2018-10-28 23:11:47 +01:00
|
|
|
ignore_changes = [
|
2019-05-28 05:42:48 +02:00
|
|
|
ami,
|
|
|
|
user_data,
|
2018-10-28 23:11:47 +01:00
|
|
|
]
|
2018-02-16 00:33:02 +01:00
|
|
|
}
|
2017-09-18 06:40:33 +02:00
|
|
|
}
|
|
|
|
|
2018-10-28 01:24:59 +02:00
|
|
|
# Controller Ignition configs
|
|
|
|
data "ct_config" "controller-ignitions" {
|
2019-12-28 21:07:10 +01:00
|
|
|
count = var.controller_count
|
|
|
|
content = data.template_file.controller-configs.*.rendered[count.index]
|
2018-10-28 01:24:59 +02:00
|
|
|
pretty_print = false
|
2020-03-29 20:46:22 +02:00
|
|
|
snippets = var.controller_snippets
|
2018-10-28 01:24:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Controller Container Linux configs
|
|
|
|
data "template_file" "controller-configs" {
|
2019-05-28 05:42:48 +02:00
|
|
|
count = var.controller_count
|
2017-11-06 07:36:50 +01:00
|
|
|
|
2019-12-28 21:07:10 +01:00
|
|
|
template = file("${path.module}/cl/controller.yaml")
|
2017-09-18 06:40:33 +02:00
|
|
|
|
|
|
|
vars = {
|
2017-11-06 07:36: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,...
|
2019-05-28 05:42:48 +02:00
|
|
|
etcd_initial_cluster = join(",", data.template_file.etcds.*.rendered)
|
2019-06-12 08:24:01 +02:00
|
|
|
cgroup_driver = local.flavor == "flatcar" && local.channel == "edge" ? "systemd" : "cgroupfs"
|
2019-09-15 01:24:32 +02:00
|
|
|
kubeconfig = indent(10, module.bootstrap.kubeconfig-kubelet)
|
2019-05-28 05:42:48 +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-09-18 06:40:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-22 01:15:54 +02:00
|
|
|
data "template_file" "etcds" {
|
2019-05-28 05:42:48 +02:00
|
|
|
count = var.controller_count
|
2018-05-22 01:15:54 +02:00
|
|
|
template = "etcd$${index}=https://$${cluster_name}-etcd$${index}.$${dns_zone}:2380"
|
2017-11-06 07:36:50 +01:00
|
|
|
|
2019-03-12 09:19:54 +01:00
|
|
|
vars = {
|
2019-05-28 05:42:48 +02:00
|
|
|
index = count.index
|
|
|
|
cluster_name = var.cluster_name
|
|
|
|
dns_zone = var.dns_zone
|
2017-11-06 07:36:50 +01:00
|
|
|
}
|
|
|
|
}
|
2019-05-28 05:42:48 +02:00
|
|
|
|