hallowed-animal-47023
05/30/2021, 1:48 PMimport pulumi
from pulumi_aws import ec2, get_availability_zones
# Create AWS VPC with specified name, CIDR block, and enable DNS
class VPC(pulumi.ComponentResource):
"""
This creates a base VPC with subnets in every available availability zone
"""
def __init__(
self,
name,
opts=None
):
vpc = ec2.Vpc(name,
cidr_block="10.0.0.0/16",
enable_dns_support=True,
enable_dns_hostnames=True,
tags={
'Name': name
})
availability_zones = get_availability_zones(state="available")
public_subnets = []
private_subnets = []
for x in range(len(availability_zones.names)):
public_subnets.append(
ec2.Subnet(f"Prod-Public-{availability_zones.names[x]}",
availability_zone=availability_zones.names[x],
cidr_block=f"10.0.{x + 1}.0/24",
vpc_id=vpc.id,
tags={
'Name': f"Prod-Public-{availability_zones.names[x]}"
})
)
private_subnets.append(
ec2.Subnet(f"Prod-Private-{availability_zones.names[x]}",
availability_zone=availability_zones.names[x],
cidr_block=f"10.0.{x + len(availability_zones.names) + 1}.0/24",
vpc_id=vpc.id,
tags={
'Name': f"Prod-Private-{availability_zones.names[x]}"
})
)
nat_gateways = []
nat_eips = []
for x in range(2):
nat_eips.append(
ec2.Eip(
f"NAT-Gateway-IP-{x}",
vpc=True,
tags={
"Name": f"NAT-Gateway-IP-{x}"
}
)
)
# nat_gateways.append(
# ec2.NatGateway(
# f"{name}-NAT-Gateway",
# allocation_id=nat_eips[x],
# subnet_id=public_subnets[x].id,
# tags = {
# "Name": f"NAT-Gateway-{x}"
# })
# )
# Export VPC Id
pulumi.export('vpc_id', vpc.id)
url = vpc.id.apply(lambda vpc_id: "https//"+vpc_id)
sticky-bear-14421
06/01/2021, 7:12 AMhallowed-animal-47023
06/01/2021, 12:40 PMsticky-bear-14421
06/02/2021, 5:06 AM