Skip to content

fix: lookup-safe access for optional cluster_addons + additional_node_policies (RULE-015)#350

Merged
unni-facets merged 1 commit into
mainfrom
fix/rule015-optional-spec-direct-access
Jun 3, 2026
Merged

fix: lookup-safe access for optional cluster_addons + additional_node_policies (RULE-015)#350
unni-facets merged 1 commit into
mainfrom
fix/rule015-optional-spec-direct-access

Conversation

@RoguedBear

Copy link
Copy Markdown
Contributor

Bug class (RULE-015)

Optional spec fields must be read via lookup(var.instance.spec, "field", default), never var.instance.spec.field directly. The Facets exec path does not reliably apply the optional() defaults declared in variables.tf, so a blueprint that omits an optional field crashes at plan/apply on the direct attribute access.

The two crash sites

1. kubernetes_cluster/eks_standard/1.0/main.tf

cluster_addons is an optional spec field (only cluster_version is required). The locals read the outer map var.instance.spec.cluster_addons and the nested .vpc_cni / .kube_proxy / .coredns keys directly. A blueprint that omits cluster_addons crashes with an "attribute does not exist" error before any addon logic runs.

Fix: introduce a safe local

cluster_addons_spec = lookup(var.instance.spec, "cluster_addons", {})

and route every addon read through nested lookup(local.cluster_addons_spec, "<key>", {}). With the field omitted, the per-addon enabled/version defaults apply, so all default addons are enabled (matching the schema/UI defaults).

2. karpenter/default/1.0/main.tf

additional_node_policies is optional but was read via values(var.instance.spec.additional_node_policies), which crashes when the field is omitted.

Fix:

values(lookup(var.instance.spec, "additional_node_policies", {}))

Why it's non-breaking

Behaviour is identical when the fields are present; previously-crashing omissions now fall back to documented defaults. No version bump — RULE-023 reserves version bumps for breaking changes.

Note

The same lookup-safety fix is already carried in the flavored forks of these modules; this PR backports the fix to the shared upstream flavors.

🤖 Generated with Claude Code

…_policies (RULE-015)

Optional spec fields must be read via lookup(var.instance.spec, "field",
default) rather than var.instance.spec.field directly. The Facets exec path
does not reliably apply the optional() defaults declared in variables.tf, so a
blueprint that omits an optional field crashes at plan/apply on the direct
attribute access (RULE-015).

Two crash sites fixed:

1. kubernetes_cluster/eks_standard/1.0/main.tf — cluster_addons is optional
   (only cluster_version is required). The locals read
   var.instance.spec.cluster_addons and nested .vpc_cni / .kube_proxy /
   .coredns directly, so a blueprint omitting cluster_addons crashed. Added a
   cluster_addons_spec = lookup(var.instance.spec, "cluster_addons", {}) local
   and routed every addon read through nested lookups with defaults. Omitting
   cluster_addons now enables all default addons (matching the schema/UI
   defaults).

2. karpenter/default/1.0/main.tf — additional_node_policies is optional but was
   read directly via values(var.instance.spec.additional_node_policies),
   crashing when omitted. Now values(lookup(var.instance.spec,
   "additional_node_policies", {})).

Backward-compatible bugfix: behaviour is identical when the fields are present,
and previously-crashing omissions now fall back to documented defaults. No
version bump (RULE-023 reserves bumps for breaking changes).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@RoguedBear
RoguedBear requested a review from unni-facets June 3, 2026 13:23
@unni-facets
unni-facets merged commit 6a47a8c into main Jun 3, 2026
1 check passed
@unni-facets
unni-facets deleted the fix/rule015-optional-spec-direct-access branch June 3, 2026 13:25
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.

2 participants