---
AWSTemplateFormatVersion: '2010-09-09'
Description: NAT Gateway by Levon Becker v20160405-1100
Parameters:
  Owner:
    Description: Enter Team or Individual Name Responsible for the Stack.
    Type: String
    Default: FirstName LastName
  Project:
    Description: Enter Project Name.
    Type: String
    Default: NAT Gateway Creation
  DeleteAfter:
    Description: Enter Date It's Ok to Delete the Stack or 'Never' if meant to be
      persistent.
    Type: String
    Default: 00/00/201x
  VPC:
    Description: Select VPC.
    Type: AWS::EC2::VPC::Id
  PublicSubnet:
    Description: Public Subnet to Attach NAT Gateway.
    Type: AWS::EC2::Subnet::Id
  PrivateRouteTable:
    Description: Enter Private Route Table ID.
    Type: String
    Default: rtb-0000000
  PublicNetworkAcl:
    Description: Enter Public Network ACL ID.
    Type: String
    Default: acl-0000000
  AllowNatRuleNumber:
    Description: Enter Public Network ACL Rule Number to Allow Return NAT Traffic.
    Type: Number
    Default: '120'
Resources:
  NatGateway:
    Type: AWS::EC2::NatGateway
    DependsOn: NatEIP
    Properties:
      AllocationId:
        Fn::GetAtt:
        - NatEIP
        - AllocationId
      SubnetId:
        Ref: PublicSubnet
  NatEIP:
    Type: AWS::EC2::EIP
    Properties:
      Domain: vpc
  NatRoute:
    Type: AWS::EC2::Route
    DependsOn: NatGateway
    Properties:
      RouteTableId:
        Ref: PrivateRouteTable
      DestinationCidrBlock: 0.0.0.0/0
      NatGatewayId:
        Ref: NatGateway
  InboundPublicNetworkAclAllowNat:
    Type: AWS::EC2::NetworkAclEntry
    Properties:
      NetworkAclId:
        Ref: PublicNetworkAcl
      RuleNumber:
        Ref: AllowNatRuleNumber
      Protocol: '6'
      RuleAction: allow
      Egress: 'false'
      CidrBlock: 0.0.0.0/0
      PortRange:
        From: '1024'
        To: '65535'
Outputs:
  Owner:
    Description: Team or Individual that Owns this Formation.
    Value:
      Ref: Owner
  Project:
    Description: The project name
    Value:
      Ref: Project
  VPC:
    Description: VPC Used
    Value:
      Ref: VPC
  NatEIP:
    Description: NAT Elastic IP Address
    Value:
      Ref: NatEIP
  PublicNetworkACLRuleNumbers:
    Description: Public Network ACL Rules Number Created.
    Value:
      Fn::Join:
      - ''
      - - Inbound (
        - Ref: AllowNatRuleNumber
        - ")"
  DeleteAfter:
    Description: It is ok to delete the Formation after this date
    Value:
      Ref: DeleteAfter
Metadata:
  TemplateAuthor: 'Levon Becker'
  AWS::CloudFormation::Interface:
    ParameterGroups:
    - Label:
        default: Ownership
      Parameters:
      - Owner
      - Project
      - DeleteAfter
    - Label:
        default: Network Configuration
      Parameters:
      - VPC
      - PublicSubnet
      - PrivateRouteTable
      - PublicNetworkAcl
      - AllowNatRuleNumber
    ParameterLabels:
      Owner:
        default: Team or Individual Owner
      DeleteAfter:
        default: Delete After Date
      PublicSubnet:
        default: Public Subnet
      PrivateRouteTable:
        default: Private Route Table
      PublicNetworkAcl:
        default: Public Network ACL
      AllowNatRuleNumber:
        default: Public Network ACL Rule Number
