Combine bare-metal CLC snippets maps into one map

This commit is contained in:
Dalton Hubble 2018-07-26 23:31:08 -07:00
parent 4e7dfc115d
commit 90c4a7483d
4 changed files with 15 additions and 29 deletions

View File

@ -126,7 +126,7 @@ data "ct_config" "controller-ignitions" {
content = "${element(data.template_file.controller-configs.*.rendered, count.index)}" content = "${element(data.template_file.controller-configs.*.rendered, count.index)}"
pretty_print = false pretty_print = false
# Must use direct lookup. Cannot use lookup(map, key) since it only works for flat maps # 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)]}"] snippets = ["${local.clc_map[element(var.controller_names, count.index)]}"]
} }
@ -161,7 +161,7 @@ data "ct_config" "worker-ignitions" {
content = "${element(data.template_file.worker-configs.*.rendered, count.index)}" content = "${element(data.template_file.worker-configs.*.rendered, count.index)}"
pretty_print = false pretty_print = false
# Must use direct lookup. Cannot use lookup(map, key) since it only works for flat maps # 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)]}"] snippets = ["${local.clc_map[element(var.worker_names, count.index)]}"]
} }
data "template_file" "worker-configs" { data "template_file" "worker-configs" {
@ -182,23 +182,15 @@ data "template_file" "worker-configs" {
locals { locals {
# Hack to workaround https://github.com/hashicorp/terraform/issues/17251 # Hack to workaround https://github.com/hashicorp/terraform/issues/17251
# Default CLC snippets map every worker to list("\n") so all lookups succeed # Default Container Linux config snippets map every node names to list("\n") so
controller_clc_default = "${zipmap(var.controller_names, chunklist(data.template_file.controller-clc-snippets.*.rendered, 1))}" # all lookups succeed
worker_clc_default = "${zipmap(var.worker_names, chunklist(data.template_file.worker-clc-snippets.*.rendered, 1))}" clc_defaults = "${zipmap(concat(var.controller_names, var.worker_names), chunklist(data.template_file.clc-default-snippets.*.rendered, 1))}"
# Union of the default and user specific snippets, later overrides prior. # Union of the default and user specific snippets, later overrides prior.
controller_clc_map = "${merge(local.controller_clc_default, var.controller_clc_snippets)}" clc_map = "${merge(local.clc_defaults, var.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 // Horrible hack to generate a Terraform list of node count length
data "template_file" "controller-clc-snippets" { data "template_file" "clc-default-snippets" {
count = "${length(var.controller_names)}" count = "${length(var.controller_names) + length(var.worker_names)}"
template = "\n" 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"
}

View File

@ -38,12 +38,6 @@ variable "controller_domains" {
description = "Ordered list of controller FQDNs (e.g. [node1.example.com])" 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" { variable "worker_names" {
type = "list" type = "list"
description = "Ordered list of worker names (e.g. [node2, node3])" description = "Ordered list of worker names (e.g. [node2, node3])"
@ -59,9 +53,9 @@ variable "worker_domains" {
description = "Ordered list of worker FQDNs (e.g. [node2.example.com, node3.example.com])" description = "Ordered list of worker FQDNs (e.g. [node2.example.com, node3.example.com])"
} }
variable "worker_clc_snippets" { variable "clc_snippets" {
type = "map" type = "map"
description = "Map from worker names to a lists of Container Linux Config snippets" description = "Map from machine names to lists of Container Linux Config snippets"
default = {} default = {}
} }

View File

@ -89,16 +89,17 @@ module "digital-ocean-nemo" {
} }
``` ```
Bare-Metal clusters allow different Container Linux snippets to be used for each node (since hardware may be heterogeneous). Define the optional `controller_clc_snippets` and `worker_clc_snippets` map variables using controller or worker keys. Bare-Metal clusters allow different Container Linux snippets to be used for each node (since hardware may be heterogeneous). Populate the optional `clc_snippets` map variable with any controller or worker name keys and lists of snippets.
``` ```
module "bare-metal-mercury" { module "bare-metal-mercury" {
... ...
controller_names = ["node1"]
worker_names = [ worker_names = [
"node2", "node2",
"node3", "node3",
] ]
worker_clc_snippets = { clc_snippets = {
"node2" = [ "node2" = [
"${file("./units/hello.yaml")}" "${file("./units/hello.yaml")}"
] ]

View File

@ -381,8 +381,7 @@ Check the [variables.tf](https://github.com/poseidon/typhoon/blob/master/bare-me
| install_disk | Disk device where Container Linux should be installed | "/dev/sda" | "/dev/sdb" | | install_disk | Disk device where Container Linux should be installed | "/dev/sda" | "/dev/sdb" |
| networking | Choice of networking provider | "calico" | "calico" or "flannel" | | networking | Choice of networking provider | "calico" | "calico" or "flannel" |
| network_mtu | CNI interface MTU (calico-only) | 1480 | - | | network_mtu | CNI interface MTU (calico-only) | 1480 | - |
| controller_clc_snippets | Map from controller names to lists of Container Linux Config snippets | {} | | | clc_snippets | Map from machine names to lists of Container Linux Config snippets | {} | [example](/advanced/customization/#usage) |
| worker_clc_snippets | Map from worker names to lists of Container Linux Config snippets | {} | |
| network_ip_autodetection_method | Method to detect host IPv4 address (calico-only) | first-found | can-reach=10.0.0.1 | | network_ip_autodetection_method | Method to detect host IPv4 address (calico-only) | first-found | can-reach=10.0.0.1 |
| pod_cidr | CIDR IPv4 range to assign to Kubernetes pods | "10.2.0.0/16" | "10.22.0.0/16" | | pod_cidr | CIDR IPv4 range to assign to Kubernetes pods | "10.2.0.0/16" | "10.22.0.0/16" |
| service_cidr | CIDR IPv4 range to assign to Kubernetes services | "10.3.0.0/16" | "10.3.0.0/24" | | service_cidr | CIDR IPv4 range to assign to Kubernetes services | "10.3.0.0/16" | "10.3.0.0/24" |