-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpc_stack.py
49 lines (40 loc) · 1.43 KB
/
vpc_stack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from aws_cdk import (
# Duration,
CfnOutput,
aws_ec2 as ec2,
aws_iam as iam
)
from constructs import Construct
from helpers.BaseStack import BaseStack
import requests
CIDR="10.0.0.0/16"
class VPCstack(BaseStack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
self.vpc= self.lookup_vpc(self.config.get("vpc_name"))
if self.vpc is None:
self.vpc = self.create_vpc(construct_id)
CfnOutput(self,"VPC", value=self.vpc.vpc_id, export_name="vpc")
def create_vpc(self, vpc_name: str) -> ec2.Vpc:
vpc = ec2.Vpc(self, vpc_name,
cidr=self.config.get("vpc_cidr"),
max_azs=2,
vpc_name=vpc_name,
nat_gateways=2,
ip_addresses=ec2.IpAddresses.cidr(CIDR),
enable_dns_hostnames=True,
enable_dns_support=True,
subnet_configuration=[
ec2.SubnetConfiguration(
name="public",
subnet_type=ec2.SubnetType.PUBLIC,
cidr_mask=self.config.get("cidr_mask")
),
ec2.SubnetConfiguration(
name="private",
subnet_type=ec2.SubnetType.PRIVATE_WITH_EGRESS,
cidr_mask=self.config.get("cidr_mask")
)
]
)
return vpc