src/nat_instance.js
function buildNatSecurityGroup(subnets = [], { name = 'NatSecurityGroup' } = {}) {
  const SecurityGroupIngress = [];

  if (Array.isArray(subnets) && subnets.length > 0) {
    subnets.forEach((subnet, index) => {
      const position = index + 1;

      const http = {
        Description: `Allow inbound HTTP traffic from ${APP_SUBNET}Subnet${position}`,
        IpProtocol: 'tcp',
        FromPort: 80,
        ToPort: 80,
        CidrIp: subnet,
      };
      const https = {
        Description: `Allow inbound HTTPS traffic from ${APP_SUBNET}Subnet${position}`,
        IpProtocol: 'tcp',
        FromPort: 443,
        ToPort: 443,
        CidrIp: subnet,
      };
      SecurityGroupIngress.push(http, https);
    });
  }

  return {
    [name]: {
      Type: 'AWS::EC2::SecurityGroup',
      Properties: {
        GroupDescription: 'NAT Instance',
        VpcId: {
          Ref: 'VPC',
        },
        SecurityGroupEgress: [
          {
            Description: 'Allow outbound HTTP access to the Internet',
            IpProtocol: 'tcp',
            FromPort: 80,
            ToPort: 80,
            CidrIp: '0.0.0.0/0',
          },
          {
            Description: 'Allow outbound HTTPS access to the Internet',
            IpProtocol: 'tcp',
            FromPort: 443,
            ToPort: 443,
            CidrIp: '0.0.0.0/0',
          },
        ],
        SecurityGroupIngress,
        Tags: [
          {
            Key: 'Name',
            Value: {
              'Fn::Join': [
                '-',
                [
                  {
                    Ref: 'AWS::StackName',
                  },
                  'nat',
                ],
              ],
            },
          },
        ],
      },
    },
  };
}
function buildNatSecurityGroup(subnets = [], { name = 'NatSecurityGroup' } = {}) {
  const SecurityGroupIngress = [];

  if (Array.isArray(subnets) && subnets.length > 0) {
    subnets.forEach((subnet, index) => {
      const position = index + 1;

      const http = {
        Description: `Allow inbound HTTP traffic from ${APP_SUBNET}Subnet${position}`,
        IpProtocol: 'tcp',
        FromPort: 80,
        ToPort: 80,
        CidrIp: subnet,
      };
      const https = {
        Description: `Allow inbound HTTPS traffic from ${APP_SUBNET}Subnet${position}`,
        IpProtocol: 'tcp',
        FromPort: 443,
        ToPort: 443,
        CidrIp: subnet,
      };
      SecurityGroupIngress.push(http, https);
    });
  }

  return {
    [name]: {
      Type: 'AWS::EC2::SecurityGroup',
      Properties: {
        GroupDescription: 'NAT Instance',
        VpcId: {
          Ref: 'VPC',
        },
        SecurityGroupEgress: [
          {
            Description: 'Allow outbound HTTP access to the Internet',
            IpProtocol: 'tcp',
            FromPort: 80,
            ToPort: 80,
            CidrIp: '0.0.0.0/0',
          },
          {
            Description: 'Allow outbound HTTPS access to the Internet',
            IpProtocol: 'tcp',
            FromPort: 443,
            ToPort: 443,
            CidrIp: '0.0.0.0/0',
          },
        ],
        SecurityGroupIngress,
        Tags: [
          {
            Key: 'Name',
            Value: {
              'Fn::Join': [
                '-',
                [
                  {
                    Ref: 'AWS::StackName',
                  },
                  'nat',
                ],
              ],
            },
          },
        ],
      },
    },
  };
}
function buildNatSecurityGroup ( subnets = [ ] , { name = 'NatSecurityGroup' } = { } ) { const SecurityGroupIngress = [ ] ; if ( Array . isArray ( subnets ) && subnets . length > 0 ) { subnets . forEach ( ( subnet , index ) => { const position = index + 1 ; const http = { Description : ` ${ APP_SUBNET } ${ position } ` , IpProtocol : 'tcp' , FromPort : 80 , ToPort : 80 , CidrIp : subnet , } ; const https = { Description : ` ${ APP_SUBNET } ${ position } ` , IpProtocol : 'tcp' , FromPort : 443 , ToPort : 443 , CidrIp : subnet , } ; SecurityGroupIngress . push ( http , https ) ; } ) ; } return { [ name ] : { Type : 'AWS::EC2::SecurityGroup' , Properties : { GroupDescription : 'NAT Instance' , VpcId : { Ref : 'VPC' , } , SecurityGroupEgress : [ { Description : 'Allow outbound HTTP access to the Internet' , IpProtocol : 'tcp' , FromPort : 80 , ToPort : 80 , CidrIp : '0.0.0.0/0' , } , { Description : 'Allow outbound HTTPS access to the Internet' , IpProtocol : 'tcp' , FromPort : 443 , ToPort : 443 , CidrIp : '0.0.0.0/0' , } , ] , SecurityGroupIngress , Tags : [ { Key : 'Name' , Value : { 'Fn::Join' : [ '-' , [ { Ref : 'AWS::StackName' , } , 'nat' , ] , ] , } , } , ] , } , } , } ; }
Build a SecurityGroup to be used by the NAT instance

@param {Array} subnets Array of subnets
@param {Object} params
@return {Object}
Build a SecurityGroup to be used by the NAT instance