Check if a subnet exists.

    Returns True if the subnet exists, otherwise returns False.

    .. versionchanged:: 2015.8.0
        Added subnet_name argument
        Deprecated name argument

    CLI Example:

    .. code-block:: bash

        salt myminion boto_vpc.subnet_exists subnet_id='subnet-6a1fe403'

def subnet_exists(subnet_id=None, name=None, subnet_name=None, cidr=None,
                  tags=None, zones=None, region=None, key=None, keyid=None,
                  profile=None):
    '''
    Check if a subnet exists.

    Returns True if the subnet exists, otherwise returns False.

    .. versionchanged:: 2015.8.0
        Added subnet_name argument
        Deprecated name argument

    CLI Example:

    .. code-block:: bash

        salt myminion boto_vpc.subnet_exists subnet_id='subnet-6a1fe403'

    '''
    if name:
        log.warning('boto_vpc.subnet_exists: name parameter is deprecated '
                    'use subnet_name instead.')
        subnet_name = name

    if not any((subnet_id, subnet_name, cidr, tags, zones)):
        raise SaltInvocationError('At least one of the following must be '
                                  'specified: subnet id, cidr, subnet_name, '
                                  'tags, or zones.')

    try:
        conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
    except BotoServerError as err:
        return {'error': __utils__['boto.get_error'](err)}

    filter_parameters = {'filters': {}}
    if subnet_id:
        filter_parameters['subnet_ids'] = [subnet_id]
    if subnet_name:
        filter_parameters['filters']['tag:Name'] = subnet_name
    if cidr:
        filter_parameters['filters']['cidr'] = cidr
    if tags:
        for tag_name, tag_value in six.iteritems(tags):
            filter_parameters['filters']['tag:{0}'.format(tag_name)] = tag_value
    if zones:
        filter_parameters['filters']['availability_zone'] = zones

    try:
        subnets = conn.get_all_subnets(**filter_parameters)
    except BotoServerError as err:
        boto_err = __utils__['boto.get_error'](err)
        if boto_err.get('aws', {}).get('code') == 'InvalidSubnetID.NotFound':
            # Subnet was not found: handle the error and return False.
            return {'exists': False}
        return {'error': boto_err}

    log.debug('The filters criteria %s matched the following subnets:%s',
              filter_parameters, subnets)
    if subnets:
        log.info('Subnet %s exists.', subnet_name or subnet_id)
        return {'exists': True}
    else:
        log.info('Subnet %s does not exist.', subnet_name or subnet_id)
        return {'exists': False}