Goal: Toggle an application Gateway WAF between prevention and detection mode via code.
Configuration Details:
- App GW SKU: WAFv2
- Application Gateway WAF deployed
- Custom rules and managed policies are implemented
- WAF is Associated to Application Gateway
Pre-requisite Commands:
$policyName = *Input*
$appGWName = *Input*
$appGWRG = *Input*
$location = *Input*
$gw = Get-AzApplicationGateway -Name $appGWName -ResourceGroupName $appGWRG
$policy = Get-AzApplicationGatewayFirewallPolicy -Name $policyName -ResourceGroupName $appGWRG
What I've attempted:
Manually I am able to switch from prevention to detection. (Successful)
Using a Powershell command I'm able to update the WAF policy setting directly, but it does not replicate to the resource itself.
$policy.PolicySettings.Mode = "Prevention" $policy.PolicySettings.Mode = "Detection"
Using Powershell command I'm able to update the WAF policy via the Appliction gateway, but it doesn't replicate to the WAF or Application gateway.
Set-AzApplicationGatewayWebApplicationFirewallConfiguration -FirewallMode Detection -ApplicationGateway $gw -Enabled $true
Getting the following error:
quoteSet-AzApplicationGateway: WebApplicationFirewallConfiguration cannot be changed when there is a WAF Policy /subscriptions/7bba5d50-5df8-49be-b59d-b737e7663335/resourceGroups/pbolkun-RG/providers/Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies/WafPolicyProdEusAgw associated with it.
I've also tried Set-AzApplicationGateway -ApplicationGateway $gw
at the end of each implementation which again, doesn't work..
I'd like a programmatic way so that I can utilize IaC to the max. I'd prefer to avoid deploying an ARM template each time I want to switch between the two for testing.
Thank you in advanced!