2020-02-13 23:18:41 +01:00
|
|
|
locals {
|
2020-04-01 06:42:51 +02:00
|
|
|
official_images = ["coreos-stable", "coreos-beta", "coreos-alpha"]
|
2020-03-25 07:45:31 +01:00
|
|
|
is_official_image = contains(local.official_images, var.os_image)
|
2020-02-13 23:18:41 +01:00
|
|
|
}
|
|
|
|
|
2017-08-13 22:02:52 +02:00
|
|
|
# Controller Instance DNS records
|
2017-07-29 20:35:53 +02:00
|
|
|
resource "digitalocean_record" "controllers" {
|
2019-05-28 00:37:36 +02:00
|
|
|
count = var.controller_count
|
2017-07-29 20:35:53 +02:00
|
|
|
|
|
|
|
# DNS zone where record should be created
|
2019-05-28 00:37:36 +02:00
|
|
|
domain = var.dns_zone
|
2017-08-13 03:25:05 +02:00
|
|
|
|
2017-08-13 22:02:52 +02:00
|
|
|
# DNS record (will be prepended to domain)
|
2019-05-28 00:37:36 +02:00
|
|
|
name = var.cluster_name
|
2017-08-13 22:02:52 +02:00
|
|
|
type = "A"
|
|
|
|
ttl = 300
|
|
|
|
|
|
|
|
# IPv4 addresses of controllers
|
2019-12-28 21:07:10 +01:00
|
|
|
value = digitalocean_droplet.controllers.*.ipv4_address[count.index]
|
2017-07-29 20:35:53 +02:00
|
|
|
}
|
|
|
|
|
2017-11-06 07:36:50 +01:00
|
|
|
# Discrete DNS records for each controller's private IPv4 for etcd usage
|
2017-10-04 09:07:48 +02:00
|
|
|
resource "digitalocean_record" "etcds" {
|
2019-05-28 00:37:36 +02:00
|
|
|
count = var.controller_count
|
2017-10-04 09:07:48 +02:00
|
|
|
|
|
|
|
# DNS zone where record should be created
|
2019-05-28 00:37:36 +02:00
|
|
|
domain = var.dns_zone
|
2017-10-04 09:07:48 +02:00
|
|
|
|
|
|
|
# DNS record (will be prepended to domain)
|
|
|
|
name = "${var.cluster_name}-etcd${count.index}"
|
|
|
|
type = "A"
|
|
|
|
ttl = 300
|
|
|
|
|
2017-11-05 20:01:50 +01:00
|
|
|
# private IPv4 address for etcd
|
2019-12-28 21:07:10 +01:00
|
|
|
value = digitalocean_droplet.controllers.*.ipv4_address_private[count.index]
|
2017-10-04 09:07:48 +02:00
|
|
|
}
|
|
|
|
|
2017-07-29 20:35:53 +02:00
|
|
|
# Controller droplet instances
|
|
|
|
resource "digitalocean_droplet" "controllers" {
|
2019-05-28 00:37:36 +02:00
|
|
|
count = var.controller_count
|
2017-07-29 20:35:53 +02:00
|
|
|
|
2017-08-13 03:25:05 +02:00
|
|
|
name = "${var.cluster_name}-controller-${count.index}"
|
2019-05-28 00:37:36 +02:00
|
|
|
region = var.region
|
2017-07-29 20:35:53 +02:00
|
|
|
|
2020-03-25 07:45:31 +01:00
|
|
|
image = var.os_image
|
2019-05-28 00:37:36 +02:00
|
|
|
size = var.controller_type
|
2017-08-13 03:25:05 +02:00
|
|
|
|
2017-07-29 20:35:53 +02:00
|
|
|
# network
|
|
|
|
private_networking = true
|
2020-06-29 08:12:54 +02:00
|
|
|
vpc_uuid = digitalocean_vpc.network.id
|
|
|
|
# TODO: Only official DigitalOcean images support IPv6
|
|
|
|
ipv6 = false
|
2017-08-13 03:25:05 +02:00
|
|
|
|
2019-12-28 21:07:10 +01:00
|
|
|
user_data = data.ct_config.controller-ignitions.*.rendered[count.index]
|
2019-05-28 00:37:36 +02:00
|
|
|
ssh_keys = var.ssh_fingerprints
|
2017-07-29 20:35:53 +02:00
|
|
|
|
|
|
|
tags = [
|
2019-05-28 00:37:36 +02:00
|
|
|
digitalocean_tag.controllers.id,
|
2017-07-29 20:35:53 +02:00
|
|
|
]
|
2018-10-28 23:11:47 +01:00
|
|
|
|
|
|
|
lifecycle {
|
2019-05-28 00:37:36 +02:00
|
|
|
ignore_changes = [user_data]
|
2018-10-28 23:11:47 +01:00
|
|
|
}
|
2017-07-29 20:35:53 +02:00
|
|
|
}
|
|
|
|
|
2017-08-13 02:03:01 +02:00
|
|
|
# Tag to label controllers
|
2017-07-29 20:35:53 +02:00
|
|
|
resource "digitalocean_tag" "controllers" {
|
|
|
|
name = "${var.cluster_name}-controller"
|
|
|
|
}
|
|
|
|
|
2018-10-28 01:24:59 +02:00
|
|
|
# Controller Ignition configs
|
|
|
|
data "ct_config" "controller-ignitions" {
|
2020-06-10 07:38:32 +02:00
|
|
|
count = var.controller_count
|
|
|
|
content = data.template_file.controller-configs.*.rendered[count.index]
|
|
|
|
strict = true
|
|
|
|
snippets = var.controller_snippets
|
2018-10-28 01:24:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Controller Container Linux configs
|
|
|
|
data "template_file" "controller-configs" {
|
2019-05-28 00:37:36 +02:00
|
|
|
count = var.controller_count
|
2017-10-04 09:07:48 +02:00
|
|
|
|
2019-12-28 21:07:10 +01:00
|
|
|
template = file("${path.module}/cl/controller.yaml")
|
2017-07-29 20:35:53 +02:00
|
|
|
|
|
|
|
vars = {
|
2017-10-04 09:07:48 +02:00
|
|
|
# Cannot use cyclic dependencies on controllers or their DNS records
|
2017-10-16 10:32:25 +02:00
|
|
|
etcd_name = "etcd${count.index}"
|
|
|
|
etcd_domain = "${var.cluster_name}-etcd${count.index}.${var.dns_zone}"
|
2017-10-04 09:07:48 +02:00
|
|
|
# etcd0=https://cluster-etcd0.example.com,etcd1=https://cluster-etcd1.example.com,...
|
2019-05-28 00:37:36 +02:00
|
|
|
etcd_initial_cluster = join(",", data.template_file.etcds.*.rendered)
|
|
|
|
cluster_dns_service_ip = cidrhost(var.service_cidr, 10)
|
|
|
|
cluster_domain_suffix = var.cluster_domain_suffix
|
2017-10-04 09:07:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-22 01:15:54 +02:00
|
|
|
data "template_file" "etcds" {
|
2019-05-28 00:37:36 +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-10-04 09:07:48 +02:00
|
|
|
|
2019-03-12 09:19:54 +01:00
|
|
|
vars = {
|
2019-05-28 00:37:36 +02:00
|
|
|
index = count.index
|
|
|
|
cluster_name = var.cluster_name
|
|
|
|
dns_zone = var.dns_zone
|
2017-07-29 20:35:53 +02:00
|
|
|
}
|
|
|
|
}
|
2019-05-28 00:37:36 +02:00
|
|
|
|