Skip to content

Commit 68bf8ec

Browse files
StandardV2 NGW changes (#27776)
Co-authored-by: Yabo Hu <[email protected]>
1 parent 03b1bbc commit 68bf8ec

23 files changed

+10621
-784
lines changed

src/Network/Network.Test/ScenarioTests/NatGatewayTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,29 @@ public void TestNatGatewayWithSubnet()
4848
{
4949
TestRunner.RunTestScript("Test-NatGatewayWithSubnet");
5050
}
51+
52+
[Fact]
53+
[Trait(Category.AcceptanceType, Category.CheckIn)]
54+
[Trait(Category.Owner, NrpTeamAlias.slbdev)]
55+
public void TestNatGatewayWithPIPsAndSourceVnet()
56+
{
57+
TestRunner.RunTestScript("Test-NatGatewayWithPIPsAndSourceVnet");
58+
}
59+
60+
[Fact]
61+
[Trait(Category.AcceptanceType, Category.CheckIn)]
62+
[Trait(Category.Owner, NrpTeamAlias.slbdev)]
63+
public void TestNatGatewayWithPrefixesAndSourceVnet()
64+
{
65+
TestRunner.RunTestScript("Test-NatGatewayWithPrefixesAndSourceVnet");
66+
}
67+
68+
[Fact]
69+
[Trait(Category.AcceptanceType, Category.CheckIn)]
70+
[Trait(Category.Owner, NrpTeamAlias.slbdev)]
71+
public void TestVirtualNetworkSubnetConfigWithNatGateway()
72+
{
73+
TestRunner.RunTestScript("Test-VirtualNetworkSubnetConfigWithNatGateway");
74+
}
5175
}
5276
}

