Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtual Network Gateway NAT feature changes #14685

Merged
merged 17 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Batch/Batch.Test/Batch.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PackageReference Include="Microsoft.Azure.Batch" Version="13.0.0" />
<PackageReference Include="Microsoft.Azure.Management.Batch" Version="11.0.0" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.0" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="323.1255.27827" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="330.2247.36274" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.CognitiveServices" Version="7.4.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="323.1255.27827" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="330.2247.36274" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Compute/Compute.Test/Compute.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="Microsoft.Azure.Graph.RBAC" Version="3.4.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="44.0.0" />
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.1.0-preview.2" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="323.1255.27827" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="330.2247.36274" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.ContainerRegistry" Version="4.0.0" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="323.1255.27827" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="330.2247.36274" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.6.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.6.0">
<NoWarn>NU1608</NoWarn>
Expand Down
2 changes: 1 addition & 1 deletion src/CosmosDB/CosmosDB.Test/CosmosDB.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</PropertyGroup>
<Import Project="$(MSBuildThisFileDirectory)..\..\Az.Test.props" />
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Network" Version="323.1255.27827" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="330.2247.36274" />
<PackageReference Include="Microsoft.Azure.Management.CosmosDB" Version="2.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.DataLake.Store" Version="2.4.2-preview" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="323.1255.27827" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="330.2247.36274" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Dns/Dns.Test/Dns.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Dns" Version="3.0.1" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="323.1255.27827" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="330.2247.36274" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/HDInsight/HDInsight.Test/HDInsight.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="Microsoft.Azure.Management.HDInsight.Job" Version="2.0.7" />
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.1.0-preview.2" />
<PackageReference Include="Microsoft.Azure.Management.ManagedServiceIdentity" Version="0.11.0" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="323.1255.27827" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="330.2247.36274" />
<PackageReference Include="Microsoft.Azure.Management.OperationalInsights" Version="0.21.0-preview" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/HPCCache/HPCCache.Test/HPCCache.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Authorization" Version="2.11.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="14.5.0" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="323.1255.27827" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="330.2247.36274" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/KeyVault/KeyVault.Test/KeyVault.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.1" />
<PackageReference Include="Microsoft.Azure.KeyVault.WebKey" Version="3.0.1" />
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.1.0-preview.2" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="323.1255.27827" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="330.2247.36274" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Monitor/Monitor.Test/Monitor.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Monitor" Version="0.25.3-preview" />
<PackageReference Include="Microsoft.Azure.Management.ApplicationInsights" Version="0.3.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="323.1255.27827" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="330.2247.36274" />
<PackageReference Include="Microsoft.Azure.Management.OperationalInsights" Version="0.21.0-preview" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/NetAppFiles/NetAppFiles.Test/NetAppFiles.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.NetApp" Version="1.10.0" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="323.1255.27827" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="330.2247.36274" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Network/Network.Test/Network.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Graph.RBAC" Version="3.4.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="323.1255.27827" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="330.2247.36274" />
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.5" />
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.1.0-preview.2" />
<PackageReference Include="Microsoft.Azure.Insights" Version="0.16.0-preview" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ function Test-VirtualNetworkGatewayConnectionCRUD
$rglocation = Get-ProviderLocation ResourceManagement
$resourceTypeParent = "Microsoft.Network/connections"
$location = Get-ProviderLocation $resourceTypeParent

