How to associate WAF to an existing Application Gateway using REST API
Hello team,
We have an existing application gateway, and I want to automate associating a WAF policy on this existing gateway. I am using Ansible URI module to achieve this, hence exploring API for WAF Association.
I want to achieve association using REST API for all 3 options - Application Gateway, HTTP Listener, Route Path.
For creating WAF and associating, I try below curl for associating HTTP Listener:
curl --location --request PUT 'https://management.azure.com/subscriptions/subscriptionId/resourceGroups/resourceGroupName/providers/Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies/policyName?api-version=2023-05-01' \
--data '{
"location": "eastus",
"properties": {
"provisioningState": "Succeeded",
"customRules": [],
"policySettings": {
"requestBodyCheck": true,
"maxRequestBodySizeInKb": 128,
"fileUploadLimitInMb": 100,
"state": "Enabled",
"mode": "Prevention",
"requestBodyInspectLimitInKB": 128,
"fileUploadEnforcement": true,
"requestBodyEnforcement": true
},
"managedRules": {
"managedRuleSets": [
{
"ruleSetType": "OWASP",
"ruleSetVersion": "3.2",
"ruleGroupOverrides": []
}
],
"exclusions": []
},
"httpListeners": [
{
"id": "/subscriptions/subscriptionId/resourceGroups/resourceGroupName/providers/Microsoft.Network/applicationGateways/test-appgateway/httpListeners/test-listener"
}
]
}
}'
Similarly, I replace "httpListeners" with "applicationGateways" in the body to associate Application Gateway to WAF:
"applicationGateways": [
{
"id": "/subscriptions/subscriptionId/resourceGroups/resourceGroupId/providers/Microsoft.Network/applicationGateways/test-appgateway"
}
]
But none of it works. The association is not reflecting.
Kindly let me know if this is not the correct approach and I should follow different methods.
Thank you
Regards,
Krutika