src/Network/Network.Test/ScenarioTests/NatGatewayTests.ps1

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,154 @@ function Test-NatGatewayCRUDAllParameters
281281
Clean-ResourceGroup $rgname;
282282
}
283283
}
284+
285+
<#
286+
.SYNOPSIS
287+
Test creating new NatGateway with IPv4 and IPv6 Public IP Addresses and a VirtualNetwork
288+
#>
289+
function Test-NatGatewayWithPIPsAndSourceVnet
290+
{
291+
# Setup
292+
$rgname = Get-ResourceGroupName;
293+
$rglocation = Get-ProviderLocation ResourceManagement;
294+
$rname = Get-ResourceName;
295+
$vnetName = Get-ResourceName;
296+
$subnetName = Get-ResourceName;
297+
$publicIpName = Get-ResourceName;
298+
$publicIpNameV6 = Get-ResourceName;
299+
$location = Get-ProviderLocation "Microsoft.Network/networkWatchers" "East US 2 EUAP";
300+
$sku = "StandardV2";
301+
302+
try
303+
{
304+
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation;
305+
306+
# Create IPv4 PublicIP
307+
$publicip = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Static -Sku $sku
308+
309+
# Create IPv6 PublicIP
310+
$publicipv6 = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpNameV6 -location $location -AllocationMethod Static -Sku $sku -IpAddressVersion "IPv6"
311+
312+
# Create Vnet
313+
New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16
314+
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
315+
316+
# Create NatGateway
317+
$vNatGateway = New-AzNatGateway -ResourceGroupName $rgname -Name $rname -Location $location -sku $sku -PublicIpAddress $publicip -PublicIPAddressV6 $publicipv6 -SourceVirtualNetwork $vnet;
318+
Assert-NotNull $vNatGateway;
319+
Assert-AreEqual $rname $vNatGateway.Name;
320+
Assert-AreEqual $vNatGateway.PublicIpAddresses.Count 1;
321+
Assert-AreEqual $vNatGateway.PublicIpAddressesV6.Count 1;
322+
Assert-AreEqual $vNatGateway.SourceVirtualNetwork.Id $vnet.Id;
323+
324+
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
325+
Assert-AreEqual $vNatGateway.Id @($vnet.DefaultPublicNatGateway.Id)
326+
327+
}
328+
finally
329+
{
330+
# Cleanup
331+
Clean-ResourceGroup $rgname;
332+
}
333+
}
334+
335+
<#
336+
.SYNOPSIS
337+
Test creating new NatGateway with IPv4 and IPv6 Public IP Prefixes and a VirtualNetwork
338+
#>
339+
function Test-NatGatewayWithPrefixesAndSourceVnet
340+
{
341+
# Setup
342+
$rgname = Get-ResourceGroupName;
343+
$rglocation = Get-ProviderLocation ResourceManagement;
344+
$rname = Get-ResourceName;
345+
$vnetName = Get-ResourceName;
346+
$subnetName = Get-ResourceName;
347+
$publicIpName = Get-ResourceName;
348+
$publicIpNameV6 = Get-ResourceName;
349+
$location = Get-ProviderLocation "Microsoft.Network/networkWatchers" "East US 2 EUAP";
350+
$sku = "StandardV2";
351+
352+
try
353+
{
354+
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation;
355+
356+
# Create IPv4 PublicIP
357+
$publicip = New-AzPublicIpPrefix -ResourceGroupName $rgname -name $publicIpName -location $location -Sku $sku -PrefixLength 28
358+
359+
# Create IPv6 PublicIP
360+
$publicipv6 = New-AzPublicIpPrefix -ResourceGroupName $rgname -name $publicIpNameV6 -location $location -Sku $sku -IpAddressVersion "IPv6" -PrefixLength 124
361+
362+
# Create Vnet
363+
New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16
364+
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
365+
366+
# Create NatGateway
367+
$vNatGateway = New-AzNatGateway -ResourceGroupName $rgname -Name $rname -Location $location -sku $sku -PublicIpPrefix $publicip -PublicIpPrefixV6 $publicipv6 -SourceVirtualNetwork $vnet;
368+
Assert-NotNull $vNatGateway;
369+
Assert-AreEqual $rname $vNatGateway.Name;
370+
Assert-AreEqual $vNatGateway.PublicIpPrefixes.Count 1;
371+
Assert-AreEqual $vNatGateway.PublicIpPrefixesV6.Count 1;
372+
Assert-AreEqual $vNatGateway.SourceVirtualNetwork.Id $vnet.Id;
373+
374+
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
375+
Assert-AreEqual $vNatGateway.Id @($vnet.DefaultPublicNatGateway.Id)
376+
377+
}
378+
finally
379+
{
380+
# Cleanup
381+
Clean-ResourceGroup $rgname;
382+
}
383+
}
384+
385+
<#
386+
.SYNOPSIS
387+
Test creating new NatGateway with IPv4 and IPv6 Public IP Prefixes and a VirtualNetwork
388+
#>
389+
function Test-VirtualNetworkSubnetConfigWithNatGateway
390+
{
391+
# Setup
392+
$rgname = Get-ResourceGroupName;
393+
$rglocation = Get-ProviderLocation ResourceManagement;
394+
$rname = Get-ResourceName;
395+
$vnetName = Get-ResourceName;
396+
$subnetName = Get-ResourceName;
397+
$publicIpName = Get-ResourceName;
398+
$publicIpNameV6 = Get-ResourceName;
399+
$location = Get-ProviderLocation "Microsoft.Network/networkWatchers" "East US 2 EUAP";
400+
$sku = "StandardV2";
401+
402+
try
403+
{
404+
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation;
405+
406+
# Create NatGateway
407+
$vNatGateway = New-AzNatGateway -ResourceGroupName $rgname -Name $rname -Location $location -sku $sku;
408+
Assert-NotNull $vNatGateway;
409+
410+
# Create Subnet Config
411+
$frontendSubnet = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.1.0/24
412+
413+
# Create Vnet
414+
New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $frontendSubnet
415+
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
416+
417+
# Set Subnet Config with NatGateway
418+
Set-AzVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $vnet -NatGateway $vNatGateway -AddressPrefix 10.0.0.0/16
419+
$vnet | Set-AzVirtualNetwork
420+
421+
Assert-AreEqual $vnet.Subnets[0].NatGateway.Id $vNatGateway.Id
422+
423+
$vNatGateway = Set-AzNatGateway -ResourceGroupName $rgname -Name $rname -SourceVirtualNetwork $vnet
424+
Assert-AreEqual $vNatGateway.SourceVirtualNetwork.Id $vnet.Id
425+
426+
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
427+
Assert-AreEqual $vNatGateway.Id @($vnet.DefaultPublicNatGateway.Id)
428+
}
429+
finally
430+
{
431+
# Cleanup
432+
Clean-ResourceGroup $rgname;
433+
}
434+
}

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.NatGatewayTests/TestNatGatewayWithPIPsAndSourceVnet.json

Lines changed: 3740 additions & 0 deletions
Large diffs are not rendered by default.

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.NatGatewayTests/TestNatGatewayWithPrefixesAndSourceVnet.json

Lines changed: 2981 additions & 0 deletions
Large diffs are not rendered by default.

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.NatGatewayTests/TestNatGatewayWithSubnet.json

Lines changed: 910 additions & 756 deletions
Large diffs are not rendered by default.

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.NatGatewayTests/TestVirtualNetworkSubnetConfigWithNatGateway.json

