.. versionadded:: 2019.2.0

    Create or update a rule within a specified route filter.

    :param name: The name of the rule to create.

    :param access: The access type of the rule. Valid values are 'Allow' and 'Deny'.

    :param communities: A list of BGP communities to filter on.

    :param route_filter: The name of the route filter containing the rule.

    :param resource_group: The resource group name assigned to the
        route filter.

    CLI Example:

    .. code-block:: bash

        salt-call azurearm_network.route_filter_rule_create_or_update \
                  test-rule allow "['12076:51006']" test-filter testgroup

def route_filter_rule_create_or_update(name, access, communities, route_filter, resource_group, **kwargs):
    '''
    .. versionadded:: 2019.2.0

    Create or update a rule within a specified route filter.

    :param name: The name of the rule to create.

    :param access: The access type of the rule. Valid values are 'Allow' and 'Deny'.

    :param communities: A list of BGP communities to filter on.

    :param route_filter: The name of the route filter containing the rule.

    :param resource_group: The resource group name assigned to the
        route filter.

    CLI Example:

    .. code-block:: bash

        salt-call azurearm_network.route_filter_rule_create_or_update \
                  test-rule allow "['12076:51006']" test-filter testgroup

    '''
    if not isinstance(communities, list):
        log.error(
            'The communities parameter must be a list of strings!'
        )
        return False

    if 'location' not in kwargs:
        rg_props = __salt__['azurearm_resource.resource_group_get'](
            resource_group, **kwargs
        )

        if 'error' in rg_props:
            log.error(
                'Unable to determine location from resource group specified.'
            )
            return False
        kwargs['location'] = rg_props['location']

    netconn = __utils__['azurearm.get_client']('network', **kwargs)

    try:
        rule_model = __utils__['azurearm.create_object_model'](
            'network',
            'RouteFilterRule',
            access=access,
            communities=communities,
            **kwargs
        )
    except TypeError as exc:
        result = {'error': 'The object model could not be built. ({0})'.format(str(exc))}
        return result

    try:
        rule = netconn.route_filter_rules.create_or_update(
            resource_group_name=resource_group,
            route_filter_name=route_filter,
            rule_name=name,
            route_filter_rule_parameters=rule_model
        )
        rule.wait()
        rule_result = rule.result()
        result = rule_result.as_dict()
    except CloudError as exc:
        message = str(exc)
        if kwargs.get('subscription_id') == str(message).strip():
            message = 'Subscription not authorized for this operation!'
        __utils__['azurearm.log_cloud_error']('network', message, **kwargs)
        result = {'error': message}
    except SerializationError as exc:
        result = {'error': 'The object model could not be parsed. ({0})'.format(str(exc))}

    return result