.. versionadded:: 2019.2.0

    Create or update a virtual network.

    :param name: The name assigned to the virtual network being
        created or updated.

    :param address_prefixes: A list of CIDR blocks which can be used
        by subnets within the virtual network.

    :param resource_group: The resource group name assigned to the
        virtual network.

    CLI Example:

    .. code-block:: bash

        salt-call azurearm_network.virtual_network_create_or_update \
                  testnet ['10.0.0.0/16'] testgroup

def virtual_network_create_or_update(name,
                                     address_prefixes,
                                     resource_group,
                                     **kwargs):
    '''
    .. versionadded:: 2019.2.0

    Create or update a virtual network.

    :param name: The name assigned to the virtual network being
        created or updated.

    :param address_prefixes: A list of CIDR blocks which can be used
        by subnets within the virtual network.

    :param resource_group: The resource group name assigned to the
        virtual network.

    CLI Example:

    .. code-block:: bash

        salt-call azurearm_network.virtual_network_create_or_update \
                  testnet ['10.0.0.0/16'] 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']

    if not isinstance(address_prefixes, list):
        log.error(
            'Address prefixes must be specified as a list!'
        )
        return False

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

    address_space = {'address_prefixes': address_prefixes}
    dhcp_options = {'dns_servers': kwargs.get('dns_servers')}

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

    try:
        vnet = netconn.virtual_networks.create_or_update(
            virtual_network_name=name,
            resource_group_name=resource_group,
            parameters=vnetmodel
        )
        vnet.wait()
        vnet_result = vnet.result()
        result = vnet_result.as_dict()
    except CloudError as exc:
        __utils__['azurearm.log_cloud_error']('network', 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