Ensure a nat gateway exists within the specified subnet

    This function requires boto3.

    .. versionadded:: 2016.11.0

    Example:

    .. code-block:: yaml

        boto_vpc.nat_gateway_present:
          - subnet_name: my-subnet

    name
        Name of the state

    subnet_name
        Name of the subnet within which the nat gateway should exist

    subnet_id
        Id of the subnet within which the nat gateway should exist.
        Either subnet_name or subnet_id must be provided.

    allocation_id
        If specified, the elastic IP address referenced by the ID is
        associated with the gateway. Otherwise, a new allocation_id is created and used.

    region
        Region to connect to.

    key
        Secret key to be used.

    keyid
        Access key to be used.

    profile
        A dict with region, key and keyid, or a pillar key (string) that
        contains a dict with region, key and keyid.

def nat_gateway_present(name, subnet_name=None, subnet_id=None,
                        region=None, key=None, keyid=None, profile=None, allocation_id=None):
    '''
    Ensure a nat gateway exists within the specified subnet

    This function requires boto3.

    .. versionadded:: 2016.11.0

    Example:

    .. code-block:: yaml

        boto_vpc.nat_gateway_present:
          - subnet_name: my-subnet

    name
        Name of the state

    subnet_name
        Name of the subnet within which the nat gateway should exist

    subnet_id
        Id of the subnet within which the nat gateway should exist.
        Either subnet_name or subnet_id must be provided.

    allocation_id
        If specified, the elastic IP address referenced by the ID is
        associated with the gateway. Otherwise, a new allocation_id is created and used.

    region
        Region to connect to.

    key
        Secret key to be used.

    keyid
        Access key to be used.

    profile
        A dict with region, key and keyid, or a pillar key (string) that
        contains a dict with region, key and keyid.
    '''
    ret = {'name': name,
           'result': True,
           'comment': '',
           'changes': {}
           }

    r = __salt__['boto_vpc.describe_nat_gateways'](subnet_name=subnet_name,
                                             subnet_id=subnet_id,
                                             region=region, key=key, keyid=keyid,
                                             profile=profile)
    if not r:
        if __opts__['test']:
            msg = 'Nat gateway is set to be created.'
            ret['comment'] = msg
            ret['result'] = None
            return ret

        r = __salt__['boto_vpc.create_nat_gateway'](subnet_name=subnet_name,
                                                    subnet_id=subnet_id,
                                                    region=region, key=key,
                                                    keyid=keyid, profile=profile,
                                                    allocation_id=allocation_id)
        if not r.get('created'):
            ret['result'] = False
            ret['comment'] = 'Failed to create nat gateway: {0}.'.format(r['error']['message'])
            return ret

        ret['changes']['old'] = {'nat_gateway': None}
        ret['changes']['new'] = {'nat_gateway': r['id']}
        ret['comment'] = 'Nat gateway created.'
        return ret

    inst = r[0]
    _id = inst.get('NatGatewayId')
    ret['comment'] = 'Nat gateway {0} present.'.format(_id)
    return ret