mirror of
https://github.com/puppetmaster/typhoon.git
synced 2025-07-16 10:41:34 +02:00
Support Container Linux Config snippets on bare-metal
This commit is contained in:
@ -118,9 +118,18 @@ resource "matchbox_profile" "flatcar-install" {
|
||||
resource "matchbox_profile" "controllers" {
|
||||
count = "${length(var.controller_names)}"
|
||||
name = "${format("%s-controller-%s", var.cluster_name, element(var.controller_names, count.index))}"
|
||||
container_linux_config = "${element(data.template_file.controller-configs.*.rendered, count.index)}"
|
||||
raw_ignition = "${element(data.ct_config.controller-ignitions.*.rendered, count.index)}"
|
||||
}
|
||||
|
||||
data "ct_config" "controller-ignitions" {
|
||||
count = "${length(var.controller_names)}"
|
||||
content = "${element(data.template_file.controller-configs.*.rendered, count.index)}"
|
||||
pretty_print = false
|
||||
# Must use direct lookup. Cannot use lookup(map, key) since it only works for flat maps
|
||||
snippets = ["${local.controller_clc_map[element(var.controller_names, count.index)]}"]
|
||||
}
|
||||
|
||||
|
||||
data "template_file" "controller-configs" {
|
||||
count = "${length(var.controller_names)}"
|
||||
|
||||
@ -143,7 +152,16 @@ data "template_file" "controller-configs" {
|
||||
resource "matchbox_profile" "workers" {
|
||||
count = "${length(var.worker_names)}"
|
||||
name = "${format("%s-worker-%s", var.cluster_name, element(var.worker_names, count.index))}"
|
||||
container_linux_config = "${element(data.template_file.worker-configs.*.rendered, count.index)}"
|
||||
raw_ignition = "${element(data.ct_config.worker-ignitions.*.rendered, count.index)}"
|
||||
}
|
||||
|
||||
|
||||
data "ct_config" "worker-ignitions" {
|
||||
count = "${length(var.worker_names)}"
|
||||
content = "${element(data.template_file.worker-configs.*.rendered, count.index)}"
|
||||
pretty_print = false
|
||||
# Must use direct lookup. Cannot use lookup(map, key) since it only works for flat maps
|
||||
snippets = ["${local.worker_clc_map[element(var.worker_names, count.index)]}"]
|
||||
}
|
||||
|
||||
data "template_file" "worker-configs" {
|
||||
@ -161,3 +179,26 @@ data "template_file" "worker-configs" {
|
||||
networkd_content = "${length(var.worker_networkds) == 0 ? "" : element(concat(var.worker_networkds, list("")), count.index)}"
|
||||
}
|
||||
}
|
||||
|
||||
locals {
|
||||
# Hack to workaround https://github.com/hashicorp/terraform/issues/17251
|
||||
# Default CLC snippets map every worker to list("\n") so all lookups succeed
|
||||
controller_clc_default = "${zipmap(var.controller_names, chunklist(data.template_file.controller-clc-snippets.*.rendered, 1))}"
|
||||
worker_clc_default = "${zipmap(var.worker_names, chunklist(data.template_file.worker-clc-snippets.*.rendered, 1))}"
|
||||
# Union of the default and user specific snippets, later overrides prior.
|
||||
controller_clc_map = "${merge(local.controller_clc_default, var.controller_clc_snippets)}"
|
||||
worker_clc_map = "${merge(local.worker_clc_default, var.worker_clc_snippets)}"
|
||||
}
|
||||
|
||||
// Horrible hack to generate a Terraform list of controller count length
|
||||
data "template_file" "controller-clc-snippets" {
|
||||
count = "${length(var.controller_names)}"
|
||||
template = "\n"
|
||||
}
|
||||
|
||||
// Horrible hack to generate a Terraform list of worker count length
|
||||
data "template_file" "worker-clc-snippets" {
|
||||
count = "${length(var.worker_names)}"
|
||||
template = "\n"
|
||||
}
|
||||
|
||||
|
@ -25,26 +25,44 @@ variable "os_version" {
|
||||
|
||||
variable "controller_names" {
|
||||
type = "list"
|
||||
description = "Ordered list of controller names (e.g. [node1])"
|
||||
}
|
||||
|
||||
variable "controller_macs" {
|
||||
type = "list"
|
||||
description = "Ordered list of controller identifying MAC addresses (e.g. [52:54:00:a1:9c:ae])"
|
||||
}
|
||||
|
||||
variable "controller_domains" {
|
||||
type = "list"
|
||||
description = "Ordered list of controller FQDNs (e.g. [node1.example.com])"
|
||||
}
|
||||
|
||||
variable "controller_clc_snippets" {
|
||||
type = "map"
|
||||
description = "Map from controller names to a lists of Container Linux Config snippets"
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "worker_names" {
|
||||
type = "list"
|
||||
description = "Ordered list of worker names (e.g. [node2, node3])"
|
||||
}
|
||||
|
||||
variable "worker_macs" {
|
||||
type = "list"
|
||||
description = "Ordered list of worker identifying MAC addresses (e.g. [52:54:00:b2:2f:86, 52:54:00:c3:61:77])"
|
||||
}
|
||||
|
||||
variable "worker_domains" {
|
||||
type = "list"
|
||||
description = "Ordered list of worker FQDNs (e.g. [node2.example.com, node3.example.com])"
|
||||
}
|
||||
|
||||
variable "worker_clc_snippets" {
|
||||
type = "map"
|
||||
description = "Map from worker names to a lists of Container Linux Config snippets"
|
||||
default = {}
|
||||
}
|
||||
|
||||
# configuration
|
||||
|
Reference in New Issue
Block a user