CodexBloom - Programming Q&A Platform

Terraform 1.5.0 scenarios to set up AWS VPC Peering with 'Invalid VPC ID' scenarios despite valid configuration

πŸ‘€ Views: 35 πŸ’¬ Answers: 1 πŸ“… Created: 2025-05-31
terraform aws vpc-peering hcl

I'm having a hard time understanding I'm confused about I've been researching this but I've been banging my head against this for hours... I'm trying to create a VPC peering connection between two VPCs using Terraform 1.5.0, but I keep running into an behavior stating 'Invalid VPC ID' during the execution. I've ensured that both VPCs are in the same region and that the IDs are correctly specified. Here’s the code snippet I'm using: ```hcl resource "aws_vpc" "vpc_a" { cidr_block = "10.0.0.0/16" tags = { Name = "VPC_A" } } resource "aws_vpc" "vpc_b" { cidr_block = "10.1.0.0/16" tags = { Name = "VPC_B" } } resource "aws_vpc_peering_connection" "peer" { vpc_id = aws_vpc.vpc_a.id peer_vpc_id = aws_vpc.vpc_b.id } ``` When I run `terraform apply`, I get this behavior: ``` behavior: Invalid VPC ID on main.tf line 10, in resource "aws_vpc_peering_connection" "peer": 10: peer_vpc_id = aws_vpc.vpc_b.id ``` To troubleshoot, I checked the outputs of both VPC resources and confirmed that they are being created properly, as shown below: ```hcl output "vpc_a_id" { value = aws_vpc.vpc_a.id } output "vpc_b_id" { value = aws_vpc.vpc_b.id } ``` Both outputs display the correct VPC IDs, but for some reason, the peering connection fails. I've also tried using hardcoded values for the VPC IDs, but I still receive the same behavior. Any insights on what could be causing this scenario or how to resolve it would be greatly appreciated! This is my first time working with Hcl stable. Is this even possible? Has anyone dealt with something similar? I'd be grateful for any help. Has anyone dealt with something similar? Hoping someone can shed some light on this.