.. versionadded:: 2019.2.0

    Create or update an availability set.

    :param name: The availability set to create.

    :param resource_group: The resource group name assigned to the
        availability set.

    CLI Example:

    .. code-block:: bash

        salt-call azurearm_compute.availability_set_create_or_update testset testgroup

def availability_set_create_or_update(name, resource_group, **kwargs):  # pylint: disable=invalid-name
    '''
    .. versionadded:: 2019.2.0

    Create or update an availability set.

    :param name: The availability set to create.

    :param resource_group: The resource group name assigned to the
        availability set.

    CLI Example:

    .. code-block:: bash

        salt-call azurearm_compute.availability_set_create_or_update testset testgroup

    '''
    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']

    compconn = __utils__['azurearm.get_client']('compute', **kwargs)

    # Use VM names to link to the IDs of existing VMs.
    if isinstance(kwargs.get('virtual_machines'), list):
        vm_list = []
        for vm_name in kwargs.get('virtual_machines'):
            vm_instance = __salt__['azurearm_compute.virtual_machine_get'](
                name=vm_name,
                resource_group=resource_group,
                **kwargs
            )
            if 'error' not in vm_instance:
                vm_list.append({'id': str(vm_instance['id'])})
        kwargs['virtual_machines'] = vm_list

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

    try:
        av_set = compconn.availability_sets.create_or_update(
            resource_group_name=resource_group,
            availability_set_name=name,
            parameters=setmodel
        )
        result = av_set.as_dict()

    except CloudError as exc:
        __utils__['azurearm.log_cloud_error']('compute', str(exc), **kwargs)
        result = {'error': str(exc)}
    except SerializationError as exc:
        result = {'error': 'The object model could not be parsed. ({0})'.format(str(exc))}

    return result