Skip to content

fix(talos-cluster): guard per-node hostname patch against empty/whitespace strings#64

Merged
jfreed-dev merged 1 commit into
mainfrom
fix/talos-cluster-hostname-empty-guard
Jun 19, 2026
Merged

fix(talos-cluster): guard per-node hostname patch against empty/whitespace strings#64
jfreed-dev merged 1 commit into
mainfrom
fix/talos-cluster-hostname-empty-guard

Conversation

@jfreed-dev

Copy link
Copy Markdown
Member

Follow-up to #57 (per-node Talos hostnames), addressing two items found in a max-effort code review of that change.

Problem

The hostname patch from #57 guarded only on hostname != null:

config_patches = each.value.hostname != null ? [
  yamlencode({ machine = { network = { hostname = each.value.hostname } } })
] : []

An explicit empty string (e.g. hostname = var.cp_hostname where the var is unset → "") passes != null, so the module pushed machine.network.hostname: "" to the node instead of treating it as "no hostname override".

Fix

  • Empty/whitespace guard (main.tf, both control-plane and worker blocks): guard on trimspace(...) != "", with try() covering the null case, and trim the value used in the patch. Blank/whitespace-only hostnames are now a no-op (Talos keeps its auto-generated name), identical to null.
  • Docs — the hostname input was undocumented beyond the type:
    • New "Node Hostnames" section in the module README, including the fresh-builds-only caveat: Talos cannot rename an already-running node (static hostname already set), so a live cluster must be wiped and re-provisioned to change a hostname.
    • Expanded control_plane / workers variable descriptions (and the synced terraform-docs input table) with the same notes.
  • CHANGELOG: entries under [Unreleased].

Verification

Guard truth table via terraform console:

input try(trimspace(x), "") != "" patch applied?
null false no (was: no)
"" false no (was: yes — the bug)
" " false no (was: yes)
"turing-cp1" true yes

Also ran terraform fmt -check (clean) and terraform validate (success) on the module.

🤖 Generated with Claude Code

…space strings

The per-node hostname patch added in v1.6.0 (#57) guarded only on
`hostname != null`, so an explicit empty or whitespace-only string —
e.g. from an unset template variable — passed the check and pushed
`machine.network.hostname: ""` to the node instead of being treated as
"no hostname". Guard now uses `trimspace(...) != ""` with `try()` covering
the null case, and the patch value is trimmed; blank hostnames are now a
no-op (Talos keeps its auto-generated name), matching null.

Also document the `hostname` input: a new "Node Hostnames" section in the
module README and expanded `control_plane`/`workers` variable descriptions
note that hostnames apply at first boot only — Talos cannot rename an
already-running node (`static hostname already set`), so a live cluster
must be wiped and re-provisioned to change a hostname.

Follow-up to #57. Verified with `terraform validate`, `terraform fmt`, and
a `terraform console` truth-table check of the new guard.
@jfreed-dev jfreed-dev merged commit 74d3a76 into main Jun 19, 2026
19 checks passed
@jfreed-dev jfreed-dev deleted the fix/talos-cluster-hostname-empty-guard branch June 19, 2026 01:04
@jfreed-dev jfreed-dev mentioned this pull request Jun 19, 2026
jfreed-dev added a commit that referenced this pull request Jun 19, 2026
Patch release: empty/whitespace guard on the talos-cluster per-node
hostname patch (follow-up to #57/#64), plus hostname input documentation.
Backward compatible — no input/output signature changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant