Ensures usage plan identified by name is no longer present

    .. versionadded:: 2017.7.0

    name
        name of the state

    plan_name
        name of the plan to remove

    .. code-block:: yaml

        usage plan absent:
          boto_apigateway.usage_plan_absent:
            - plan_name: my_usage_plan
            - profile: my_profile

def usage_plan_absent(name, plan_name, region=None, key=None, keyid=None, profile=None):
    '''
    Ensures usage plan identified by name is no longer present

    .. versionadded:: 2017.7.0

    name
        name of the state

    plan_name
        name of the plan to remove

    .. code-block:: yaml

        usage plan absent:
          boto_apigateway.usage_plan_absent:
            - plan_name: my_usage_plan
            - profile: my_profile

    '''
    ret = {'name': name,
           'result': True,
           'comment': '',
           'changes': {}
           }

    try:
        common_args = dict([('region', region),
                            ('key', key),
                            ('keyid', keyid),
                            ('profile', profile)])

        existing = __salt__['boto_apigateway.describe_usage_plans'](name=plan_name, **common_args)
        if 'error' in existing:
            ret['result'] = False
            ret['comment'] = 'Failed to describe existing usage plans'
            return ret

        if not existing['plans']:
            ret['comment'] = 'Usage plan {0} does not exist already'.format(plan_name)
            return ret

        if __opts__['test']:
            ret['comment'] = 'Usage plan {0} exists and would be deleted'.format(plan_name)
            ret['result'] = None
            return ret

        plan_id = existing['plans'][0]['id']
        result = __salt__['boto_apigateway.delete_usage_plan'](plan_id, **common_args)

        if 'error' in result:
            ret['result'] = False
            ret['comment'] = 'Failed to delete usage plan {0}, {1}'.format(plan_name, result)
            return ret

        ret['comment'] = 'Usage plan {0} has been deleted'.format(plan_name)
        ret['changes']['old'] = {'plan': existing['plans'][0]}
        ret['changes']['new'] = {'plan': None}

    except (ValueError, IOError) as e:
        ret['result'] = False
        ret['comment'] = '{0}'.format(e.args)

    return ret