-
-
Save ohlol/9b4923804c6de07ca1c5c23dfcd37d60 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class VPC: | |
def __init__(self, | |
name: str, | |
options: VPCOptions): | |
self.name = name | |
self._options = options | |
self._manage() | |
self._manage_hosted_domain() | |
self._manage_igw() | |
self._manage_subnets() | |
self._manage_natgw() | |
def _manage(self): | |
self.vpc = ec2.Vpc(self.name, | |
cidr_block = self._options.cidr_block, | |
tags = merge_tags_with_name(self.name, self._options.tags)) | |
def _manage_hosted_domain(self): | |
if self._options.create_route53_zone: | |
zone_name = f'{self.name}.{self._options.region}.internal' | |
route53.Zone(zone_name, | |
name=zone_name, | |
vpcs=[{ | |
'vpc_id': self.vpc.id, | |
}]) | |
def _manage_igw(self): | |
name = f'{self.name}-igw' | |
print(f'VPC ID before ec2.InternetGateway: {self.vpc.id}') | |
ec2.InternetGateway(name, | |
tags=merge_tags_with_name(name, self._options.tags), | |
vpc_id=self.vpc.id) | |
def _manage_natgw(self): | |
name = f'{self.name}-natgw' | |
print(f'VPC ID before deriving subnets for ec2.NatGateway: {self.vpc.id}') | |
subnets = ec2.get_subnet_ids(vpc_id=self.vpc) | |
def _manage_subnets(self): | |
for subnet in subnet_generator(self._options.cidr_block, self._options.subnets): | |
name = subnet.get('name') | |
ec2.Subnet(name, | |
availability_zone=subnet.get('availability_zone'), | |
cidr_block=subnet.get('cidr_block'), | |
tags=merge_tags_with_name(name, self._options.tags), | |
vpc_id=self.vpc.id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment