Skip to content

Commit

Permalink
Connection Mode Support for VPN Link Connections (#14183)
Browse files Browse the repository at this point in the history
* Skeleton Code

* Minor fixes

* Adding test

Co-authored-by: Abhishek Shah <[email protected]>
  • Loading branch information
abhi7860 and Abhishek Shah authored Feb 19, 2021
1 parent 1cc74ba commit fa0dbb5
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/Network/Network.Test/ScenarioTests/CortexTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,15 @@ function Test-CortexCRUD
# Create the VpnConnection with site with links
$natRule2 = Get-AzVpnGatewayNatRule -ResourceGroupName $rgName -ParentResourceName $vpnGatewayName -Name "NatRule2"
$vpnSiteLinkConnection1 = New-AzVpnSiteLinkConnection -Name $vpnLink1ConnectionName -VpnSiteLink $vpnSite2.VpnSiteLinks[0] -ConnectionBandwidth 100 -EgressNatRule $natRule2
$vpnSiteLinkConnection2 = New-AzVpnSiteLinkConnection -Name $vpnLink2ConnectionName -VpnSiteLink $vpnSite2.VpnSiteLinks[1] -ConnectionBandwidth 10
$vpnSiteLinkConnection2 = New-AzVpnSiteLinkConnection -Name $vpnLink2ConnectionName -VpnSiteLink $vpnSite2.VpnSiteLinks[1] -ConnectionBandwidth 10 -VpnLinkConnectionMode "Default"

$createdVpnConnection2 = New-AzVpnConnection -ResourceGroupName $rgName -ParentResourceName $vpnGatewayName -Name $vpnConnection2Name -VpnSite $vpnSite2 -VpnSiteLinkConnection @($vpnSiteLinkConnection1, $vpnSiteLinkConnection2)
$vpnConnection2 = Get-AzVpnConnection -ResourceGroupName $rgName -ParentResourceName $vpnGatewayName -Name $vpnConnection2Name
Assert-AreEqual $vpnConnection2Name $vpnConnection2.Name
Assert-AreEqual 2 $vpnConnection2.VpnLinkConnections.Count
Assert-AreEqual 1 $vpnConnection2.VpnLinkConnections[0].EgressNatRules.Count
Assert-AreEqual 0 $vpnConnection2.VpnLinkConnections[0].IngressNatRules.Count
Assert-AreEqual "Default" $vpnConnection2.VpnLinkConnections[1].VpnLinkConnectionMode

$natRule2 = Get-AzVpnGatewayNatRule -ResourceGroupName $rgName -ParentResourceName $vpnGatewayName -Name "NatRule2"
Assert-AreEqual 0 $natRule2.IngressVpnSiteLinkConnections.count
Expand Down
3 changes: 3 additions & 0 deletions src/Network/Network/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
## Upcoming Release
* Updated format list and format table views for Get-AzVirtualNetworkGatewayConnectionIkeSa
* Updated `set-azExpressRouteGateway` to allow parameter -MinScaleUnits without specifying -MaxScaleUnits
* Updated cmdlets to enable setting of VpnLinkConnectionMode on VpnSiteLinkConnections.
- `New-AzVpnSiteLinkConnection`
- `Update-AzVpnConnection`

## Version 4.5.0
* Added new cmdlets for CRUD of VpnGatewayNATRule.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Security;
using Microsoft.WindowsAzure.Commands.Common;
using System.Linq;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;

[Cmdlet(
VerbsCommon.New,
Expand All @@ -30,8 +31,8 @@ public class NewAzVpnSiteLinkConnectionCommand : NetworkBaseCmdlet
public PSVpnSiteLink VpnSiteLink { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "The shared key required to set this link connection up.")]
Mandatory = false,
HelpMessage = "The shared key required to set this link connection up.")]
[ValidateNotNullOrEmpty]
public SecureString SharedKey { get; set; }

Expand All @@ -51,8 +52,8 @@ public class NewAzVpnSiteLinkConnectionCommand : NetworkBaseCmdlet
public PSIpsecPolicy IpSecPolicy { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "Gateway connection protocol:IKEv1/IKEv2")]
Mandatory = false,
HelpMessage = "Gateway connection protocol:IKEv1/IKEv2")]
[ValidateSet(
MNM.VirtualNetworkGatewayConnectionProtocol.IKEv1,
MNM.VirtualNetworkGatewayConnectionProtocol.IKEv2,
Expand Down Expand Up @@ -84,6 +85,12 @@ public class NewAzVpnSiteLinkConnectionCommand : NetworkBaseCmdlet
HelpMessage = "The list of egress NAT rules that are associated with this link Connection.")]
public PSResourceId[] EgressNatRule { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "The connection mode for this link connection.")]
[PSArgumentCompleter("Default", "ResponderOnly", "InitiatorOnly")]
public string VpnLinkConnectionMode { get; set; }

public override void Execute()
{
base.Execute();
Expand All @@ -96,7 +103,8 @@ public override void Execute()
UsePolicyBasedTrafficSelectors = this.UsePolicyBasedTrafficSelectors.IsPresent,
RoutingWeight = Convert.ToInt32(this.RoutingWeight),
IngressNatRules = IngressNatRule?.ToList(),
EgressNatRules = EgressNatRule?.ToList()
EgressNatRules = EgressNatRule?.ToList(),
VpnLinkConnectionMode = this.VpnLinkConnectionMode
};

if (this.VpnSiteLink == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ public class UpdateAzureRmVpnConnectionCommand : VpnConnectionBaseCmdlet
HelpMessage = "The routing configuration for this vpn connection")]
public PSRoutingConfiguration RoutingConfiguration { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "The connection mode for the link connections.")]
[PSArgumentCompleter("Default", "ResponderOnly", "InitiatorOnly")]
public string VpnLinkConnectionMode { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "Run cmdlet in the background")]
Expand Down Expand Up @@ -231,6 +237,14 @@ public override void Execute()
vpnConnectionToModify.RoutingConfiguration = RoutingConfiguration;
}

