How to import AWS VPC with Pulumi CLI?TypeScript
You can import an existing VPC into a Pulumi program using the
getfunction, provided by Pulumi AWS Provider. This will allow Pulumi to retrieve the state of the existing VPC without needing to manage it.
Here's an example on how you might do this:
This program uses
aws.ec2.getVpcto get the VPC based on its ID. You'll need to replace
"your-vpc-id"with your actual VPC ID. The
vpcconstant will hold a promise which resolves to the VPC details. Note that the VPC details are not immediately available because they're fetched asynchronously. Thus, if you want to access these details (like the
cidrBlock), you need to use
Once you run this program, you can retrieve the exported VPC CIDR block using the
pulumi stack output vpcCidrBlockcommand in the CLI.