Passing VPC_ID from one Env (ex: Dev) to Another Env (ex: stage)

Hey,

Here is my framework

Environments
—dev
------main.tf
—stage
------main.tf
VPC
------main.tf
------variables.tf
------outputs.tf

VPC Module is like below and Used Outputs to VPC_ID

resource “aws_vpc” “vpc” {

}

Environments–>Dev–.>Main.tf is like create VPC
module “vpc” {

source = “…/…/vpc/”

}

My requirement over here, I needed to pass DEV ENV VPC ID to STAGE ENV to establish VPC Peering.

If its the same environment or main.tf means, i’m using below to get id, but is there any way to get passed this VPC_ID dynamically in any another environment like Stage?

“${module.vpc.vpc_id}”

It would be grate if you could share any sample example or code, pretty much appreciated.

Thank you so much for your time and kind favor,
Bala

Hi @balarajuaws68

You could use Data Source: aws_vpc to search for the ID of the VPC from another Terraform environment, for example if you know the cidr_block, a tag or other VPC unique characteristics.

See documentation at: