src/vpc.js
function buildRoute(
  name,
  position,
  { NatGatewayId = null, GatewayId = null, InstanceId = null } = {},
) {
  const route = {
    Type: 'AWS::EC2::Route',
    Properties: {
      DestinationCidrBlock: '0.0.0.0/0',
      RouteTableId: {
        Ref: `${name}RouteTable${position}`,
      },
    },
  };

  if (NatGatewayId) {
    route.Properties.NatGatewayId = {
      Ref: NatGatewayId,
    };
  } else if (GatewayId) {
    route.Properties.GatewayId = {
      Ref: GatewayId,
    };
  } else if (InstanceId) {
    route.Properties.InstanceId = {
      Ref: InstanceId,
    };
  } else {
    throw new Error(
      'Unable to create route: either NatGatewayId, GatewayId or InstanceId must be provided',
    );
  }

  const cfName = `${name}Route${position}`;
  return {
    [cfName]: route,
  };
}
function buildRoute(
  name,
  position,
  { NatGatewayId = null, GatewayId = null, InstanceId = null } = {},
) {
  const route = {
    Type: 'AWS::EC2::Route',
    Properties: {
      DestinationCidrBlock: '0.0.0.0/0',
      RouteTableId: {
        Ref: `${name}RouteTable${position}`,
      },
    },
  };

  if (NatGatewayId) {
    route.Properties.NatGatewayId = {
      Ref: NatGatewayId,
    };
  } else if (GatewayId) {
    route.Properties.GatewayId = {
      Ref: GatewayId,
    };
  } else if (InstanceId) {
    route.Properties.InstanceId = {
      Ref: InstanceId,
    };
  } else {
    throw new Error(
      'Unable to create route: either NatGatewayId, GatewayId or InstanceId must be provided',
    );
  }

  const cfName = `${name}Route${position}`;
  return {
    [cfName]: route,
  };
}
function buildRoute ( name , position , { NatGatewayId = null , GatewayId = null , InstanceId = null } = { } , ) { const route = { Type : 'AWS::EC2::Route' , Properties : { DestinationCidrBlock : '0.0.0.0/0' , RouteTableId : { Ref : ` ${ name } ${ position } ` , } , } , } ; if ( NatGatewayId ) { route . Properties . NatGatewayId = { Ref : NatGatewayId , } ; } else if ( GatewayId ) { route . Properties . GatewayId = { Ref : GatewayId , } ; } else if ( InstanceId ) { route . Properties . InstanceId = { Ref : InstanceId , } ; } else { throw new Error ( 'Unable to create route: either NatGatewayId, GatewayId or InstanceId must be provided' , ) ; } const cfName = ` ${ name } ${ position } ` ; return { [ cfName ] : route , } ; }
Build a Route for a NatGateway or InternetGateway

@param {String} name
@param {Number} position
@param {Object} params
@return {Object}
Build a Route for a NatGateway or InternetGateway