Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
baremetal: use templatefile instead of template_file data source
Browse files Browse the repository at this point in the history
This commit changes the template method we use in baremetal Terraform
code responsible for generating workers Ignition configs from
template_file data source coming from 3rd party Terraform provider
to built-in 'templatefile' function, which is available from
Terraform 0.12, as it provides the exact same functionality, but
do not require downloading 3rd party provider.

Also 'template' provider recommends using this function:
https://www.terraform.io/docs/providers/template/d/file.html.

This also allows passing parameters to the template in complex types
(like lists) and call functions like 'join' inside the template, which
better separates data from how they are rendered.

Part of #196

Signed-off-by: Mateusz Gozdek <mateusz@kinvolk.io>
  • Loading branch information
invidian committed May 28, 2020
1 parent 9545489 commit 9db538b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ storage:
KUBELET_IMAGE_URL=docker://k8s.gcr.io/hyperkube
KUBELET_IMAGE_TAG=v1.18.3
KUBELET_IMAGE_ARGS="--exec=/usr/local/bin/kubelet"
NODE_LABELS="${kubelet_labels}"
NODE_LABELS="${join(",", [for k, v in kubelet_labels : "${k}=${v}"])}"
- path: /etc/hostname
filesystem: root
mode: 0644
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,26 +206,18 @@ resource "matchbox_profile" "workers" {
}

data "ct_config" "worker-ignitions" {
count = length(var.worker_names)
content = data.template_file.worker-configs[count.index].rendered
pretty_print = false

# Must use direct lookup. Cannot use lookup(map, key) since it only works for flat maps
snippets = local.clc_map[var.worker_names[count.index]]
}

data "template_file" "worker-configs" {
count = length(var.worker_names)

template = file("${path.module}/cl/worker.yaml.tmpl")

vars = {
content = templatefile("${path.module}/cl/worker.yaml.tmpl", {
domain_name = var.worker_domains[count.index]
cluster_dns_service_ip = module.bootkube.cluster_dns_service_ip
cluster_domain_suffix = var.cluster_domain_suffix
ssh_keys = jsonencode(var.ssh_keys)
kubelet_labels = join(",", [for k, v in merge({ "node.kubernetes.io/node" = "" }, var.labels) : "${k}=${v}"])
}
kubelet_labels = merge({ "node.kubernetes.io/node" = "" }, var.labels),
})
pretty_print = false

# Must use direct lookup. Cannot use lookup(map, key) since it only works for flat maps
snippets = local.clc_map[var.worker_names[count.index]]
}

locals {
Expand Down
Loading

0 comments on commit 9db538b

Please sign in to comment.