2018-05-17 07:37:37 +02:00
|
|
|
locals {
|
|
|
|
# coreos-stable -> coreos flavor, stable channel
|
2018-05-17 08:30:48 +02:00
|
|
|
# flatcar-stable -> flatcar flavor, stable channel
|
2019-05-29 04:19:23 +02:00
|
|
|
flavor = element(split("-", var.os_channel), 0)
|
2018-06-22 09:28:36 +02:00
|
|
|
|
2019-05-29 04:19:23 +02:00
|
|
|
channel = element(split("-", var.os_channel), 1)
|
2018-05-17 07:37:37 +02:00
|
|
|
}
|
|
|
|
|
2017-07-25 08:16:34 +02:00
|
|
|
// Container Linux Install profile (from release.core-os.net)
|
|
|
|
resource "matchbox_profile" "container-linux-install" {
|
2019-05-29 04:19:23 +02:00
|
|
|
count = length(var.controller_names) + length(var.worker_names)
|
|
|
|
name = format("%s-container-linux-install-%s", var.cluster_name, element(concat(var.controller_names, var.worker_names), count.index))
|
2018-01-14 21:36:40 +01:00
|
|
|
|
2019-03-10 04:34:15 +01:00
|
|
|
kernel = "${var.download_protocol}://${local.channel}.release.core-os.net/amd64-usr/${var.os_version}/coreos_production_pxe.vmlinuz"
|
2017-07-25 08:16:34 +02:00
|
|
|
|
|
|
|
initrd = [
|
2019-03-10 04:34:15 +01:00
|
|
|
"${var.download_protocol}://${local.channel}.release.core-os.net/amd64-usr/${var.os_version}/coreos_production_pxe_image.cpio.gz",
|
2017-07-25 08:16:34 +02:00
|
|
|
]
|
|
|
|
|
2019-05-29 04:19:23 +02:00
|
|
|
args = flatten([
|
2017-11-17 08:19:51 +01:00
|
|
|
"initrd=coreos_production_pxe_image.cpio.gz",
|
2017-07-25 08:16:34 +02:00
|
|
|
"coreos.config.url=${var.matchbox_http_endpoint}/ignition?uuid=$${uuid}&mac=$${mac:hexhyp}",
|
|
|
|
"coreos.first_boot=yes",
|
|
|
|
"console=tty0",
|
|
|
|
"console=ttyS0",
|
2019-05-29 04:19:23 +02:00
|
|
|
var.kernel_args,
|
|
|
|
])
|
2017-07-25 08:16:34 +02:00
|
|
|
|
2019-05-29 04:19:23 +02:00
|
|
|
container_linux_config = element(data.template_file.container-linux-install-configs.*.rendered, count.index)
|
2017-07-25 08:16:34 +02:00
|
|
|
}
|
|
|
|
|
2018-01-14 21:36:40 +01:00
|
|
|
data "template_file" "container-linux-install-configs" {
|
2019-05-29 04:19:23 +02:00
|
|
|
count = length(var.controller_names) + length(var.worker_names)
|
2018-01-14 21:36:40 +01:00
|
|
|
|
2019-05-29 04:19:23 +02:00
|
|
|
template = file("${path.module}/cl/install.yaml.tmpl")
|
2017-07-25 08:16:34 +02:00
|
|
|
|
2019-03-12 09:19:54 +01:00
|
|
|
vars = {
|
2019-05-29 04:19:23 +02:00
|
|
|
os_flavor = local.flavor
|
|
|
|
os_channel = local.channel
|
|
|
|
os_version = var.os_version
|
|
|
|
ignition_endpoint = format("%s/ignition", var.matchbox_http_endpoint)
|
|
|
|
install_disk = var.install_disk
|
|
|
|
container_linux_oem = var.container_linux_oem
|
|
|
|
ssh_authorized_key = var.ssh_authorized_key
|
2017-07-25 08:16:34 +02:00
|
|
|
# only cached-container-linux profile adds -b baseurl
|
|
|
|
baseurl_flag = ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Container Linux Install profile (from matchbox /assets cache)
|
2018-10-15 11:27:32 +02:00
|
|
|
// Note: Admin must have downloaded os_version into matchbox assets/coreos.
|
2017-07-25 08:16:34 +02:00
|
|
|
resource "matchbox_profile" "cached-container-linux-install" {
|
2019-05-29 04:19:23 +02:00
|
|
|
count = length(var.controller_names) + length(var.worker_names)
|
|
|
|
name = format("%s-cached-container-linux-install-%s", var.cluster_name, element(concat(var.controller_names, var.worker_names), count.index))
|
2018-01-14 21:36:40 +01:00
|
|
|
|
2018-05-17 07:37:37 +02:00
|
|
|
kernel = "/assets/coreos/${var.os_version}/coreos_production_pxe.vmlinuz"
|
2017-07-25 08:16:34 +02:00
|
|
|
|
|
|
|
initrd = [
|
2018-05-17 07:37:37 +02:00
|
|
|
"/assets/coreos/${var.os_version}/coreos_production_pxe_image.cpio.gz",
|
2017-07-25 08:16:34 +02:00
|
|
|
]
|
|
|
|
|
2019-05-29 04:19:23 +02:00
|
|
|
args = flatten([
|
2017-11-17 08:19:51 +01:00
|
|
|
"initrd=coreos_production_pxe_image.cpio.gz",
|
2017-07-25 08:16:34 +02:00
|
|
|
"coreos.config.url=${var.matchbox_http_endpoint}/ignition?uuid=$${uuid}&mac=$${mac:hexhyp}",
|
|
|
|
"coreos.first_boot=yes",
|
|
|
|
"console=tty0",
|
|
|
|
"console=ttyS0",
|
2019-05-29 04:19:23 +02:00
|
|
|
var.kernel_args,
|
|
|
|
])
|
2017-07-25 08:16:34 +02:00
|
|
|
|
2019-05-29 04:19:23 +02:00
|
|
|
container_linux_config = element(data.template_file.cached-container-linux-install-configs.*.rendered, count.index)
|
2017-07-25 08:16:34 +02:00
|
|
|
}
|
|
|
|
|
2018-01-14 21:36:40 +01:00
|
|
|
data "template_file" "cached-container-linux-install-configs" {
|
2019-05-29 04:19:23 +02:00
|
|
|
count = length(var.controller_names) + length(var.worker_names)
|
2018-01-14 21:36:40 +01:00
|
|
|
|
2019-05-29 04:19:23 +02:00
|
|
|
template = file("${path.module}/cl/install.yaml.tmpl")
|
2017-07-25 08:16:34 +02:00
|
|
|
|
2019-03-12 09:19:54 +01:00
|
|
|
vars = {
|
2019-05-29 04:19:23 +02:00
|
|
|
os_flavor = local.flavor
|
|
|
|
os_channel = local.channel
|
|
|
|
os_version = var.os_version
|
|
|
|
ignition_endpoint = format("%s/ignition", var.matchbox_http_endpoint)
|
|
|
|
install_disk = var.install_disk
|
|
|
|
container_linux_oem = var.container_linux_oem
|
|
|
|
ssh_authorized_key = var.ssh_authorized_key
|
2017-07-25 08:16:34 +02:00
|
|
|
# profile uses -b baseurl to install from matchbox cache
|
2018-10-15 11:27:32 +02:00
|
|
|
baseurl_flag = "-b ${var.matchbox_http_endpoint}/assets/${local.flavor}"
|
2017-07-25 08:16:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-17 08:30:48 +02:00
|
|
|
// Flatcar Linux install profile (from release.flatcar-linux.net)
|
|
|
|
resource "matchbox_profile" "flatcar-install" {
|
2019-05-29 04:19:23 +02:00
|
|
|
count = length(var.controller_names) + length(var.worker_names)
|
|
|
|
name = format("%s-flatcar-install-%s", var.cluster_name, element(concat(var.controller_names, var.worker_names), count.index))
|
2018-05-17 08:30:48 +02:00
|
|
|
|
2019-03-10 04:34:15 +01:00
|
|
|
kernel = "${var.download_protocol}://${local.channel}.release.flatcar-linux.net/amd64-usr/${var.os_version}/flatcar_production_pxe.vmlinuz"
|
2018-05-17 08:30:48 +02:00
|
|
|
|
|
|
|
initrd = [
|
2019-03-10 04:34:15 +01:00
|
|
|
"${var.download_protocol}://${local.channel}.release.flatcar-linux.net/amd64-usr/${var.os_version}/flatcar_production_pxe_image.cpio.gz",
|
2018-05-17 08:30:48 +02:00
|
|
|
]
|
|
|
|
|
2019-05-29 04:19:23 +02:00
|
|
|
args = flatten([
|
2018-05-17 08:30:48 +02:00
|
|
|
"initrd=flatcar_production_pxe_image.cpio.gz",
|
|
|
|
"flatcar.config.url=${var.matchbox_http_endpoint}/ignition?uuid=$${uuid}&mac=$${mac:hexhyp}",
|
|
|
|
"flatcar.first_boot=yes",
|
|
|
|
"console=tty0",
|
|
|
|
"console=ttyS0",
|
2019-05-29 04:19:23 +02:00
|
|
|
var.kernel_args,
|
|
|
|
])
|
2018-05-17 08:30:48 +02:00
|
|
|
|
2019-05-29 04:19:23 +02:00
|
|
|
container_linux_config = element(data.template_file.container-linux-install-configs.*.rendered, count.index)
|
2018-05-17 08:30:48 +02:00
|
|
|
}
|
|
|
|
|
2018-10-15 11:27:32 +02:00
|
|
|
// Flatcar Linux Install profile (from matchbox /assets cache)
|
|
|
|
// Note: Admin must have downloaded os_version into matchbox assets/flatcar.
|
|
|
|
resource "matchbox_profile" "cached-flatcar-linux-install" {
|
2019-05-29 04:19:23 +02:00
|
|
|
count = length(var.controller_names) + length(var.worker_names)
|
|
|
|
name = format("%s-cached-flatcar-linux-install-%s", var.cluster_name, element(concat(var.controller_names, var.worker_names), count.index))
|
2018-10-15 11:27:32 +02:00
|
|
|
|
|
|
|
kernel = "/assets/flatcar/${var.os_version}/flatcar_production_pxe.vmlinuz"
|
|
|
|
|
|
|
|
initrd = [
|
|
|
|
"/assets/flatcar/${var.os_version}/flatcar_production_pxe_image.cpio.gz",
|
|
|
|
]
|
|
|
|
|
2019-05-29 04:19:23 +02:00
|
|
|
args = flatten([
|
2018-10-15 11:27:32 +02:00
|
|
|
"initrd=flatcar_production_pxe_image.cpio.gz",
|
|
|
|
"flatcar.config.url=${var.matchbox_http_endpoint}/ignition?uuid=$${uuid}&mac=$${mac:hexhyp}",
|
|
|
|
"flatcar.first_boot=yes",
|
|
|
|
"console=tty0",
|
|
|
|
"console=ttyS0",
|
2019-05-29 04:19:23 +02:00
|
|
|
var.kernel_args,
|
|
|
|
])
|
2018-10-15 11:27:32 +02:00
|
|
|
|
2019-05-29 04:19:23 +02:00
|
|
|
container_linux_config = element(data.template_file.cached-container-linux-install-configs.*.rendered, count.index)
|
2018-10-15 11:27:32 +02:00
|
|
|
}
|
|
|
|
|
2017-09-23 20:49:12 +02:00
|
|
|
// Kubernetes Controller profiles
|
|
|
|
resource "matchbox_profile" "controllers" {
|
2019-05-29 04:19:23 +02:00
|
|
|
count = length(var.controller_names)
|
|
|
|
name = format("%s-controller-%s", var.cluster_name, element(var.controller_names, count.index))
|
|
|
|
raw_ignition = element(data.ct_config.controller-ignitions.*.rendered, count.index)
|
2017-07-25 08:16:34 +02:00
|
|
|
}
|
|
|
|
|
2018-07-26 07:44:07 +02:00
|
|
|
data "ct_config" "controller-ignitions" {
|
2019-05-29 04:19:23 +02:00
|
|
|
count = length(var.controller_names)
|
|
|
|
content = element(data.template_file.controller-configs.*.rendered, count.index)
|
2018-07-26 07:44:07 +02:00
|
|
|
pretty_print = false
|
2019-05-29 04:19:23 +02:00
|
|
|
snippets = local.clc_map[element(var.controller_names, count.index)]
|
2018-07-26 07:44:07 +02:00
|
|
|
}
|
|
|
|
|
2017-09-23 20:49:12 +02:00
|
|
|
data "template_file" "controller-configs" {
|
2019-05-29 04:19:23 +02:00
|
|
|
count = length(var.controller_names)
|
2017-09-23 20:49:12 +02:00
|
|
|
|
2019-05-29 04:19:23 +02:00
|
|
|
template = file("${path.module}/cl/controller.yaml.tmpl")
|
2017-09-23 20:49:12 +02:00
|
|
|
|
2019-03-12 09:19:54 +01:00
|
|
|
vars = {
|
2019-05-29 04:19:23 +02:00
|
|
|
domain_name = element(var.controller_domains, count.index)
|
|
|
|
etcd_name = element(var.controller_names, count.index)
|
|
|
|
etcd_initial_cluster = join(",", formatlist("%s=https://%s:2380", var.controller_names, var.controller_domains))
|
2019-06-12 08:24:01 +02:00
|
|
|
cgroup_driver = var.os_channel == "flatcar-edge" ? "systemd" : "cgroupfs"
|
2019-09-15 01:24:32 +02:00
|
|
|
cluster_dns_service_ip = module.bootstrap.cluster_dns_service_ip
|
2019-05-29 04:19:23 +02:00
|
|
|
cluster_domain_suffix = var.cluster_domain_suffix
|
|
|
|
ssh_authorized_key = var.ssh_authorized_key
|
2017-09-23 20:49:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Kubernetes Worker profiles
|
|
|
|
resource "matchbox_profile" "workers" {
|
2019-05-29 04:19:23 +02:00
|
|
|
count = length(var.worker_names)
|
|
|
|
name = format("%s-worker-%s", var.cluster_name, element(var.worker_names, count.index))
|
|
|
|
raw_ignition = element(data.ct_config.worker-ignitions.*.rendered, count.index)
|
2018-07-26 07:44:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
data "ct_config" "worker-ignitions" {
|
2019-05-29 04:19:23 +02:00
|
|
|
count = length(var.worker_names)
|
|
|
|
content = element(data.template_file.worker-configs.*.rendered, count.index)
|
2018-07-26 07:44:07 +02:00
|
|
|
pretty_print = false
|
2019-05-29 04:19:23 +02:00
|
|
|
snippets = local.clc_map[element(var.worker_names, count.index)]
|
2017-09-23 20:49:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
data "template_file" "worker-configs" {
|
2019-05-29 04:19:23 +02:00
|
|
|
count = length(var.worker_names)
|
2017-09-23 20:49:12 +02:00
|
|
|
|
2019-05-29 04:19:23 +02:00
|
|
|
template = file("${path.module}/cl/worker.yaml.tmpl")
|
2017-09-23 20:49:12 +02:00
|
|
|
|
2019-03-12 09:19:54 +01:00
|
|
|
vars = {
|
2019-05-29 04:19:23 +02:00
|
|
|
domain_name = element(var.worker_domains, count.index)
|
2019-06-12 08:24:01 +02:00
|
|
|
cgroup_driver = var.os_channel == "flatcar-edge" ? "systemd" : "cgroupfs"
|
2019-09-15 01:24:32 +02:00
|
|
|
cluster_dns_service_ip = module.bootstrap.cluster_dns_service_ip
|
2019-05-29 04:19:23 +02:00
|
|
|
cluster_domain_suffix = var.cluster_domain_suffix
|
|
|
|
ssh_authorized_key = var.ssh_authorized_key
|
2017-09-23 20:49:12 +02:00
|
|
|
}
|
2017-07-25 08:16:34 +02:00
|
|
|
}
|
2018-07-26 07:44:07 +02:00
|
|
|
|
|
|
|
locals {
|
|
|
|
# Hack to workaround https://github.com/hashicorp/terraform/issues/17251
|
2019-05-29 04:19:23 +02:00
|
|
|
# Still an issue in Terraform v0.12 https://github.com/hashicorp/terraform/issues/20572
|
2018-07-27 08:31:08 +02:00
|
|
|
# Default Container Linux config snippets map every node names to list("\n") so
|
|
|
|
# all lookups succeed
|
2019-05-29 04:19:23 +02:00
|
|
|
clc_defaults = zipmap(
|
|
|
|
concat(var.controller_names, var.worker_names),
|
|
|
|
chunklist(data.template_file.clc-default-snippets.*.rendered, 1),
|
|
|
|
)
|
2018-08-22 06:59:55 +02:00
|
|
|
|
2018-07-26 07:44:07 +02:00
|
|
|
# Union of the default and user specific snippets, later overrides prior.
|
2019-05-29 04:19:23 +02:00
|
|
|
clc_map = merge(local.clc_defaults, var.clc_snippets)
|
2018-07-26 07:44:07 +02:00
|
|
|
}
|
|
|
|
|
2018-07-27 08:31:08 +02:00
|
|
|
// Horrible hack to generate a Terraform list of node count length
|
|
|
|
data "template_file" "clc-default-snippets" {
|
2019-05-29 04:19:23 +02:00
|
|
|
count = length(var.controller_names) + length(var.worker_names)
|
2018-07-26 07:44:07 +02:00
|
|
|
template = "\n"
|
|
|
|
}
|
2019-05-29 04:19:23 +02:00
|
|
|
|