CodexBloom - Programming Q&A Platform

AWS CloudFormation scenarios to Create VPC Peering Connection with 'InvalidVpcPeeringConnectionState' scenarios

👀 Views: 86 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-08
AWS CloudFormation VPC yaml

I'm writing unit tests and I've been struggling with this for a few days now and could really use some help. I'm trying to set up a VPC peering connection between two VPCs using AWS CloudFormation, but the stack creation fails with the behavior 'InvalidVpcPeeringConnectionState'. I have the following CloudFormation template: ```yaml Resources: VpcA: Type: AWS::EC2::VPC Properties: CidrBlock: 10.0.0.0/16 EnableDnsSupport: true EnableDnsHostnames: true Tags: - Key: Name Value: VpcA VpcB: Type: AWS::EC2::VPC Properties: CidrBlock: 10.1.0.0/16 EnableDnsSupport: true EnableDnsHostnames: true Tags: - Key: Name Value: VpcB VpcPeeringConnection: Type: AWS::EC2::VPCPeeringConnection Properties: PeerVpcId: !Ref VpcB VpcId: !Ref VpcA Tags: - Key: Name Value: VpcPeeringConnection ``` I've ensured that both VPCs are in the same region and that I'm not exceeding the limit of active VPC peering connections. Additionally, I have the necessary permissions set for the IAM role executing this stack. When I attempt to create the stack, I get the following behavior: ``` CREATE_FAILED InvalidVpcPeeringConnectionState: VPC peering connection is not in a valid state for the requested action. ``` I've tried deploying the VPCs first without the peering connection and then creating the peering connection afterward, but I still face the same scenario. Is there something specific about the order of resource creation or configuration that I'm missing? Any insights would be greatly appreciated! Any help would be greatly appreciated! For context: I'm using Yaml on Linux. Is there a simpler solution I'm overlooking?