# Buggy code
def build_vpn_connection_resource(
    cmd,
    name,
    location,
    tags,
    gateway1,
    gateway2,
    vpn_type,
    authorization_key,
    enable_bgp,
    routing_weight,
    shared_key,
    use_policy_based_traffic_selectors,
):
    vpn_properties = {
        "virtualNetworkGateway1": {"id": gateway1},
        "authorizationKey": authorization_key,
        "enableBgp": enable_bgp,
        "connectionType": vpn_type,
        "routingWeight": routing_weight,
    }
    if cmd.supported_api_version(min_api="2017-03-01"):
        vpn_properties["usePolicyBasedTrafficSelectors"] = (
            use_policy_based_traffic_selectors
        )

    # add scenario specific properties
    if vpn_type == "IPSec":
        vpn_properties.update(
            {"localNetworkGateway2": {"id": gateway2}, "sharedKey": shared_key}
        )
    elif vpn_type == "Vnet2Vnet":
        vpn_properties.update(
            {"virtualNetworkGateway2": {"id": gateway2}, "sharedKey": shared_key}
        )
    elif vpn_type == "ExpressRoute":
        vpn_properties.update({"peer": {"id": gateway2}})

    vpn_connection = {
        "type": "Microsoft.Network/connections",
        "name": name,
        "location": location,
        "tags": tags,
        "apiVersion": "2015-06-15",
        "dependsOn": [],
        "properties": vpn_properties if vpn_type != "VpnClient" else {},
    }
    return vpn_connection


# Traceback (FileNotFoundError)
(env) C:\Users\trpresco\Documents\github\azure-cli>run_tests --module network --parallel
The run_tests command is going to be replaced by 'azdev test' command.

Traceback (most recent call last):
File "C:\Users\trpresco\Documents\github\azure-cli\env\Scripts\run_tests-script.py", line 11, in <module>
load_entry_point('azure-cli-dev-tools', 'console_scripts', 'run_tests')()
File "c:\users\trpresco\documents\github\azure-cli\tools\automation\tests\__init__.py", line 79, in legacy_entry_point
args.func(args)
File "c:\users\trpresco\documents\github\azure-cli\tools\automation\tests\__init__.py", line 20, in execute
current_profile = check_output(shlex.split('az cloud show --query profile -otsv')).decode('utf-8').strip()
File "C:\Users\trpresco\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 336, in check_output
**kwargs).stdout
File "C:\Users\trpresco\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 403, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\trpresco\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\trpresco\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 990, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

# Fixed code
def build_vpn_connection_resource(
    cmd,
    name,
    location,
    tags,
    gateway1,
    gateway2,
    vpn_type,
    authorization_key,
    enable_bgp,
    routing_weight,
    shared_key,
    use_policy_based_traffic_selectors,
):
    vpn_properties = {
        "virtualNetworkGateway1": {"id": gateway1},
        "enableBgp": enable_bgp,
        "connectionType": vpn_type,
        "routingWeight": routing_weight,
    }
    if authorization_key:
        vpn_properties["authorizationKey"] = "[parameters('authorizationKey')]"
    if cmd.supported_api_version(min_api="2017-03-01"):
        vpn_properties["usePolicyBasedTrafficSelectors"] = (
            use_policy_based_traffic_selectors
        )

    # add scenario specific properties
    if shared_key:
        shared_key = "[parameters('sharedKey')]"
    if vpn_type == "IPSec":
        vpn_properties.update(
            {"localNetworkGateway2": {"id": gateway2}, "sharedKey": shared_key}
        )
    elif vpn_type == "Vnet2Vnet":
        vpn_properties.update(
            {"virtualNetworkGateway2": {"id": gateway2}, "sharedKey": shared_key}
        )
    elif vpn_type == "ExpressRoute":
        vpn_properties.update({"peer": {"id": gateway2}})

    vpn_connection = {
        "type": "Microsoft.Network/connections",
        "name": name,
        "location": location,
        "tags": tags,
        "apiVersion": "2015-06-15",
        "dependsOn": [],
        "properties": vpn_properties if vpn_type != "VpnClient" else {},
    }
    return vpn_connection