We have a VPC with an Internet Gateway. We have 3 subnets (one in each AZ) and want to use one routing table for all three. This RT contains a rule to route 0.0.0.0/0 to the igw however when we try associate more than one subnet with this RT the stack creation fails on creating the routing rule, giving the following error message:
route table rtb-xxxxxxx and network gateway igw-xxxxx belong to different networks.
This is weird because the igw isn't attached to a subnet, it's attached to the VPC itself.
What I have to do to get the template working is to only have 1 subnet association with the RT and then update the stack afterwards with the other two.
I've tried adding 2 Wait Conditions, one tied to the creation of the RT and the other to the creation of the routing rule however they don't fix the problem – I still get the same error on the same damn rule 🙁
Can anyone shed some light on what I need to do to fix this issue?
Best Answer
As @Marcus explained in his response to his own question; it is the lack of the DependsOn attribute when you create an AWS::EC2::Route entry where you specify a Gateway.
Having received the same error and scratching my head as to how this failed when the IGW is attached to the VPC it was a simple change in the
AWS::EC2::Route
declaration.Failing CFN:
Working CFN: