feat(clusters): key for_each by host, validate hostname uniqueness (#68, #69)#83
Merged
jfreed-dev merged 1 commit intoJun 26, 2026
Merged
Conversation
…, #69) Two v1.7.0 follow-ups for talos-cluster and k3s-cluster, milestoned v1.8.0. #69 — key per-node resources by host instead of list index. The Talos talos_machine_configuration_apply.{controlplane,worker} and the K3s null_resource.{k3s_workers,bootstrap_ssh_workers} / data.tls_public_key .workers_bootstrap were keyed positionally, so removing/reordering a node shifted every later index and re-targeted config at a surviving host (Talos rejects a re-applied hostname with "static hostname already set"; K3s re-runs the agent install). Now keyed by the stable host; the Talos hostname_patches map is host-keyed to match. Instance addresses change, so existing state needs a one-time `tofu state mv` (recipe in each module README + docs/UPGRADE.md); moved {} blocks can't ship in a reusable module since the index->host mapping depends on the consumer's node list. #68 — validate hostname uniqueness across control_plane + workers at plan time. A duplicate non-blank hostname makes two nodes register under the same node identity (kubelet collision). A resource lifecycle precondition now fails the plan naming the duplicate; null/empty/whitespace stay exempt. precondition is the lightest mechanism that actually fails the plan (check{} only warns), so required_version is raised >= 1.0 -> >= 1.2 in both modules; READMEs and the project prerequisite updated to match. Validated with `tofu plan`: duplicate hostnames fail with the named-duplicate message, unique/blank hostnames plan cleanly, resources keyed by host. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two v1.7.0 (#67) follow-ups for
talos-clusterandk3s-cluster, both milestoned v1.8.0.#69 — key
for_eachby host, not list index (bug)The per-node resources keyed
for_eachpositionally:talos_machine_configuration_apply.{controlplane,worker}null_resource.{k3s_workers,bootstrap_ssh_workers},data.tls_public_key.workers_bootstrapRemoving/reordering a node shifted every later index, so Terraform re-targeted the surviving instances at a different host — re-pushing Talos machine config (which a live node rejects with
static hostname already set) or re-running the K3s install provisioners. Now keyed by the stablenode.host; the Taloslocal.hostname_patchesmap is host-keyed to match.All index-keyed worker
for_eachblocks in k3s were re-keyed together (not just the install one) so they stay consistent.#68 — plan-time hostname uniqueness (enhancement)
A duplicate non-blank
hostnameacrosscontrol_plane+workersmade two nodes register under the same Talos/Kubernetes node identity (kubelet collision, one node shadows the other) with no plan-time signal. A resourcelifecycleprecondition now failsterraform plannaming the duplicate. Null/empty/whitespace stay exempt.preconditionis the lightest mechanism that actually fails the plan —check {}only warns, cross-variablevalidationneeds TF >= 1.9 — sorequired_versionis raised>= 1.0→>= 1.2in both modules.Instance addresses change (
…["0"]→…["10.10.88.73"]). Existing state must be re-mapped once withtofu state mvbefore the nextapply, or Terraform destroys/recreates the apply resources against live nodes. Per-module recipes are in each README ("Upgrading from < v1.8.0") anddocs/UPGRADE.md.moved {}blocks can't ship in a reusable module — the index→host mapping depends on the consumer's node list/order.Validation
tofu validate+tofu fmt -checkpass on both modules. Offlinetofu planconfirms:…["10.0.0.1"])Docs
>= 1.2, uniqueness note, "Upgrading from < v1.8.0" state-mv recipedocs/UPGRADE.md: new### v1.8.0Breaking Changes entry>= 1.2CHANGELOG.md:## [1.8.0]entry (+ restored the missing 1.7.0–1.7.2 compare links)Closes #68
Closes #69