Skip to content

Conversation

bamdadd
Copy link
Contributor

@bamdadd bamdadd commented Sep 25, 2025

This pull request refactors the Terraform configuration to use for_each instead of count for resources that are created per availability zone. This change improves resource management by making it easier to add or remove availability zones without destroying existing resources. Outputs are also updated to use explicit mapping by availability zone, and a new integration test is added to verify that adding an availability zone does not destroy existing resources.

Resource management improvements:

  • Refactored all per-availability-zone resources in public_subnets.tf, private_subnets.tf, and nat.tf to use for_each with toset(var.availability_zones) instead of count, ensuring stable resource addressing and preventing unnecessary resource destruction when availability zones are changed. [1] [2] [3]
  • Updated resource references and tags to use each.value (the AZ name) for clearer resource identification and mapping. [1] [2] [3]

Output consistency:

  • Modified all outputs in outputs.tf to explicitly map resource IDs and CIDR blocks by availability zone, ensuring outputs remain stable and predictable when AZs are added or removed.

Testing and validation:

  • Added a new integration test spec/integration/availability_zone_addition_spec.rb that verifies adding an availability zone results only in new resources being created, with no destruction of existing subnets, NAT gateways, or EIPs.

@bamdadd bamdadd requested a review from tobyclemson September 25, 2025 11:24
@jonassvalin
Copy link
Contributor

Breaking change so will need a major version upgrade

@johncowie johncowie merged commit 0e05f06 into main Oct 8, 2025
@johncowie johncowie deleted the support-az-updates branch October 8, 2025 10:03
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.

3 participants