2018-03-25 22:47:36 +02:00
|
|
|
# Discrete DNS records for each controller's private IPv4 for etcd usage
|
|
|
|
resource "aws_route53_record" "etcds" {
|
|
|
|
count = "${var.controller_count}"
|
|
|
|
|
|
|
|
# DNS Zone where record should be created
|
|
|
|
zone_id = "${var.dns_zone_id}"
|
|
|
|
|
|
|
|
name = "${format("%s-etcd%d.%s.", var.cluster_name, count.index, var.dns_zone)}"
|
|
|
|
type = "A"
|
|
|
|
ttl = 300
|
|
|
|
|
|
|
|
# private IPv4 address for etcd
|
|
|
|
records = ["${element(aws_instance.controllers.*.private_ip, count.index)}"]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Controller instances
|
|
|
|
resource "aws_instance" "controllers" {
|
|
|
|
count = "${var.controller_count}"
|
|
|
|
|
|
|
|
tags = {
|
|
|
|
Name = "${var.cluster_name}-controller-${count.index}"
|
|
|
|
}
|
|
|
|
|
|
|
|
instance_type = "${var.controller_type}"
|
|
|
|
|
|
|
|
ami = "${data.aws_ami.fedora.image_id}"
|
|
|
|
user_data = "${element(data.template_file.controller-cloudinit.*.rendered, count.index)}"
|
|
|
|
|
|
|
|
# storage
|
|
|
|
root_block_device {
|
2018-03-31 22:11:42 +02:00
|
|
|
volume_type = "${var.disk_type}"
|
2018-03-25 22:47:36 +02:00
|
|
|
volume_size = "${var.disk_size}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# network
|
|
|
|
associate_public_ip_address = true
|
|
|
|
subnet_id = "${element(aws_subnet.public.*.id, count.index)}"
|
|
|
|
vpc_security_group_ids = ["${aws_security_group.controller.id}"]
|
|
|
|
|
|
|
|
lifecycle {
|
|
|
|
ignore_changes = ["ami"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Controller Cloud-Init
|
|
|
|
data "template_file" "controller-cloudinit" {
|
|
|
|
count = "${var.controller_count}"
|
|
|
|
|
|
|
|
template = "${file("${path.module}/cloudinit/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}"
|
|
|
|
|
|
|
|
# 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))}"
|
|
|
|
|
|
|
|
kubeconfig = "${indent(6, module.bootkube.kubeconfig)}"
|
|
|
|
ssh_authorized_key = "${var.ssh_authorized_key}"
|
|
|
|
k8s_dns_service_ip = "${cidrhost(var.service_cidr, 10)}"
|
|
|
|
cluster_domain_suffix = "${var.cluster_domain_suffix}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Horrible hack to generate a Terraform list of a desired length without dependencies.
|
|
|
|
# Ideal ${repeat("etcd", 3) -> ["etcd", "etcd", "etcd"]}
|
|
|
|
resource null_resource "repeat" {
|
|
|
|
count = "${var.controller_count}"
|
|
|
|
|
|
|
|
triggers {
|
|
|
|
name = "etcd${count.index}"
|
|
|
|
domain = "${var.cluster_name}-etcd${count.index}.${var.dns_zone}"
|
|
|
|
}
|
|
|
|
}
|