Get the default VPC
PythonTo achieve this goal, you can use the AWS package in Pulumi. The
aws.ec2
module has agetVpc
implementation that we can use to fetch the details of a specific VPC. Since you're trying to get the default VPC, we'll use thedefault
filter which targets the main VPC.Here's the code that will do this:
import pulumi from pulumi_aws import ec2 # Get default VPC default_vpc = ec2.get_vpc(default="true") # Export the VPC's ID pulumi.export('vpcId', default_vpc.id)
In this program,
ec2.get_vpc(default="true")
fetches the default VPC from your AWS environment. The ID of this VPC is then exported as an output of the Pulumi program.This uses the
aws.ec2.getVpc
function from the Pulumi Registry.