try
{
# Create the resource group
Expand All @@ -420,11 +420,13 @@ function Test-VirtualNetworkGatewayConnectionCRUD

# Create VirtualNetworkGateway
$vnetIpConfig = New-AzVirtualNetworkGatewayIpConfig -Name $vnetGatewayConfigName -PublicIpAddress $publicip -Subnet $subnet

$actual = New-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -IpConfigurations $vnetIpConfig -GatewayType Vpn -VpnType RouteBased -EnableBgp $false
$natRule1 = New-AzVirtualNetworkGatewayNatRule -Name "natRule1" -Type "Static" -Mode "IngressSnat" -InternalMapping @("25.0.0.0/16") -ExternalMapping @("30.0.0.0/16")
$natRule2 = New-AzVirtualNetworkGatewayNatRule -Name "natRule2" -Type "Static" -Mode "EgressSnat" -InternalMapping @("20.0.0.0/16") -ExternalMapping @("50.0.0.0/16")
$actual = New-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -IpConfigurations $vnetIpConfig -GatewayType Vpn -VpnType RouteBased -EnableBgp $false -GatewaySku VpnGw2 -NatRule $natRule1,$natRule2
$vnetGateway = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname
Assert-AreEqual $vnetGateway.ResourceGroupName $actual.ResourceGroupName
Assert-AreEqual $vnetGateway.Name $actual.Name
Assert-AreEqual $vnetGateway.Name $actual.Name
Assert-AreEqual 2 @($vnetGateway.NatRules).Count
#Assert-AreEqual "Vpn" $expected.GatewayType
#Assert-AreEqual "RouteBased" $expected.VpnType

Expand All @@ -437,8 +439,12 @@ function Test-VirtualNetworkGatewayConnectionCRUD
Assert-AreEqual "192.168.0.0/16" $localnetGateway.LocalNetworkAddressSpace.AddressPrefixes[0]
$localnetGateway.Location = $location

# Get VirtualNetworkGatewayNatRules
$natRule1 = Get-AzVirtualNetworkGatewayNatRule -Name "natRule1" -ResourceGroupName $rgname -ParentResourceName $rname
$natRule2 = Get-AzVirtualNetworkGatewayNatRule -Name "natRule2" -ResourceGroupName $rgname -ParentResourceName $rname

# Create & Get VirtualNetworkGatewayConnection
$actual = New-AzVirtualNetworkGatewayConnection -ResourceGroupName $rgname -name $vnetConnectionName -location $location -VirtualNetworkGateway1 $vnetGateway -LocalNetworkGateway2 $localnetGateway -ConnectionType IPsec -RoutingWeight 3 -SharedKey abc -ConnectionProtocol IKEv1 -ConnectionMode "Default"
$actual = New-AzVirtualNetworkGatewayConnection -ResourceGroupName $rgname -name $vnetConnectionName -location $location -VirtualNetworkGateway1 $vnetGateway -LocalNetworkGateway2 $localnetGateway -ConnectionType IPsec -RoutingWeight 3 -SharedKey abc -ConnectionProtocol IKEv1 -ConnectionMode "Default" -IngressNatRule $natRule1 -EgressNatRule $natRule2
$expected = Get-AzVirtualNetworkGatewayConnection -ResourceGroupName $rgname -name $vnetConnectionName
Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName
Assert-AreEqual $expected.Name $actual.Name
Expand All @@ -447,6 +453,8 @@ function Test-VirtualNetworkGatewayConnectionCRUD
Assert-AreEqual "IKEv1" $expected.ConnectionProtocol
#Assert-AreEqual "abc" $expected.SharedKey
Assert-AreEqual $expected.ConnectionMode $actual.ConnectionMode
Assert-AreEqual 1 @($expected.IngressNatRules).Count
Assert-AreEqual 1 @($expected.EgressNatRules).Count

# List VirtualNetworkGatewayConnections
$list = Get-AzVirtualNetworkGatewayConnection -ResourceGroupName $rgname
Expand All @@ -467,11 +475,12 @@ function Test-VirtualNetworkGatewayConnectionCRUD
$expected.ConnectionMode = "ResponderOnly"

# Set/Update VirtualNetworkGatewayConnection Tags
$actual = Set-AzVirtualNetworkGatewayConnection -VirtualNetworkGatewayConnection $expected -Tag @{ testtagKey="SomeTagKey"; testtagValue="SomeKeyValue" } -Force
$actual = Set-AzVirtualNetworkGatewayConnection -VirtualNetworkGatewayConnection $expected -IngressNatRule @() -Tag @{ testtagKey="SomeTagKey"; testtagValue="SomeKeyValue" } -Force
$expected = Get-AzVirtualNetworkGatewayConnection -ResourceGroupName $rgname -name $vnetConnectionName
Assert-AreEqual 2 $expected.Tag.Count
Assert-AreEqual $true $expected.Tag.Contains("testtagKey")
Assert-AreEqual $expected.ConnectionMode $actual.ConnectionMode
Assert-AreEqual 0 $expected.IngressNatRules.Count

# Delete VirtualNetworkGatewayConnection
$delete = Remove-AzVirtualNetworkGatewayConnection -ResourceGroupName $actual.ResourceGroupName -name $vnetConnectionName -PassThru -Force
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,13 @@ public void TestDisconnectVirtualNetworkGatewayVpnConnection()
{
TestRunner.RunTestScript("Test-DisconnectVNGVpnConnection");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.brooklynft_subset2)]
public void TestVirtualNetworkGatewayNatRuleCRUD()
{
TestRunner.RunTestScript("Test-VirtualNetworkGatewayNatRuleCRUD");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1241,3 +1241,85 @@ function Test-DisconnectVNGVpnConnection
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Virtual network gateway NatRule tests
#>
function Test-VirtualNetworkGatewayNatRuleCRUD
{
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$domainNameLabel = Get-ResourceName
$vnetName = Get-ResourceName
$publicIpName = Get-ResourceName
$vnetGatewayConfigName = Get-ResourceName
$rglocation = Get-ProviderLocation ResourceManagement
$resourceTypeParent = "Microsoft.Network/virtualNetworkGateways"
$location = Get-ProviderLocation $resourceTypeParent

try
{
# Create the resource group
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }

# Create the Virtual Network
$subnet = New-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -AddressPrefix 10.0.0.0/24
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
$subnet = Get-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -VirtualNetwork $vnet

# Create the publicip
$publicip = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel

# Create & Get virtualnetworkgateway with NatRules
$vnetIpConfig = New-AzVirtualNetworkGatewayIpConfig -Name $vnetGatewayConfigName -PublicIpAddress $publicip -Subnet $subnet
$ipconfigurationId = $vnetIpConfig.id
$natRule = New-AzVirtualNetworkGatewayNatRule -Name "natRule1" -Type "Static" -Mode "IngressSnat" -InternalMapping @("25.0.0.0/16") -ExternalMapping @("30.0.0.0/16")
$job = New-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -IpConfigurations $vnetIpConfig -GatewayType Vpn -VpnType RouteBased -GatewaySku VpnGw2 -NatRule $natRule -EnableBgpRouteTranslationForNatFlag -AsJob
$job | Wait-Job
$actual = $job | Receive-Job
$expected = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname
Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName
Assert-AreEqual $expected.Name $actual.Name
Assert-AreEqual "Vpn" $expected.GatewayType
Assert-AreEqual "RouteBased" $expected.VpnType
Assert-AreEqual 1 @($expected.NatRules).Count

# Updates & Get virtualnetworkgateway with NatRules
$gateway = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname
$vngNatRules = $gateway.NatRules
$natRule = New-AzVirtualNetworkGatewayNatRule -Name "natRule2" -Type "Static" -Mode "EgressSnat" -InternalMapping @("20.0.0.0/16") -ExternalMapping @("50.0.0.0/16")
$vngNatRules.Add($natrule)
$updatedGateway = Set-AzVirtualNetworkGateway -VirtualNetworkGateway $gateway -NatRule $vngNatRules
Assert-AreEqual 2 @($updatedGateway.NatRules).Count

# List virtualNetworkGateways NatRules
$list = Get-AzVirtualNetworkGatewayNatRule -ResourceGroupName $rgname -ParentResourceName $rname
Assert-AreEqual 2 @($list).Count

# update virtualNetworkGateways NatRule
$natrule = Get-AzVirtualNetworkGatewayNatRule -ResourceGroupName $rgname -ParentResourceName $rname -Name "natRule2"
$updatedNatRule = Update-AzVirtualNetworkGatewayNatRule -InputObject $natrule -ExternalMapping @("40.0.0.0/16")
Assert-AreEqual "Succeeded" $updatedNatRule.ProvisioningState

# Delete virtualNetworkGatewayNatRules
$delete = Remove-AzVirtualNetworkGatewayNatRule -ResourceGroupName $rgname -ParentResourceName $rname -Name natRule1 -PassThru -Force
Assert-AreEqual $True $delete

# Delete virtualNetworkGateway
$job = Remove-AzVirtualNetworkGateway -ResourceGroupName $actual.ResourceGroupName -name $rname -PassThru -Force -AsJob
$job | Wait-Job
$delete = $job | Receive-Job
Assert-AreEqual true $delete

$list = Get-AzVirtualNetworkGateway -ResourceGroupName $actual.ResourceGroupName
Assert-AreEqual 0 @($list).Count
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

Large diffs are not rendered by default.

Loading