# Buggy code
def create_vnet_peering(
    cmd,
    resource_group_name,
    virtual_network_name,
    virtual_network_peering_name,
    remote_virtual_network,
    allow_virtual_network_access=False,
    allow_forwarded_traffic=False,
    allow_gateway_transit=False,
    use_remote_gateways=False,
):
    SubResource, VirtualNetworkPeering = cmd.get_models(
        "SubResource", "VirtualNetworkPeering"
    )
    peering = VirtualNetworkPeering(
        id=resource_id(
            subscription=get_subscription_id(cmd.cli_ctx),
            resource_group=resource_group_name,
            namespace="Microsoft.Network",
            type="virtualNetworks",
            name=virtual_network_name,
        ),
        name=virtual_network_peering_name,
        remote_virtual_network=SubResource(id=remote_virtual_network),
        allow_virtual_network_access=allow_virtual_network_access,
        allow_gateway_transit=allow_gateway_transit,
        allow_forwarded_traffic=allow_forwarded_traffic,
        use_remote_gateways=use_remote_gateways,
    )
    aux_subscription = parse_resource_id(remote_virtual_network)["subscription"]
    ncf = network_client_factory(cmd.cli_ctx, aux_subscriptions=[aux_subscription])
    return ncf.virtual_network_peerings.create_or_update(
        resource_group_name, virtual_network_name, virtual_network_peering_name, peering
    )


# Traceback (KeyError)
'subscription'
Traceback (most recent call last):
File "/usr/local/Cellar/azure-cli/2.0.43/libexec/lib/python3.7/site-packages/knack/cli.py", line 197, in invoke
cmd_result = self.invocation.execute(args)
File "/usr/local/Cellar/azure-cli/2.0.43/libexec/lib/python3.7/site-packages/azure/cli/core/commands/__init__.py", line 369, in execute
six.reraise(*sys.exc_info())
File "/usr/local/Cellar/azure-cli/2.0.43/libexec/lib/python3.7/site-packages/six.py", line 693, in reraise
raise value
File "/usr/local/Cellar/azure-cli/2.0.43/libexec/lib/python3.7/site-packages/azure/cli/core/commands/__init__.py", line 343, in execute
result = cmd(params)
File "/usr/local/Cellar/azure-cli/2.0.43/libexec/lib/python3.7/site-packages/azure/cli/core/commands/__init__.py", line 182, in __call__
return self.handler(*args, **kwargs)
File "/usr/local/Cellar/azure-cli/2.0.43/libexec/lib/python3.7/site-packages/azure/cli/core/__init__.py", line 436, in default_command_handler
result = op(**command_args)
File "/usr/local/Cellar/azure-cli/2.0.43/libexec/lib/python3.7/site-packages/azure/cli/command_modules/network/custom.py", line 2938, in create_vnet_peering
aux_subscription = parse_resource_id(remote_virtual_network)['subscription']
KeyError: 'subscription'

# Fixed code
def create_vnet_peering(
    cmd,
    resource_group_name,
    virtual_network_name,
    virtual_network_peering_name,
    remote_virtual_network,
    allow_virtual_network_access=False,
    allow_forwarded_traffic=False,
    allow_gateway_transit=False,
    use_remote_gateways=False,
):
    if not is_valid_resource_id(remote_virtual_network):
        remote_virtual_network = resource_id(
            subscription=get_subscription_id(cmd.cli_ctx),
            resource_group=resource_group_name,
            namespace="Microsoft.Network",
            type="virtualNetworks",
            name=remote_virtual_network,
        )
    SubResource, VirtualNetworkPeering = cmd.get_models(
        "SubResource", "VirtualNetworkPeering"
    )
    peering = VirtualNetworkPeering(
        id=resource_id(
            subscription=get_subscription_id(cmd.cli_ctx),
            resource_group=resource_group_name,
            namespace="Microsoft.Network",
            type="virtualNetworks",
            name=virtual_network_name,
        ),
        name=virtual_network_peering_name,
        remote_virtual_network=SubResource(id=remote_virtual_network),
        allow_virtual_network_access=allow_virtual_network_access,
        allow_gateway_transit=allow_gateway_transit,
        allow_forwarded_traffic=allow_forwarded_traffic,
        use_remote_gateways=use_remote_gateways,
    )
    aux_subscription = parse_resource_id(remote_virtual_network)["subscription"]
    ncf = network_client_factory(cmd.cli_ctx, aux_subscriptions=[aux_subscription])
    return ncf.virtual_network_peerings.create_or_update(
        resource_group_name, virtual_network_name, virtual_network_peering_name, peering
    )