Skip to content

Commit

Permalink
Merge pull request #106 from NASA-IMPACT/feature/deploy-nat-instance
Browse files Browse the repository at this point in the history
Deploy NAT instance with standalone base infrastructure
  • Loading branch information
anayeaye authored Sep 15, 2022
2 parents 4b32593 + a55dbda commit 572f14a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions standalone_base_infrastructure/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Standalone Base Infrastructure

Optional shared base infrastructure provisioning. This CloudFormation stack is intended to simulate controlled deployment environments. It also useful for deploying a long-standing VPC that can be shared across stacks.
Optional shared base infrastructure provisioning. This CloudFormation stack is intended to simulate controlled deployment environments. It also useful for deploying a long-standing VPC that can be shared across stacks. This VPC is deployed with an EC2 NAT Instance that is configured as the NAT gateway provider for the private subnets.

## Deployment

Expand All @@ -26,4 +26,4 @@ See main app [deployment instructions](../README.md#deployment).
| `CDK_DEFAULT_REGION` | The AWS region id is required to deploy to an exiting VPC |
| `VPC_CIDR` | The CIDR range to use for the VPC. Default is 10.100.0.0/16 |
| `VPC_MAX_AZS` | Maximum number of availability zones per region. Default is 2. |
| `VPC_NAT_GATEWAYS` | Number of gateways to create. Default is 0. |
| `VPC_NAT_GATEWAYS` | Number of NAT gateways to create. Default is 1. |
11 changes: 11 additions & 0 deletions standalone_base_infrastructure/network_construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ def __init__(
subnet_type=aws_ec2.SubnetType.PRIVATE_ISOLATED,
)

nat_provider_instance = aws_ec2.NatProvider.instance(
instance_type=aws_ec2.InstanceType("t3.nano")
)

vpc = aws_ec2.Vpc(
self,
"vpc",
max_azs=base_settings.vpc_max_azs,
cidr=base_settings.vpc_cidr,
subnet_configuration=[public_subnet, private_subnet],
nat_gateway_provider=nat_provider_instance,
nat_gateways=base_settings.vpc_nat_gateways,
)

Expand All @@ -48,4 +53,10 @@ def __init__(
elif isinstance(service, aws_ec2.GatewayVpcEndpointAwsService):
vpc.add_gateway_endpoint(id, service=service)

# This config step associates the NAT instance EIP with the private subnet and should happen in VPC construct but does not
for private_subnet in vpc.select_subnets(
subnet_type=aws_ec2.SubnetType.PRIVATE_ISOLATED
).subnets:
nat_provider_instance.configure_subnet(subnet=private_subnet)

CfnOutput(self, "vpc-id", value=vpc.vpc_id)
2 changes: 1 addition & 1 deletion standalone_base_infrastructure/standalone_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class baseSettings(BaseSettings):

vpc_cidr: Optional[str] = "10.100.0.0/16"
vpc_max_azs: Optional[int] = 2
vpc_nat_gateways: Optional[int] = 0
vpc_nat_gateways: Optional[int] = 1

def cdk_env(self) -> dict:
"""Load a cdk environment dict for stack"""
Expand Down

0 comments on commit 572f14a

Please sign in to comment.