Skip to content

Conversation

@Manoj-Kumar-Selvaraj
Copy link

@Manoj-Kumar-Selvaraj Manoj-Kumar-Selvaraj commented Nov 8, 2025

[Test_Results.docx](https://github.com/user-attachments/files/23433838/Test_Results.docx)

✳️ Pull Request — Fix NAT Gateway AZ Mapping Logic (#1257)

📝 Description

This PR fixes and improves the subnet-to-AZ mapping logic in the VPC module, ensuring that NAT gateways are consistently mapped to their respective Availability Zones (AZs).
The update also improves behavior when the number of subnets differs from the number of AZs and updates example configurations accordingly.


🎯 Motivation and Context

Previously, subnet indexing caused misalignment between public/private subnets and NAT gateways when subnet counts did not match AZ counts.
This resulted in uneven NAT gateway distribution or mismatched subnet routing.

This PR ensures:

  • Consistent NAT gateway allocation per AZ

  • Flexible handling when the number of subnets > or < number of AZs

  • Accurate example coverage for both 2-AZ and 3-AZ configurations

Fixes: #1257


⚙️ Breaking Changes

No breaking changes.
Existing configurations using standard subnet-to-AZ ratios remain fully compatible.
Only internal subnet indexing logic is refined to ensure correctness and consistency.


🧪 How Has This Been Tested?

  • Updated and validated examples/complete to demonstrate proper behavior

  • Tested with multiple configurations:

    • AZ = #Subnets → NAT gateways align correctly

    • 2 AZs → validated subnet indexing logic

    • #Subnets > AZs → confirmed correct subnet distribution

  • Executed pre-commit run -a successfully

    • terraform fmt, terraform_docs, tflint, and validate passed

    • ✅ Wrapper modules generated successfully (wrappers/)

  • Verified terraform plan output across all scenarios

  • 📎 Test evidence and screenshots attached: Test_Results.docx


🧩 Files Updated

  • variables.tf — refined subnet/AZ indexing logic

  • wrappers/main.tf — regenerated wrappers

  • examples/complete/main.tf — validated multi-AZ behavior

  • README.md — updated automatically by terraform_docs


✅ Summary of Validation

Check Status
terraform fmt ✅ Passed
terraform_docs ✅ Regenerated
tflint ✅ Passed
terraform validate ✅ Passed
Example plans (2 AZ / 3 AZ / >AZ) ✅ Verified
Pre-commit checks ✅ All passed

🙌 Notes for Maintainers

  • The PR follows contributing guidelines

  • Semantic commit: fix(vpc): correct NAT gateway AZ mapping logic (#1257)

  • No manual changelog update required (maintainers handle this at merge)


📸 Test Artifacts

  • Attached: Test_Results.docx — includes screenshots, plan outputs, and hook validation logs.


@Manoj-Kumar-Selvaraj
Copy link
Author

@antonbabenko — all checks passed and requirements met. Please review when you get a chance. 🙏

@Manoj-Kumar-Selvaraj Manoj-Kumar-Selvaraj changed the title fix(nat): ensure NAT gateways are created in correct availability zone(#1257) fix(nat): Ensure NAT gateways are created in correct availability zone (#1257) Nov 9, 2025
@Manoj-Kumar-Selvaraj Manoj-Kumar-Selvaraj marked this pull request as draft November 9, 2025 04:11
@Manoj-Kumar-Selvaraj Manoj-Kumar-Selvaraj marked this pull request as ready for review November 9, 2025 04:13
@Manoj-Kumar-Selvaraj Manoj-Kumar-Selvaraj marked this pull request as draft November 9, 2025 04:13
@Manoj-Kumar-Selvaraj Manoj-Kumar-Selvaraj marked this pull request as ready for review November 9, 2025 04:22
@Manoj-Kumar-Selvaraj
Copy link
Author

@antonbabenko — all checks passed and requirements met. Please review when you get a chance

@Manoj-Kumar-Selvaraj
Copy link
Author

@antonbabenko — All checks are passed with required changes, Please reeview it once you get some time.

@Manoj-Kumar-Selvaraj Manoj-Kumar-Selvaraj changed the title fix(nat): Ensure NAT gateways are created in correct availability zone (#1257) fix(nat):Ensure NAT gateways are created in correct availability zone (#1257) Nov 10, 2025
@Manoj-Kumar-Selvaraj Manoj-Kumar-Selvaraj changed the title fix(nat):Ensure NAT gateways are created in correct availability zone (#1257) fix(nat): Ensure NAT gateways are created in correct availability zone (#1257) Nov 10, 2025
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