Lines changed: 2435 additions & 0 deletions
Large diffs are not rendered by default.

src/Network/Network/ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
--->
2020

2121
## Upcoming Release
22+
* Added properties 'PublicIpAddressesV6', 'PublicIpPrefixesV6', and 'SourceVirtualNetwork' to NatGateway, as well as support for it for the following cmdlets:
23+
- `New-AzNatGateway`
24+
- `Set-AzNatGateway`
25+
* Added property 'DefaultPublicNatGateway' to VirtualNetwork.
26+
* Onboarded `Microsoft.FluidRelay/fluidRelayServers` to private link cmdlets
2227
* Added cmdlet `Get-AzLoadBalancerRuleHealth` for Load Balancer Rule Health.
2328
* Added property "EnableConnectionTracking" to Load Balancing Rule, as well as support for it for the following cmdlets:
2429
- `Add-AzLoadBalancerRuleConfig`

src/Network/Network/Models/PSNatGateway.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public partial class PSNatGateway : PSTopLevelResource
3030
public List<string> Zones { get; set; }
3131
public List<PSResourceId> PublicIpAddresses { get; set; }
3232
public List<PSResourceId> PublicIpPrefixes { get; set; }
33+
public List<PSResourceId> PublicIpAddressesV6 { get; set; }
34+
public List<PSResourceId> PublicIpPrefixesV6 { get; set; }
35+
public PSResourceId SourceVirtualNetwork { get; set; }
3336

