Skip to content

fix(security): resolve cluster SG from data source instead of variable#284

Merged
agustincelentano merged 1 commit intomainfrom
fix/security-resolve-cluster-sg-internally
Apr 7, 2026
Merged

fix(security): resolve cluster SG from data source instead of variable#284
agustincelentano merged 1 commit intomainfrom
fix/security-resolve-cluster-sg-internally

Conversation

@agustincelentano
Copy link
Copy Markdown
Collaborator

Summary

The cluster_security_group_id variable was used in count expressions, but on first apply when EKS doesn't exist yet, its value is (known after apply) and OpenTofu can't evaluate the count during plan.

Now the module derives the primary SG internally from data.aws_eks_cluster.this[0].vpc_config[0].cluster_security_group_id (which resolves via depends_on), using the same override pattern as vpc_id and network_cidr:

  • If cluster_security_group_id variable is provided -> use it (override)
  • If not -> derive from the EKS data source

This eliminates the need for a second tofu apply on fresh setups.

Test plan

  • Fresh apply with new EKS cluster — verify security module creates SG rules in single apply
  • Existing setup with explicit cluster_security_group_id — verify override still works
  • Plan without changes on existing infra — verify no diff

The cluster_security_group_id variable was used in count expressions,
but on first apply its value is (known after apply) causing plan
failures. Now the module derives the SG internally from
data.aws_eks_cluster when the variable is not provided, using the
same override pattern as vpc_id and network_cidr.
@gdrojas gdrojas self-requested a review April 7, 2026 18:28
@agustincelentano agustincelentano merged commit a816f55 into main Apr 7, 2026
42 checks passed
@agustincelentano agustincelentano deleted the fix/security-resolve-cluster-sg-internally branch April 7, 2026 18:29
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