.. versionadded:: 2019.2.0

    Create or update a network interface within a specified resource group.

    :param name: The name of the network interface to create.

    :param ip_configurations: A list of dictionaries representing valid
        NetworkInterfaceIPConfiguration objects. The 'name' key is required at
        minimum. At least one IP Configuration must be present.

    :param subnet: The name of the subnet assigned to the network interface.

    :param virtual_network: The name of the virtual network assigned to the subnet.

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

    CLI Example:

    .. code-block:: bash

        salt-call azurearm_network.network_interface_create_or_update test-iface0 [{'name': 'testipconfig1'}] \
                  testsubnet testnet testgroup

def network_interface_create_or_update(name, ip_configurations, subnet, virtual_network,
                                       resource_group, **kwargs):
    '''
    .. versionadded:: 2019.2.0

    Create or update a network interface within a specified resource group.

    :param name: The name of the network interface to create.

    :param ip_configurations: A list of dictionaries representing valid
        NetworkInterfaceIPConfiguration objects. The 'name' key is required at
        minimum. At least one IP Configuration must be present.

    :param subnet: The name of the subnet assigned to the network interface.

    :param virtual_network: The name of the virtual network assigned to the subnet.

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

    CLI Example:

    .. code-block:: bash

        salt-call azurearm_network.network_interface_create_or_update test-iface0 [{'name': 'testipconfig1'}] \
                  testsubnet testnet 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']

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

    # Use NSG name to link to the ID of an existing NSG.
    if kwargs.get('network_security_group'):
        nsg = network_security_group_get(
            name=kwargs['network_security_group'],
            resource_group=resource_group,
            **kwargs
        )
        if 'error' not in nsg:
            kwargs['network_security_group'] = {'id': str(nsg['id'])}

    # Use VM name to link to the ID of an existing VM.
    if kwargs.get('virtual_machine'):
        vm_instance = __salt__['azurearm_compute.virtual_machine_get'](
            name=kwargs['virtual_machine'],
            resource_group=resource_group,
            **kwargs
        )
        if 'error' not in vm_instance:
            kwargs['virtual_machine'] = {'id': str(vm_instance['id'])}

    # Loop through IP Configurations and build each dictionary to pass to model creation.
    if isinstance(ip_configurations, list):
        subnet = subnet_get(
            name=subnet,
            virtual_network=virtual_network,
            resource_group=resource_group,
            **kwargs
        )
        if 'error' not in subnet:
            subnet = {'id': str(subnet['id'])}
            for ipconfig in ip_configurations:
                if 'name' in ipconfig:
                    ipconfig['subnet'] = subnet
                    if isinstance(ipconfig.get('application_gateway_backend_address_pools'), list):
                        # TODO: Add ID lookup for referenced object names
                        pass
                    if isinstance(ipconfig.get('load_balancer_backend_address_pools'), list):
                        # TODO: Add ID lookup for referenced object names
                        pass
                    if isinstance(ipconfig.get('load_balancer_inbound_nat_rules'), list):
                        # TODO: Add ID lookup for referenced object names
                        pass
                    if ipconfig.get('public_ip_address'):
                        pub_ip = public_ip_address_get(
                            name=ipconfig['public_ip_address'],
                            resource_group=resource_group,
                            **kwargs
                        )
                        if 'error' not in pub_ip:
                            ipconfig['public_ip_address'] = {'id': str(pub_ip['id'])}

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

    try:
        interface = netconn.network_interfaces.create_or_update(
            resource_group_name=resource_group,
            network_interface_name=name,
            parameters=nicmodel
        )
        interface.wait()
        nic_result = interface.result()
        result = nic_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