Commit f08eb02
[Bug] Fix is_subnet_public to use main route table for subnets without explicit association (#7174)
* [Bug] Fix is_subnet_public to use main route table for subnets without explicit association
When a subnet has no explicit route table association, it uses the VPC's
main route table. The previous implementation incorrectly used route_tables[0]
which may not be the main route table, causing public subnets to be
incorrectly identified as private.
This fix explicitly finds the main route table by checking the "Main" flag
in route table associations. If no main route table is found (which should
not happen in a valid VPC), an exception is raised with a helpful message.
Fixes #7173
* Use API filter association.main instead of Python filtering
Refactor is_subnet_public to use AWS API filter 'association.main=true'
to fetch only the main route table, instead of fetching all route tables
and filtering in Python. This is more efficient and cleaner.
Update test mocks to match the new API filter parameters.
* Refactor main route table tests to use pytest.mark.parametrize
Combine test_is_subnet_public_with_main_route_table and
test_is_subnet_public_main_route_table_no_igw into a single
parameterized test for better maintainability.
---------
Co-authored-by: Himani Anil Deshpande <[email protected]>1 parent 92357d9 commit f08eb02
2 files changed
+74
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
568 | 568 | | |
569 | 569 | | |
570 | 570 | | |
571 | | - | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
572 | 574 | | |
573 | 575 | | |
574 | 576 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
679 | 679 | | |
680 | 680 | | |
681 | 681 | | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
682 | 711 | | |
683 | 712 | | |
684 | 713 | | |
| |||
698 | 727 | | |
699 | 728 | | |
700 | 729 | | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
0 commit comments