Skip to content

Commit b2abd61

Browse files
authored
[Network] - Add DefaultOutboundAccess parameter on subnet (#22910)
* Add DefaultOutboundAccess parameter on subnet * update help doc * make property nullable to avoid default false
1 parent bc22d23 commit b2abd61

File tree

10 files changed

+1984
-4
lines changed

10 files changed

+1984
-4
lines changed

src/Network/Network.Test/ScenarioTests/VirtualNetworkTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ public void TestVirtualNetworkSubnetCRUD()
5050
TestRunner.RunTestScript("Test-subnetCRUD");
5151
}
5252

53+
[Fact]
54+
[Trait(Category.AcceptanceType, Category.CheckIn)]
55+
[Trait(Category.Owner, NrpTeamAlias.wanrpdev_subset1)]
56+
public void TestSubnetWithDefaultOutboundAccessCRUD()
57+
{
58+
TestRunner.RunTestScript("Test-subnetWithDefaultOutboundAccessCRUD");
59+
}
60+
5361
[Fact(Skip = "Authentication failed for auxiliary token: The '1' auxiliary tokens contains duplicates which are from the same tenant.")]
5462
[Trait(Category.AcceptanceType, Category.LiveOnly)]
5563
[Trait(Category.Owner, NrpTeamAlias.wanrpdev_subset1)]

src/Network/Network.Test/ScenarioTests/VirtualNetworkTests.ps1

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,64 @@ function Test-subnetCRUD
202202
}
203203
}
204204

205+
<#
206+
.SYNOPSIS
207+
Tests creating new simple virtualNetwork and subnets.
208+
.DESCRIPTION
209+
SmokeTest
210+
#>
211+
function Test-subnetWithDefaultOutboundAccessCRUD
212+
{
213+
# Setup
214+
$rgname = Get-ResourceGroupName
215+
$vnetName = Get-ResourceName
216+
$subnetName = Get-ResourceName
217+
$subnet2Name = Get-ResourceName
218+
$domainNameLabel = Get-ResourceName
219+
$rglocation = Get-ProviderLocation ResourceManagement
220+
$resourceTypeParent = "Microsoft.Network/virtualNetworks"
221+
$location = Get-ProviderLocation $resourceTypeParent
222+
223+
try
224+
{
225+
# Create the resource group
226+
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }
227+
228+
# Create the Virtual Network
229+
$subnet = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.1.0/24 -DefaultOutboundAccess $true
230+
New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
231+
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
232+
233+
# Add a subnet
234+
$vnet | Add-AzVirtualNetworkSubnetConfig -Name $subnet2Name -AddressPrefix 10.0.2.0/24 -DefaultOutboundAccess $true
235+
236+
# Set VirtualNetwork
237+
$vnet | Set-AzVirtualNetwork
238+
239+
# Get VirtualNetwork
240+
$vnetExpected = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
241+
242+
Assert-AreEqual 2 @($vnetExpected.Subnets).Count
243+
Assert-AreEqual $subnetName $vnetExpected.Subnets[0].Name
244+
Assert-AreEqual $subnet2Name $vnetExpected.Subnets[1].Name
245+
Assert-AreEqual "10.0.2.0/24" $vnetExpected.Subnets[1].AddressPrefix
246+
Assert-AreEqual $true $vnetExpected.Subnets[0].DefaultOutboundAccess
247+
Assert-AreEqual $true $vnetExpected.Subnets[1].DefaultOutboundAccess
248+
249+
# Remove a subnet
250+
Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname | Remove-AzVirtualNetworkSubnetConfig -Name $subnet2Name | Set-AzVirtualNetwork
251+
252+
$vnetExpected = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
253+
Assert-AreEqual 1 @($vnetExpected.Subnets).Count
254+
Assert-AreEqual $subnetName $vnetExpected.Subnets[0].Name
255+
}
256+
finally
257+
{
258+
# Cleanup
259+
Clean-ResourceGroup $rgname
260+
}
261+
}
262+
205263
<#
206264
.SYNOPSIS
207265
Tests creating, updating & deleting a virtualNetwork with BGP Communities.

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.VirtualNetworkTests/TestSubnetWithDefaultOutboundAccessCRUD.json

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

src/Network/Network/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
--->
2020

2121
## Upcoming Release
22+
* Added DefaultOutboundAccess parameter on subnet creation
2223
* Updated cmdlet `New-AzPublicIpPrefix` and `New-PublicIpAddress` to require Location parameter
2324
* Updated cmdlet `New-AzLoadBalancerBackendAddressPool` to support managed IP based backend
2425
* Added cmdlet `New-AzSaaSNetworkVirtualAppliance` for creating a NetworkVirtualAppliance of SaaS type.

src/Network/Network/Models/PSSubnet.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ public class PSSubnet : PSChildResource
7171
[JsonProperty(Order = 1)]
7272
public List<PSResourceId> IpAllocations { get; set; }
7373

74+
[JsonProperty(Order = 1)]
75+
public bool? DefaultOutboundAccess { get; set; }
76+
7477
[JsonIgnore]
7578
public string IpConfigurationsText
7679
{
@@ -171,5 +174,11 @@ public string IpAllocationsText
171174
{
172175
get { return JsonConvert.SerializeObject(IpAllocations, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
173176
}
177+
178+
[JsonIgnore]
179+
public string DefaultOutboundAccessText
180+
{
181+
get { return JsonConvert.SerializeObject(DefaultOutboundAccess, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
182+
}
174183
}
175184
}

src/Network/Network/VirtualNetwork/Subnet/AddAzureVirtualNetworkSubnetConfigCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public override void Execute()
7070

7171
subnet.Name = this.Name;
7272
subnet.AddressPrefix = this.AddressPrefix?.ToList();
73+
subnet.DefaultOutboundAccess = this.DefaultOutboundAccess;
7374

7475
if (this.IpAllocation != null)
7576
{

src/Network/Network/VirtualNetwork/Subnet/AzureVirtualNetworkSubnetConfigBase.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,11 @@ public class AzureVirtualNetworkSubnetConfigBase : NetworkBaseCmdlet
126126
ValueFromPipelineByPropertyName = true,
127127
HelpMessage = "IpAllocation")]
128128
public PSIpAllocation[] IpAllocation { get; set; }
129+
130+
[Parameter(
131+
Mandatory = false,
132+
ValueFromPipelineByPropertyName = true,
133+
HelpMessage = "Default outbound connectivity for all VMs in the subnet")]
134+
public bool? DefaultOutboundAccess { get; set; }
129135
}
130136
}

src/Network/Network/VirtualNetwork/Subnet/NewAzureVirtualNetworkSubnetConfigCommand.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public override void Execute()
5454
subnet.Name = this.Name;
5555
subnet.AddressPrefix = this.AddressPrefix?.ToList();
5656
subnet.IpAllocations = new List<PSResourceId>();
57+
subnet.DefaultOutboundAccess = this.DefaultOutboundAccess;
58+
5759
if (this.IpAllocation != null)
5860
{
5961
foreach (var allocation in this.IpAllocation)

src/Network/Network/help/Add-AzVirtualNetworkSubnetConfig.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Add-AzVirtualNetworkSubnetConfig -Name <String> -VirtualNetwork <PSVirtualNetwor
2020
[-ServiceEndpoint <String[]>] [-ServiceEndpointPolicy <PSServiceEndpointPolicy[]>]
2121
[-Delegation <PSDelegation[]>] [-PrivateEndpointNetworkPoliciesFlag <String>]
2222
[-PrivateLinkServiceNetworkPoliciesFlag <String>] [-IpAllocation <PSIpAllocation[]>]
23-
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
23+
[-DefaultOutboundAccess <Boolean>] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
2424
```
2525

2626
### SetByResourceId
@@ -30,7 +30,7 @@ Add-AzVirtualNetworkSubnetConfig -Name <String> -VirtualNetwork <PSVirtualNetwor
3030
[-ServiceEndpoint <String[]>] [-ServiceEndpointPolicy <PSServiceEndpointPolicy[]>]
3131
[-Delegation <PSDelegation[]>] [-PrivateEndpointNetworkPoliciesFlag <String>]
3232
[-PrivateLinkServiceNetworkPoliciesFlag <String>] [-IpAllocation <PSIpAllocation[]>]
33-
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
33+
[-DefaultOutboundAccess <Boolean>] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
3434
```
3535

3636
## DESCRIPTION
@@ -79,6 +79,21 @@ Accept pipeline input: False
7979
Accept wildcard characters: False
8080
```
8181
82+
### -DefaultOutboundAccess
83+
Default outbound connectivity for all VMs in the subnet
84+
85+
```yaml
86+
Type: System.Nullable`1[System.Boolean]
87+
Parameter Sets: (All)
88+
Aliases:
89+
90+
Required: False
91+
Position: Named
92+
Default value: None
93+
Accept pipeline input: True (ByPropertyName)
94+
Accept wildcard characters: False
95+
```
96+
8297
### -DefaultProfile
8398
The credentials, account, tenant, and subscription used for communication with azure.
8499

src/Network/Network/help/New-AzVirtualNetworkSubnetConfig.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ New-AzVirtualNetworkSubnetConfig -Name <String> -AddressPrefix <String[]>
2020
[-ServiceEndpoint <String[]>] [-ServiceEndpointPolicy <PSServiceEndpointPolicy[]>]
2121
[-Delegation <PSDelegation[]>] [-PrivateEndpointNetworkPoliciesFlag <String>]
2222
[-PrivateLinkServiceNetworkPoliciesFlag <String>] [-IpAllocation <PSIpAllocation[]>]
23-
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
23+
[-DefaultOutboundAccess <Boolean>] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
2424
```
2525

2626
### SetByResourceId
@@ -29,7 +29,8 @@ New-AzVirtualNetworkSubnetConfig -Name <String> -AddressPrefix <String[]> [-Netw
2929
[-RouteTableId <String>] [-ResourceId <String>] [-ServiceEndpoint <String[]>]
3030
[-ServiceEndpointPolicy <PSServiceEndpointPolicy[]>] [-Delegation <PSDelegation[]>]
3131
[-PrivateEndpointNetworkPoliciesFlag <String>] [-PrivateLinkServiceNetworkPoliciesFlag <String>]
32-
[-IpAllocation <PSIpAllocation[]>] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
32+
[-IpAllocation <PSIpAllocation[]>] [-DefaultOutboundAccess <Boolean>]
33+
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
3334
```
3435

3536
## DESCRIPTION
@@ -92,6 +93,21 @@ Accept pipeline input: False
9293
Accept wildcard characters: False
9394
```
9495
96+
### -DefaultOutboundAccess
97+
Default outbound connectivity for all VMs in the subnet
98+
99+
```yaml
100+
Type: System.Nullable`1[System.Boolean]
101+
Parameter Sets: (All)
102+
Aliases:
103+
104+
Required: False
105+
Position: Named
106+
Default value: None
107+
Accept pipeline input: True (ByPropertyName)
108+
Accept wildcard characters: False
109+
```
110+
95111
### -DefaultProfile
96112
The credentials, account, tenant, and subscription used for communication with azure.
97113

0 commit comments

Comments
 (0)