Skip to content

Commit 7a7409d

Browse files
Copilotmatthansen0
andcommitted
Address code review feedback - fix AFD_STATUS initialization order and add WAF policy existence check
Co-authored-by: matthansen0 <23407342+matthansen0@users.noreply.github.com>
1 parent 6880b8f commit 7a7409d

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

azureAISecurityDeploy.sh

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,10 @@ COSMOS_MARK="➖"; [ "$COSMOS_SUB_STATUS" = "already enabled" ] && COSMOS_MARK="
194194
echo "- Defender plan (App Services) at subscription: $APPSVC_MARK $APPSVC_SUB_STATUS"
195195
echo "- 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
199198
AFD_STATUS=""
199+
200+
# Deploy Azure Front Door with WAF
200201
AFD_PROFILE_NAME="fd-${RESOURCE_GROUP}"
201202
AFD_ENDPOINT_NAME="endpoint-${RESOURCE_GROUP}"
202203
AFD_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
}
271278
EOF
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

@@ -465,5 +473,8 @@ EOF
465473
fi
466474
fi
467475

476+
# Print final comprehensive summary
477+
print_summary
478+
468479
echo
469480
echo "All specified security features have been attempted for resources in $RESOURCE_GROUP."

0 commit comments

Comments
 (0)