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-05-28 05:42:48 +02:00
|
|
|
records = [element(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
|
|
|
|
user_data = element(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
|
2017-09-18 06:40:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# network
|
|
|
|
associate_public_ip_address = true
|
2019-05-28 05:42:48 +02:00
|
|
|
subnet_id = element(aws_subnet.public.*.id, count.index)
|
|
|
|
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-05-28 05:42:48 +02:00
|
|
|
count = var.controller_count
|
|
|
|
content = element(
|
|
|
|
data.template_file.controller-configs.*.rendered,
|
|
|
|
count.index,
|
|
|
|
)
|
2018-10-28 01:24:59 +02:00
|
|
|
pretty_print = false
|
2019-05-28 05:42:48 +02:00
|
|
|
snippets = var.controller_clc_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-05-28 05:42:48 +02:00
|
|
|
template = file("${path.module}/cl/controller.yaml.tmpl")
|
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)
|
|
|
|
kubeconfig = indent(10, module.bootkube.kubeconfig-kubelet)
|
|
|
|
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
|
|
|
|