The Azure Firewall is a fantastic Azure service; Microsoft constantly being improving the already feature rich networking security service but the one downside to this service when in your own lab or demo environment is the cost, the Azure Firewall is not a cheap service to run. There is a way to solve this, however. You can start and stop the Azure Firewall and as with Azure services such as virtual machines you only pay for consumption – you only pay for when it’s turned on.
To Stop the Azure Firewall, you can run the command:
$subName = YourSubscriptionName
$fwName = YourFirewallName
$rgName = YourResourceGroupName
Select-AzSubscription -SubscriptionName $subName
$azfw = Get-AzFirewall -Name $fwName -ResourceGroupName $rgName
$azfw.Deallocate()
Set-AzFirewall -AzureFirewall $azfw
To start the Azure Firewall, you can run the command:
$subName = YourSubscriptionName
$fwName = YourFirewallName
$rgName = YourResourceGroupName
$vnetName = YourVNETName
$pipName = YourPIPName
Select-AzSubscription -SubscriptionName $subName
$azfw = Get-AzFirewall -Name $fwName -ResourceGroupName $rgName
$vnet = Get-AzVirtualNetwork -ResourceGroupName $rgName -Name $vnetName
$publicip = Get-AzPublicIpAddress -Name $pipName -ResourceGroupName $rgName
$azfw.Allocate($vnet,$publicip)
Set-AzFirewall -AzureFirewall $azfw
You can run these command from the Azure Cloud Shell making it even quicker and easier to start and stop the firewall.
You can find the code here » https://github.com/Joe-Hodkinson/BuildingYourCloud/blob/main/tools/start_stop_azure.firewall.ps1