How to configure VPC and subnets in AWS with the aws-native provider?
TypeScriptIn your Pulumi program, you will first create a VPC (Virtual Private Cloud), then create a subnet within that VPC. To achieve this, you will use two aws-native resources:
aws-native.ec2.Vpc
to create a VPC andaws-native.ec2.Subnet
to create a subnet within the VPC.Here is a TypeScript program that accomplishes this:
import * as pulumi from "@pulumi/pulumi"; import * as awsNative from "@pulumi/aws-native"; // Create an AWS VPC const vpc = new awsNative.ec2.Vpc("vpc", { cidrBlock: "10.0.0.0/16" }); // Create a subnet in the VPC const subnet = new awsNative.ec2.Subnet("subnet", { vpcId: vpc.id, cidrBlock: "10.0.1.0/24" }); // Export the VPC and subnet IDs export const vpcId = vpc.id; export const subnetId = subnet.id;
This program first creates a VPC with its network range set to
10.0.0.0/16
. It then creates a subnet within the newly created VPC with a narrower network range of10.0.1.0/24
. The ID of the VPC and subnet are then exported for further use.