I have created a VPC B through Ansible playbook. Now I want to do the VPC peering between VPC B and VPC A. I can create VPC peering and activate the VPC peering connection.
But I am struggling with how to Append/Edit existing route table entry for VPC A with the new vpc_peering_id.
One way to update the route table through AWS CLI replace-route command.
Example: aws ec2 replace-route --route-table-id rtb-d0e3dsb7 --destination-cidr-block 10.101.0.0/16 --vpc-peering-connection-id pcx-0ffa4766
This will update vpc_peering_connection_id -pcx-0ffa4766 as gateway for CIDR 10.101.0.0/16 in existing route table -rtb-d0e3dsb7.
Now I can use this command in Ansible play, which will update vpc_peering_id in existing route table of VPC A to communicate between VPC A and VPC B.