Ensure a distribution with the given Name tag does not exist.

    Note that CloudFront does not allow directly deleting an enabled
    Distribution. If such is requested, Salt will attempt to first update the
    distribution's status to Disabled, and once that returns success, to then
    delete the resource. THIS CAN TAKE SOME TIME, so be patient :)

    name (string)
        Name of the state definition.

    Name (string)
        Name of the CloudFront distribution to be managed. If not provided, the
        value of ``name`` will be used as a default. The purpose of this
        parameter is only to resolve it to a Resource ID, so be aware that an
        explicit value for ``Id`` below will override any value provided, or
        defaulted, here.

    Id (string)
        The Resource ID of a CloudFront distribution to be managed.

    region (string)
        Region to connect to

    key (string)
        Secret key to use

    keyid (string)
        Access key to use

    profile (dict or string)
        Dict, or pillar key pointing to a dict, containing AWS region/key/keyid.

    Example:

    .. code-block:: yaml

        Ensure a distribution named my_distribution is gone:
          boto_cloudfront.distribution_absent:
          - Name: my_distribution

def distribution_absent(name, region=None, key=None, keyid=None, profile=None, **kwargs):
    '''
    Ensure a distribution with the given Name tag does not exist.

    Note that CloudFront does not allow directly deleting an enabled
    Distribution. If such is requested, Salt will attempt to first update the
    distribution's status to Disabled, and once that returns success, to then
    delete the resource. THIS CAN TAKE SOME TIME, so be patient :)

    name (string)
        Name of the state definition.

    Name (string)
        Name of the CloudFront distribution to be managed. If not provided, the
        value of ``name`` will be used as a default. The purpose of this
        parameter is only to resolve it to a Resource ID, so be aware that an
        explicit value for ``Id`` below will override any value provided, or
        defaulted, here.

    Id (string)
        The Resource ID of a CloudFront distribution to be managed.

    region (string)
        Region to connect to

    key (string)
        Secret key to use

    keyid (string)
        Access key to use

    profile (dict or string)
        Dict, or pillar key pointing to a dict, containing AWS region/key/keyid.

    Example:

    .. code-block:: yaml

        Ensure a distribution named my_distribution is gone:
          boto_cloudfront.distribution_absent:
          - Name: my_distribution

    '''
    Name = kwargs['Name'] if 'Name' in kwargs else name
    Id = kwargs.get('Id')
    ref = kwargs['Id'] if 'Id' in kwargs else Name
    ret = {'name': Id if Id else Name, 'comment': '', 'changes': {}, 'result': True}
    authargs = {'region': region, 'key': key, 'keyid': keyid, 'profile': profile}
    if not Id:
        res = __salt__['boto_cloudfront.get_distributions_by_comment'](Comment=Name, **authargs)
        if res is None:
            msg = 'Error dereferencing CloudFront distribution `{}` to a Resource ID.'.format(Name)
            log.error(msg)
            ret['comment'] = msg
            ret['result'] = False
            return ret
        if len(res) > 1:
            msg = ('Multiple CloudFront distibutions matched `{}`, no way to know which to'
                   ' delete.`.'.format(Name))
            log.error(msg)
            ret['comment'] = msg
            ret['result'] = False
            return ret
        if not res:
            msg = 'CloudFront Distribution `{}` already absent.'.format(Name)
            log.info(msg)
            ret['comment'] = msg
            ret['result'] = True
            return ret
        Id = res[0]['Id']

    if not __salt__['boto_cloudfront.distribution_exists'](Id=Id, **authargs):
        msg = 'CloudFront distribution `{}` already absent.'.format(ref)
        log.info(msg)
        ret['comment'] = msg
        return ret

    old = __salt__['boto_cloudfront.get_distribution_v2'](Id=Id, **authargs)
    if old is None:
        ret['result'] = False
        msg = 'Error getting state of CloudFront distribution `{}`.'.format(ref)
        log.error(msg)
        ret['comment'] = msg
        return ret
    currETag = old['ETag']

    Enabled = old['DistributionConfig']['Enabled']
    if __opts__['test']:
        ret['result'] = None
        ret['comment'] = 'CloudFront distribution `{}` would be {}deleted.'.format(ref,
                ('disabled and ' if Enabled else ''))
        ret['pchanges'] = {'old': old, 'new': None}
        return ret

    comments = []
    if Enabled:
        disabled = __salt__['boto_cloudfront.disable_distribution'](Id=Id, **authargs)
        if disabled is None:
            ret['result'] = False
            msg = 'Error disabling CloudFront distribution `{}`'.format(ref)
            log.error(msg)
            ret['comment'] = msg
            return ret
        comments += ['CloudFront distribution `{}` disabled.'.format(ref)]
        currETag = disabled['ETag']
    deleted = __salt__['boto_cloudfront.delete_distribution'](Id=Id, IfMatch=currETag, **authargs)
    if deleted is False:
        ret['result'] = False
        msg = 'Error deleting CloudFront distribution `{}`'.format(ref)
        comments += [msg]
        log.error(msg)
        ret['comment'] = '  '.join(comments)
        return ret
    msg = 'CloudFront distribution `{}` deleted.'.format(ref)
    comments += [msg]
    log.info(msg)
    ret['comment'] = '  '.join(comments)
    ret['changes'] = {'old': old, 'new': None}
    return ret