diff --git a/session-2/awsops.py b/session-2/awsops.py index c2b6ec3..880331e 100644 --- a/session-2/awsops.py +++ b/session-2/awsops.py @@ -47,7 +47,6 @@ def create_nat_gateway(self, subnet_id, eip): ) return response['NatGateway']['NatGatewayId'] - def wait_for_nat_gateway(self, nat_gateway_id): """ Use waiter method to wait till the nat gateway is ready """ waiter = self.ec2.get_waiter('nat_gateway_available') @@ -62,6 +61,11 @@ def wait_for_nat_gateway(self, nat_gateway_id): } ) + try: + response = self.ec2.create_nat_gateway(AllocationId='eip') + return response['NatGatewayId'] + except ClientError as error: + logging.error(error) def create_subnet(self, cidr): """ Get availability zone, cidr and vpc id diff --git a/session-2/config.py b/session-2/config.py index 4685c55..a31c3cb 100644 --- a/session-2/config.py +++ b/session-2/config.py @@ -6,4 +6,5 @@ PUBLIC_TAG: "10.24.0.0/23", PRIVATE_TAG: "10.24.2.0/23" } -DESTINATION = "0.0.0.0/0" \ No newline at end of file +DESTINATION = "0.0.0.0/0" +CIDR="10.24.0.0/16" \ No newline at end of file diff --git a/session-2/natgateway.py b/session-2/natgateway.py index a59b4f1..cfc76e9 100755 --- a/session-2/natgateway.py +++ b/session-2/natgateway.py @@ -9,12 +9,12 @@ def main(): args = parser.args_parser() aws = awsops.AwsOperations(args) allocate_id = aws.allocate_address() - subnet_id = aws.get_subnet_id(get-the-correct-tag-from-config) + subnet_id = aws.get_subnet_id(config.PUBLIC_TAG) nat_gateway_id = aws.create_nat_gateway(subnet_id, allocate_id) + aws.wait_for_nat_gateway(nat_gateway_id) #use function wait_for_nat_gateway to wait till the nat gateway is in available state print(nat_gateway_id) if __name__ == '__main__': main() - diff --git a/session-2/routes.py b/session-2/routes.py index 7ee1db4..a0e776b 100755 --- a/session-2/routes.py +++ b/session-2/routes.py @@ -13,6 +13,11 @@ def main(): aws.add_internet_gateway_route(route_table_id, config.DESTINATION) subnet_id = aws.get_subnet_id(config.PUBLIC_TAG) aws.associate_route_table(route_table_id, subnet_id) + private_route_table_id = aws.create_route_table() + aws.create_tags(private_route_table_id, config.PRIVATE_TAG) + private_subnet_id = aws.get_subnet_id(config.PRIVATE_TAG) + aws.associate_route_table(private_route_table_id, private_subnet_id) + aws.add_nat_gateway_route(private_route_table_id, config.DESTINATION, config.CIDR) # create private route table # create tags for the private route table # get private subnet id diff --git a/session-2/subnets.py b/session-2/subnets.py index 4f5e5b9..08852e0 100755 --- a/session-2/subnets.py +++ b/session-2/subnets.py @@ -1,4 +1,7 @@ #!/usr/bin/env python3 +""" +This module creates public and private subnet. +""" import awsops import parsing @@ -6,16 +9,22 @@ def main(): + """ + This function create a private and a public subnet + """ parser = parsing.Parsing() args = parser.args_parser() aws = awsops.AwsOperations(args) public_cidr = config.MAPPING[config.PUBLIC_TAG] subnet_id = aws.create_subnet(public_cidr) aws.create_tags(subnet_id, config.PUBLIC_TAG) - # get private subnet cidr + private_cidr = config.MAPPING[config.PRIVATE_TAG] + private_subnet_id = aws.create_subnet(private_cidr) + aws.create_tags(private_subnet_id, config.PRIVATE_TAG) + # get private subnet cidr # create private subnet # tag the private subnet if __name__ == '__main__': - main() + main() \ No newline at end of file