A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources with infrastructure-as-code.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Amazon VPC lets you provision a logically isolated section of AWS Cloud. VPC resources are part of the ec2 module.
Create a basic VPC with public and private subnets
const vpc = new aws.ec2.Vpc("main", { cidrBlock: "10.0.0.0/16" });
const publicSubnet = new aws.ec2.Subnet("public", {
vpcId: vpc.id,
cidrBlock: "10.0.1.0/24",
});Set up NAT Gateway for private subnet internet access
const eip = new aws.ec2.Eip("nat", { domain: "vpc" });
const natGw = new aws.ec2.NatGateway("main", {
allocationId: eip.id,
subnetId: publicSubnet.id,
});Configure VPC peering between two VPCs
const peering = new aws.ec2.VpcPeeringConnection("peer", {
vpcId: vpcA.id,
peerVpcId: vpcB.id,
autoAccept: true,
});VPC networking resources are available through aws.ec2:
import { ec2 } from "@pulumi/aws";See EC2 Documentation for detailed API signatures and examples.
import * as aws from "@pulumi/aws";
// Create VPC
const vpc = new aws.ec2.Vpc("main", {
cidrBlock: "10.0.0.0/16",
enableDnsHostnames: true,
enableDnsSupport: true,
tags: { Name: "main-vpc" },
});
// Create internet gateway
const igw = new aws.ec2.InternetGateway("main", {
vpcId: vpc.id,
});
// Create public subnet
const publicSubnet = new aws.ec2.Subnet("public", {
vpcId: vpc.id,
cidrBlock: "10.0.1.0/24",
mapPublicIpOnLaunch: true,
availabilityZone: "us-west-2a",
});
// Create private subnet
const privateSubnet = new aws.ec2.Subnet("private", {
vpcId: vpc.id,
cidrBlock: "10.0.2.0/24",
availabilityZone: "us-west-2a",
});
// Create NAT gateway
const eip = new aws.ec2.Eip("nat", { domain: "vpc" });
const natGw = new aws.ec2.NatGateway("main", {
allocationId: eip.id,
subnetId: publicSubnet.id,
});
// Public route table
const publicRt = new aws.ec2.RouteTable("public", {
vpcId: vpc.id,
routes: [{
cidrBlock: "0.0.0.0/0",
gatewayId: igw.id,
}],
});
new aws.ec2.RouteTableAssociation("public", {
subnetId: publicSubnet.id,
routeTableId: publicRt.id,
});
// Private route table
const privateRt = new aws.ec2.RouteTable("private", {
vpcId: vpc.id,
routes: [{
cidrBlock: "0.0.0.0/0",
natGatewayId: natGw.id,
}],
});
new aws.ec2.RouteTableAssociation("private", {
subnetId: privateSubnet.id,
routeTableId: privateRt.id,
});
export const vpcId = vpc.id;Install with Tessl CLI
npx tessl i tessl/npm-pulumi--aws