Skip to content

Commit

Permalink
feat(k3s_env_vars): introduce variable for speicfic k3s installation …
Browse files Browse the repository at this point in the history
…environment variabels
  • Loading branch information
FalcoSuessgott committed May 14, 2023
1 parent fa0a2d2 commit 4b7f090
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion agent_nodes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ resource "null_resource" "agents_install" {
// Install k3s
provisioner "remote-exec" {
inline = [
"INSTALL_K3S_SELINUX_WARN=${var.k3s_selinux_warn} INSTALL_K3S_VERSION=${local.k3s_version} sh /tmp/k3s-installer agent ${local.agents_metadata[each.key].flags}",
"${local.install_env_vars} INSTALL_K3S_VERSION=${local.k3s_version} sh /tmp/k3s-installer agent ${local.agents_metadata[each.key].flags}",
"until systemctl is-active --quiet k3s-agent.service; do sleep 1; done"
]
}
Expand Down
4 changes: 3 additions & 1 deletion server_nodes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ locals {
// If root_advertise_ip is IPv6 wrap it in square brackets for IPv6 K3S URLs otherwise leave it raw
root_advertise_ip_k3s = can(regex("::", local.root_advertise_ip)) ? "[${local.root_advertise_ip}]" : local.root_advertise_ip

// string representation of all specified extra k3s installation env vars
install_env_vars = join(" ", [for k, v in var.k3s_install_env_vars : "${k}=${v}"])

root_server_connection = {
type = try(var.servers[local.root_server_name].connection.type, "ssh")
Expand Down Expand Up @@ -213,7 +215,7 @@ resource "null_resource" "servers_install" {
// Install k3s server
provisioner "remote-exec" {
inline = [
"INSTALL_K3S_SELINUX_WARN=${var.k3s_selinux_warn} INSTALL_K3S_VERSION=${local.k3s_version} sh /tmp/k3s-installer server ${local.servers_metadata[each.key].flags}",
"${local.install_env_vars} INSTALL_K3S_VERSION=${local.k3s_version} sh /tmp/k3s-installer server ${local.servers_metadata[each.key].flags}",
"until ${local.kubectl_cmd} get node ${local.servers_metadata[each.key].name}; do sleep 1; done"
]
}
Expand Down
17 changes: 11 additions & 6 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ variable "k3s_version" {
default = "latest"
}

variable "k3s_selinux_warn" {
description = "Force the install script to log a warning rather than fail when k3s tries to install the SELinux policies."
type = bool
default = false
variable "k3s_install_env_vars" {
description = "map of enviroment variables that are passed to the k3s installation script (see https://docs.k3s.io/reference/env-variables)"
type = map(string)
default = null

validation {
condition = !can(var.k3s_install_env_vars["INSTALL_K3S_VERSION"])
error_message = "Environment variable \"INSTALL_K3S_VERSION\" needs to be set via variable k3s_version"
}
}

variable "name" {
Expand Down Expand Up @@ -95,7 +100,7 @@ variable "servers" {
}
validation {
condition = !can(values(var.servers)[*].flags) || !contains([for v in var.servers : can(tolist(v.flags))], false)
error_message = "Field servers.<name>.flags must be a list of string."
error_message = "Field servers.<name>.flags must be a list of string (see: https://docs.k3s.io/cli/server)."
}
validation {
condition = !can(values(var.servers)[*].annotations) || !contains([for v in var.servers : can(tomap(v.annotations))], false)
Expand Down Expand Up @@ -126,7 +131,7 @@ variable "agents" {
}
validation {
condition = !can(values(var.agents)[*].flags) || !contains([for v in var.agents : can(tolist(v.flags))], false)
error_message = "Field agents.<name>.flags must be a list of string."
error_message = "Field agents.<name>.flags must be a list of string (see: https://docs.k3s.io/cli/agent)."
}
validation {
condition = !can(values(var.agents)[*].annotations) || !contains([for v in var.agents : can(tomap(v.annotations))], false)
Expand Down

0 comments on commit 4b7f090

Please sign in to comment.