3437
[JsonIgnore]
3538
public string SkuText
@@ -48,5 +51,32 @@ public string PublicIpPrefixesText
4851
{
4952
get { return JsonConvert.SerializeObject(PublicIpPrefixes, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
5053
}
54+
55+
[JsonIgnore]
56+
public string PublicIpAddressesV6Text
57+
{
58+
get { return JsonConvert.SerializeObject(PublicIpAddressesV6, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
59+
}
60+
61+
[JsonIgnore]
62+
public string PublicIpPrefixesV6Text
63+
{
64+
get { return JsonConvert.SerializeObject(PublicIpPrefixesV6, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
65+
}
66+
67+
68+
[JsonIgnore]
69+
public string SourceVirtualNetworkText
70+
{
71+
get
72+
{
73+
if (SourceVirtualNetwork?.Id != null)
74+
{
75+
string resourceName = SourceVirtualNetwork.Id.Substring(SourceVirtualNetwork.Id.LastIndexOf('/') + 1);
76+
return resourceName;
77+
}
78+
return null;
79+
}
80+
}
5181
}
5282
}

src/Network/Network/Models/PSPublicIpAddress.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public string IpTagsText
7878
[JsonIgnore]
7979
public string SkuText
8080
{
81-
get { return JsonConvert.SerializeObject(Sku, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
81+
get { return Sku != null ? JsonConvert.SerializeObject(Sku.Name, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }) : null; }
8282
}
8383

8484
[JsonIgnore]

src/Network/Network/Models/PSPublicIpPrefix.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public string IpTagsText
6060
[JsonIgnore]
6161
public string SkuText
6262
{
63-
get { return JsonConvert.SerializeObject(Sku, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
63+
get { return Sku != null ? JsonConvert.SerializeObject(Sku.Name, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }) : null; }
6464
}
6565

6666
[JsonIgnore]

src/Network/Network/Models/PSSubnet.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public class PSSubnet : PSChildResource
4545
public PSRouteTable RouteTable { get; set; }
4646

4747
[JsonProperty(Order = 1)]
48-
[Ps1Xml(Label = "NatGateway Name", Target = ViewControl.Table, ScriptBlock = "$_.NatGateway.Name")]
4948
public PSResourceId NatGateway { get; set; }
5049

5150
[JsonProperty(Order = 1)]
@@ -110,7 +109,15 @@ public string RouteTableText
110109
[JsonIgnore]
111110
public string NatGatewayText
112111
{
113-
get { return JsonConvert.SerializeObject(NatGateway, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
112+
get
113+
{
114+
if (NatGateway?.Id != null)
115+
{
116+
string resourceName = NatGateway.Id.Substring(NatGateway.Id.LastIndexOf('/') + 1);
117+
return resourceName;
118+
}
119+
return null;
120+
}
114121
}
115122

116123
public bool ShouldSerializeIpConfigurations()

src/Network/Network/Models/PSVirtualNetwork.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public class PSVirtualNetwork : PSTopLevelResource, IResourceReference, IVirtual
5252
[Ps1Xml(Target = ViewControl.Table)]
5353
public string PrivateEndpointVNetPolicies { get; set; }
5454

55+
public PSResourceId DefaultPublicNatGateway { get; set; }
56+
5557
[JsonIgnore]
5658
public string AddressSpaceText
5759
{
@@ -117,5 +119,19 @@ public string ExtendedLocationText
117119
{
118120
get { return JsonConvert.SerializeObject(ExtendedLocation, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
119121
}
122+
123+
[JsonIgnore]
124+
public string DefaultPublicNatGatewayText
125+
{
126+
get
127+
{
128+
if (DefaultPublicNatGateway?.Id != null)
129+
{
130+
string resourceName = DefaultPublicNatGateway.Id.Substring(DefaultPublicNatGateway.Id.LastIndexOf('/') + 1);
131+
return resourceName;
132+
}
133+
return null;
134+
}
135+
}
120136
}
121137
}

src/Network/Network/NatGateway/NewAzureRMNatGatewayCommand.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public partial class NewAzureRmNatGateway : NetworkBaseCmdlet
6464
Mandatory = false,
6565
HelpMessage = "Name of a NAT gateway SKU.")]
6666
[ValidateNotNullOrEmpty]
67-
[PSArgumentCompleter(MNM.NatGatewaySkuName.Standard)]
67+
[PSArgumentCompleter(MNM.NatGatewaySkuName.Standard, "StandardV2")]
6868
public string Sku { get; set; }
6969

7070
[Parameter(
@@ -80,14 +80,29 @@ public partial class NewAzureRmNatGateway : NetworkBaseCmdlet
8080

8181
[Parameter(
8282
Mandatory = false,
83-
HelpMessage = "An array of public ip addresses associated with the nat gateway resource.")]
83+
HelpMessage = "An array of public IPv4 addresses associated with the nat gateway resource.")]
8484
public PSResourceId[] PublicIpAddress { get; set; }
8585

8686
[Parameter(
8787
Mandatory = false,
88-
HelpMessage = "An array of public ip prefixes associated with the nat gateway resource.")]
88+
HelpMessage = "An array of public IPv6 addresses associated with the nat gateway resource.")]
89+
public PSResourceId[] PublicIpAddressV6 { get; set; }
90+
91+
[Parameter(
92+
Mandatory = false,
93+
HelpMessage = "An array of public IPv4 prefixes associated with the nat gateway resource.")]
8994
public PSResourceId[] PublicIpPrefix { get; set; }
9095

96+
[Parameter(
97+
Mandatory = false,
98+
HelpMessage = "An array of public IPv6 prefixes associated with the nat gateway resource.")]
99+
public PSResourceId[] PublicIpPrefixV6 { get; set; }
100+
101+
[Parameter(
102+
Mandatory = false,
103+
HelpMessage = "The id of the source virtual network using this nat gateway resource.")]
104+
public PSResourceId SourceVirtualNetwork { get; set; }
105+
91106
[Parameter(
92107
Mandatory = false,
93108
HelpMessage = "Do not ask for confirmation if you want to overwrite a resource")]
@@ -109,17 +124,25 @@ public override void Execute()
109124
{
110125
vSku = new PSNatGatewaySku();
111126
}
112-
vSku.Name = MNM.NatGatewaySkuName.Standard;
127+
vSku.Name = this.Sku;
113128
}
114129

115130
// PublicIpAddresses
116131
List<PSResourceId> vPublicIpAddresses = null;
117132

133+
// PublicIpAddressesV6
134+
List<PSResourceId> vPublicIpAddressesV6 = null;
135+
118136
// PublicIpPrefixes
119137
List<PSResourceId> vPublicIpPrefixes = null;
120138

139+
// PublicIpPrefixesV6
140+
List<PSResourceId> vPublicIpPrefixesV6 = null;
141+
121142
vPublicIpAddresses = this.PublicIpAddress?.ToList();
143+
vPublicIpAddressesV6 = this.PublicIpAddressV6?.ToList();
122144
vPublicIpPrefixes = this.PublicIpPrefix?.ToList();
145+
vPublicIpPrefixesV6 = this.PublicIpPrefixV6?.ToList();
123146

124147
var vNatGateway = new PSNatGateway
125148
{
@@ -128,6 +151,9 @@ public override void Execute()
128151
Sku = vSku,
129152
PublicIpAddresses = vPublicIpAddresses,
130153
PublicIpPrefixes = vPublicIpPrefixes,
154+
PublicIpAddressesV6 = vPublicIpAddressesV6,
155+
PublicIpPrefixesV6 = vPublicIpPrefixesV6,
156+
SourceVirtualNetwork = this.SourceVirtualNetwork
131157
};
132158

133159
vNatGateway.Zones = this.Zone?.ToList();

0 commit comments

Comments
 (0)