if(!String.IsNullOrEmpty(this.VpnLinkConnectionMode))
{
foreach(var vpnSiteLinkConnection in vpnConnectionToModify.VpnLinkConnections)
{
vpnSiteLinkConnection.VpnLinkConnectionMode = this.VpnLinkConnectionMode;
}
}

ConfirmAction(
Properties.Resources.SettingResourceMessage,
this.Name,
Expand Down
3 changes: 3 additions & 0 deletions src/Network/Network/Models/Cortex/PSVpnSiteLinkConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class PSVpnSiteLinkConnection : PSChildResource
[Ps1Xml(Label = "EgressNatRules", Target = ViewControl.Table)]
public List<PSResourceId> EgressNatRules { get; set; }

[Ps1Xml(Label = "VpnLinkConnectionMode", Target = ViewControl.Table)]
public string VpnLinkConnectionMode { get; set; }

[JsonIgnore]
public string IngressNatRulesText
{
Expand Down
15 changes: 14 additions & 1 deletion src/Network/Network/help/New-AzVpnSiteLinkConnection.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Creates an Azure VpnSiteLinkConnection object.
New-AzVpnSiteLinkConnection -Name <String> -VpnSiteLink <PSVpnSiteLink> [-SharedKey <SecureString>]
[-ConnectionBandwidth <UInt32>] [-RoutingWeight <UInt32>] [-IpSecPolicy <PSIpsecPolicy>]
[-VpnConnectionProtocolType <String>] [-EnableBgp] [-UseLocalAzureIpAddress] [-UsePolicyBasedTrafficSelectors]
[-IngressNatRule <PSResourceId[]>] [-EgressNatRule <PSResourceId[]>]
[-IngressNatRule <PSResourceId[]>] [-EgressNatRule <PSResourceId[]>] [-VpnLinkConnectionMode <String>]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

Expand Down Expand Up @@ -233,6 +233,19 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -VpnLinkConnectionMode
The connection mode for this link connection.
```yaml
Type: System.String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: Default
Accept wildcard characters: False
```
### -VpnSiteLink
The vpn site link object to connect to.
Expand Down
19 changes: 16 additions & 3 deletions src/Network/Network/help/Update-AzVpnConnection.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Updates a VPN connection.
Update-AzVpnConnection -ResourceGroupName <String> -ParentResourceName <String> -Name <String>
[-SharedKey <SecureString>] [-ConnectionBandwidthInMbps <UInt32>] [-IpSecPolicy <PSIpsecPolicy>]
[-EnableBgp <Boolean>] [-UseLocalAzureIpAddress <Boolean>] [-UsePolicyBasedTrafficSelectors <Boolean>]
[-VpnSiteLinkConnection <PSVpnSiteLinkConnection[]>] [-EnableInternetSecurity <Boolean>] [-RoutingConfiguration <PSRoutingConfiguration>] [-AsJob]
[-VpnSiteLinkConnection <PSVpnSiteLinkConnection[]>] [-EnableInternetSecurity <Boolean>] [-RoutingConfiguration <PSRoutingConfiguration>] [-VpnLinkConnectionMode <String>] [-AsJob]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

Expand All @@ -26,7 +26,7 @@ Update-AzVpnConnection -ResourceGroupName <String> -ParentResourceName <String>
Update-AzVpnConnection -ResourceId <String> [-SharedKey <SecureString>] [-ConnectionBandwidthInMbps <UInt32>]
[-IpSecPolicy <PSIpsecPolicy>] [-EnableBgp <Boolean>] [-UseLocalAzureIpAddress <Boolean>]
[-UsePolicyBasedTrafficSelectors <Boolean>] [-VpnSiteLinkConnection <PSVpnSiteLinkConnection[]>]
[-EnableInternetSecurity <Boolean>] [-RoutingConfiguration <PSRoutingConfiguration>] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[-EnableInternetSecurity <Boolean>] [-RoutingConfiguration <PSRoutingConfiguration>] [-VpnLinkConnectionMode <String>] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[<CommonParameters>]
```

Expand All @@ -35,7 +35,7 @@ Update-AzVpnConnection -ResourceId <String> [-SharedKey <SecureString>] [-Connec
Update-AzVpnConnection -InputObject <PSVpnConnection> [-SharedKey <SecureString>]
[-ConnectionBandwidthInMbps <UInt32>] [-IpSecPolicy <PSIpsecPolicy>] [-EnableBgp <Boolean>]
[-UseLocalAzureIpAddress <Boolean>] [-UsePolicyBasedTrafficSelectors <Boolean>]
[-VpnSiteLinkConnection <PSVpnSiteLinkConnection[]>] [-EnableInternetSecurity <Boolean>] [-RoutingConfiguration <PSRoutingConfiguration>] [-AsJob]
[-VpnSiteLinkConnection <PSVpnSiteLinkConnection[]>] [-EnableInternetSecurity <Boolean>] [-RoutingConfiguration <PSRoutingConfiguration>] [-VpnLinkConnectionMode <String>] [-AsJob]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

Expand Down Expand Up @@ -397,6 +397,19 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -VpnLinkConnectionMode
The connection mode for all VpnSiteLinkConnections in this VpnConnection
```yaml
Type: System.String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: Default
Accept wildcard characters: False
```
### -Confirm
Prompts you for confirmation before running the cmdlet.
Expand Down

0 comments on commit fa0dbb5

Please sign in to comment.