@@ -194,9 +194,10 @@ COSMOS_MARK="➖"; [ "$COSMOS_SUB_STATUS" = "already enabled" ] && COSMOS_MARK="
194194echo " - Defender plan (App Services) at subscription: $APPSVC_MARK $APPSVC_SUB_STATUS "
195195echo " - Defender plan (Cosmos DBs) at subscription: $COSMOS_MARK $COSMOS_SUB_STATUS "
196196
197- # Print comprehensive summary
198- print_summary
197+ # Initialize AFD status before printing summary
199198AFD_STATUS=" ➖"
199+
200+ # Deploy Azure Front Door with WAF
200201AFD_PROFILE_NAME=" fd-${RESOURCE_GROUP} "
201202AFD_ENDPOINT_NAME=" endpoint-${RESOURCE_GROUP} "
202203AFD_ORIGIN_GROUP_NAME=" appservice-origin-group"
@@ -241,7 +242,13 @@ else
241242 # Step 2: Create WAF policy using ARM API
242243 echo " Creating WAF policy: $AFD_WAF_POLICY_NAME "
243244 WAF_POLICY_URL=" https://management.azure.com/subscriptions/${SUBSCRIPTION_ID} /resourceGroups/${RESOURCE_GROUP} /providers/Microsoft.Network/frontdoorwebapplicationfirewallpolicies/${AFD_WAF_POLICY_NAME} ?api-version=2024-02-01"
244- WAF_POLICY_BODY=$( cat << EOF
245+
246+ # Check if WAF policy already exists
247+ WAF_POLICY_EXISTS=$( az rest --method GET --url " $WAF_POLICY_URL " --query id -o tsv 2> /dev/null || true)
248+ if [ -n " $WAF_POLICY_EXISTS " ]; then
249+ echo " WAF policy already exists."
250+ else
251+ WAF_POLICY_BODY=$( cat << EOF
245252{
246253 "location": "Global",
247254 "sku": {
@@ -270,11 +277,12 @@ else
270277}
271278EOF
272279)
273- if az rest --method PUT --url " $WAF_POLICY_URL " --body " $WAF_POLICY_BODY " --headers " Content-Type=application/json" --only-show-errors; then
274- echo " WAF policy created successfully."
275- else
276- echo " Failed to create WAF policy."
277- AFD_STATUS=" ❌"
280+ if az rest --method PUT --url " $WAF_POLICY_URL " --body " $WAF_POLICY_BODY " --headers " Content-Type=application/json" --only-show-errors; then
281+ echo " WAF policy created successfully."
282+ else
283+ echo " Failed to create WAF policy."
284+ AFD_STATUS=" ❌"
285+ fi
278286 fi
279287 fi
280288
465473 fi
466474fi
467475
476+ # Print final comprehensive summary
477+ print_summary
478+
468479echo
469480echo " All specified security features have been attempted for resources in $RESOURCE_GROUP ."
0 commit comments