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}"
|
|
|
|
}
|
2019-05-28 05:42:48 +02:00
|
|
|
instance_type = var.controller_type
|
2024-08-23 05:02:53 +02:00
|
|
|
ami = local.ami_id
|
2017-09-18 06:40:33 +02:00
|
|
|
|
|
|
|
# storage
|
|
|
|
root_block_device {
|
2024-07-27 07:22:34 +02:00
|
|
|
volume_type = var.controller_disk_type
|
|
|
|
volume_size = var.controller_disk_size
|
|
|
|
iops = var.controller_disk_iops
|
2019-08-08 05:56:55 +02:00
|
|
|
encrypted = true
|
2024-08-23 05:02:53 +02:00
|
|
|
tags = {
|
|
|
|
Name = "${var.cluster_name}-controller-${count.index}"
|
|
|
|
}
|
2017-09-18 06:40:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# network
|
|
|
|
associate_public_ip_address = true
|
2020-04-30 05:41:08 +02:00
|
|
|
subnet_id = element(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
|
|
|
|
2024-08-23 05:02:53 +02:00
|
|
|
# boot
|
|
|
|
user_data = data.ct_config.controllers.*.rendered[count.index]
|
|
|
|
|
|
|
|
# cost
|
2024-07-27 07:22:34 +02:00
|
|
|
credit_specification {
|
|
|
|
cpu_credits = var.controller_cpu_credits
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-08-03 03:15:03 +02:00
|
|
|
# Flatcar Linux controllers
|
|
|
|
data "ct_config" "controllers" {
|
2019-05-28 05:42:48 +02:00
|
|
|
count = var.controller_count
|
2022-08-03 03:12:37 +02:00
|
|
|
content = templatefile("${path.module}/butane/controller.yaml", {
|
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,...
|
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 05:42:48 +02:00
|
|
|
ssh_authorized_key = var.ssh_authorized_key
|
|
|
|
cluster_dns_service_ip = cidrhost(var.service_cidr, 10)
|
2022-08-03 03:15:03 +02:00
|
|
|
})
|
|
|
|
strict = true
|
|
|
|
snippets = var.controller_snippets
|
2017-11-06 07:36:50 +01:00
|
|
|
}
|