-
-
Save clstokes/1c42f23a666c183f1353282fa393c82a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| from pulumi_aws import ec2 | |
| class VPCOptions: | |
| def __init__(self,cidr_block, subnets): | |
| self.cidr_block = cidr_block | |
| self.subnets = subnets | |
| class VPC: | |
| def __init__(self, | |
| name: str, | |
| options: VPCOptions): | |
| self.name = name | |
| self._options = options | |
| self._manage() | |
| self._manage_igw() | |
| self._manage_subnets() | |
| self._manage_natgw() | |
| def _manage(self): | |
| self.vpc = ec2.Vpc(self.name, | |
| cidr_block = self._options.cidr_block) | |
| def _manage_igw(self): | |
| name = f'{self.name}-igw' | |
| print(f'VPC ID before ec2.InternetGateway: {self.vpc.id}') | |
| ec2.InternetGateway(name, | |
| 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}') | |
| for i, subnet in enumerate(self.subnets): | |
| eip = ec2.Eip(f'{i}', | |
| vpc=True) | |
| ec2.NatGateway(f'{i}', | |
| subnet_id=subnet.id, | |
| allocation_id=eip.id) | |
| def _manage_subnets(self): | |
| self.subnets = [] | |
| for subnet in self._options.subnets: # TODO: change this back to subnet_generator | |
| name = subnet.get('name') | |
| self.subnets.append(ec2.Subnet(name, | |
| availability_zone=subnet.get('availability_zone'), | |
| cidr_block=subnet.get('cidr_block'), # TODO: change this back to cidr_mask | |
| vpc_id=self.vpc.id)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment