Skip to content

Commit 1e7af8e

Browse files
[Network] Added changes for Allocate function in Azure Firewall (#25385)
* Added changes for Allocate function * Updated change log file * Updated the test case * Updated the test which was failing * Updated the failed test --------- Co-authored-by: uditmisra52 <[email protected]>
1 parent 3167bc3 commit 1e7af8e

File tree

6 files changed

+10265
-1798
lines changed

6 files changed

+10265
-1798
lines changed

src/Network/Network.Test/ScenarioTests/AzureFirewallTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,5 +217,13 @@ public void TestByopipAzureHubFirewall()
217217
{
218218
TestRunner.RunTestScript("Test-InvokeAzureByopipHubFirewall");
219219
}
220+
221+
[Fact]
222+
[Trait(Category.AcceptanceType, Category.CheckIn)]
223+
[Trait(Category.Owner, NrpTeamAlias.azurefirewall)]
224+
public void TestAllocateByopipAzureHubFirewall()
225+
{
226+
TestRunner.RunTestScript("Test-InvokeAzureAllocateByopipHubFirewall");
227+
}
220228
}
221229
}

src/Network/Network.Test/ScenarioTests/AzureFirewallTests.ps1

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2181,7 +2181,7 @@ function Test-InvokeAzureByopipHubFirewall {
21812181
$rgname = Get-ResourceGroupName
21822182
$azureFirewallName = Get-ResourceName
21832183
$resourceTypeParent = "Microsoft.Network/AzureFirewalls"
2184-
$location = Get-ProviderLocation $resourceTypeParent "eastus2euap"
2184+
$location = Get-ProviderLocation $resourceTypeParent "westcentralus"
21852185
$azureFirewallPolicyName = Get-ResourceName
21862186
$skuName = "AZFW_Hub"
21872187
$skuTier = "Standard"
@@ -2224,4 +2224,75 @@ function Test-InvokeAzureByopipHubFirewall {
22242224
# Cleanup
22252225
Clean-ResourceGroup $rgname
22262226
}
2227+
}
2228+
2229+
2230+
<#
2231+
.SYNOPSIS
2232+
Tests Byopip Allocate feature for Hub Firewall
2233+
#>
2234+
function Test-InvokeAzureAllocateByopipHubFirewall {
2235+
# Setup
2236+
$rgname = Get-ResourceGroupName
2237+
$azureFirewallName = Get-ResourceName
2238+
$resourceTypeParent = "Microsoft.Network/AzureFirewalls"
2239+
$location = Get-ProviderLocation $resourceTypeParent "westcentralus"
2240+
$azureFirewallPolicyName = Get-ResourceName
2241+
$skuName = "AZFW_Hub"
2242+
$skuTier = "Standard"
2243+
$publicIpName = Get-ResourceName
2244+
$virtualWanName = Get-ResourceName
2245+
$virtualHubName = Get-ResourceName
2246+
2247+
try {
2248+
# Create the resource group
2249+
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $location -Tags @{ testtag = "testval" }
2250+
2251+
#Creating Public Ip
2252+
$publicip = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Static -Sku Standard
2253+
2254+
# Create virtual Hub
2255+
$Vwan = New-AzVirtualWan -Name $virtualWanName -ResourceGroupName $rgname -Location $location -AllowVnetToVnetTraffic -AllowBranchToBranchTraffic -VirtualWANType "Standard"
2256+
$Hub = New-AzVirtualHub -Name $virtualHubName -ResourceGroupName $rgname -VirtualWan $Vwan -Location $Location -AddressPrefix "192.168.1.0/24" -Sku "Standard"
2257+
2258+
# Create firewall
2259+
$vHubId = $Hub.Id
2260+
2261+
$hubIp = New-AzFirewallHubPublicIpAddress -Count 2
2262+
$AzFWHubIPs = New-AzFirewallHubIpAddress -PublicIP $hubIp
2263+
2264+
New-AzFirewall -Name $azureFirewallName -ResourceGroupName $rgname -Location $location -SkuName $skuName -SkuTier $skuTier -HubIPAddress $AzFWHubIPs -VirtualHubId $vHubId
2265+
2266+
$AzFw = Get-AzFirewall -name $azureFirewallName -ResourceGroupName $rgname
2267+
2268+
$hubIp = New-AzFirewallHubPublicIpAddress -Count 0
2269+
$AzFWHubIPs = New-AzFirewallHubIpAddress -PublicIP $hubIp
2270+
$Azfw.HubIpAddresses = $AzFWHubIPs
2271+
$AzFw.Deallocate()
2272+
Set-AzFirewall -AzureFirewall $AzFw
2273+
2274+
# Allocate the firewall
2275+
$AzFw = Get-AzFirewall -name $azureFirewallName -ResourceGroupName $rgname
2276+
$AzFw.Allocate($Hub.Id, $publicip)
2277+
Set-AzFirewall -AzureFirewall $AzFw
2278+
2279+
# Get AzureFirewall
2280+
$getAzureFirewall = Get-AzFirewall -name $azureFirewallName -ResourceGroupName $rgname
2281+
2282+
#verification
2283+
Assert-AreEqual $rgName $getAzureFirewall.ResourceGroupName
2284+
Assert-AreEqual $azureFirewallName $getAzureFirewall.Name
2285+
Assert-NotNull $getAzureFirewall.Location
2286+
Assert-AreEqual (Normalize-Location $location) $getAzureFirewall.Location
2287+
Assert-NotNull $getAzureFirewall.Sku
2288+
Assert-AreEqual $skuName $getAzureFirewall.Sku.Name
2289+
Assert-AreEqual $skuTier $getAzureFirewall.Sku.Tier
2290+
Assert-AreEqual 1 @($getAzureFirewall.IpConfigurations).Count
2291+
Assert-NotNull $getAzureFirewall.IpConfigurations[0].PublicIpAddress.Id
2292+
Assert-NotNull $getAzureFirewall.IpConfigurations[0].PrivateIpAddress
2293+
}
2294+
finally {
2295+
# Cleanup
2296+
Clean-ResourceGroup $rgname
2297+
}
22272298
}

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.AzureFirewallTests/TestAllocateByopipAzureHubFirewall.json

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

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.AzureFirewallTests/TestByopipAzureHubFirewall.json

Lines changed: 1215 additions & 1797 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
@@ -43,6 +43,7 @@
4343
* Updated the Azure Firewall and Azure Firewall Policy setter for their respective Private Range properties
4444
- Fixed a bug that prevented using /32 in private ranges on classic Azure Firewalls
4545
- Updated the error message to provide a suggested private range when the supplied range is not correctly masked by the host identifier
46+
- Added a new Allocate function for Azure Firewall that allows allocating customer public ip address to the firewall
4647
- Fixed a bug that caused firewalls and policies to lose their private range property value when using their 'Get' cmdlets
4748

4849
## Version 7.6.0

src/Network/Network/Models/AzureFirewall/PSAzureFirewall.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,39 @@ public void Allocate(Management.Network.Models.SubResource virtualHub)
150150
throw new ArgumentException($"Hub firewall allocation attempted on a Non-hub firewall. Firewall name = {this.Name}, Sku name = {this.Sku.Name}");
151151
}
152152
}
153+
public void Allocate(Management.Network.Models.SubResource virtualHub, PSPublicIpAddress[] publicIpAddresses)
154+
{
155+
if (this.Sku.Name.Equals("AZFW_Hub", StringComparison.OrdinalIgnoreCase))
156+
{
157+
this.VirtualHub = virtualHub;
158+
}
159+
else
160+
{
161+
throw new ArgumentException($"Hub firewall allocation attempted on a Non-hub firewall. Firewall name = {this.Name}, Sku name = {this.Sku.Name}");
162+
}
163+
164+
this.IpConfigurations = new List<PSAzureFirewallIpConfiguration>();
165+
166+
if (publicIpAddresses != null && publicIpAddresses.Count() > 0)
167+
{
168+
for (var i = 0; i < publicIpAddresses.Count(); i++)
169+
{
170+
this.IpConfigurations.Add(
171+
new PSAzureFirewallIpConfiguration
172+
{
173+
Name = $"{AzureFirewallIpConfigurationName}{i}",
174+
PublicIpAddress = new PSResourceId { Id = publicIpAddresses[i].Id }
175+
});
176+
}
177+
}
178+
else
179+
{
180+
this.IpConfigurations.Add(new PSAzureFirewallIpConfiguration { Name = $"{AzureFirewallIpConfigurationName}{0}" });
181+
}
182+
183+
// Making HubIpAddresses property null because it is an allocate for Byopip Hub firewall, where HubIpAddress should be kept null
184+
this.HubIPAddresses = null;
185+
}
153186

154187
public void Allocate(PSVirtualNetwork virtualNetwork, PSPublicIpAddress[] publicIpAddresses, PSPublicIpAddress ManagementPublicIpAddress = null)
155188
{

0 commit comments

Comments
 (0)