Skip to content
This repository was archived by the owner on Oct 21, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion session-2/awsops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion session-2/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
PUBLIC_TAG: "10.24.0.0/23",
PRIVATE_TAG: "10.24.2.0/23"
}
DESTINATION = "0.0.0.0/0"
DESTINATION = "0.0.0.0/0"
CIDR="10.24.0.0/16"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you using the same config for the VPC creation? otherwise, this is not required

4 changes: 2 additions & 2 deletions session-2/natgateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

5 changes: 5 additions & 0 deletions session-2/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions session-2/subnets.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
#!/usr/bin/env python3
"""
This module creates public and private subnet.
"""

import awsops
import parsing
import config


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()