Azure Policy for governance - Time & Space Complexity
We want to understand how the time to apply Azure Policy changes as we add more resources.
How does the number of resources affect the policy evaluation time?
Analyze the time complexity of assigning a policy to a subscription and evaluating it.
# Assign a policy definition to a subscription
az policy assignment create \
--name "enforce-tag" \
--policy "require-tag" \
--scope "/subscriptions/00000000-0000-0000-0000-000000000000"
# Azure evaluates the policy against all resources in the subscription
# and marks non-compliant resources
This sequence assigns a policy and triggers evaluation on all subscription resources.
Look at what happens repeatedly when the policy runs.
- Primary operation: Policy evaluation on each resource.
- How many times: Once per resource in the subscription.
As the number of resources grows, the policy evaluation runs on each one.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 evaluations |
| 100 | 100 evaluations |
| 1000 | 1000 evaluations |
Pattern observation: The number of evaluations grows directly with the number of resources.
Time Complexity: O(n)
This means the time to evaluate policies grows in direct proportion to the number of resources.
[X] Wrong: "Policy evaluation time stays the same no matter how many resources there are."
[OK] Correct: Each resource must be checked, so more resources mean more work and longer evaluation time.
Understanding how policy evaluation scales helps you design governance that stays efficient as your cloud grows.
"What if we assigned the policy at a resource group level instead of subscription? How would the time complexity change?"
Practice
Solution
Step 1: Understand Azure Policy's role
Azure Policy is designed to enforce rules on resources to keep them compliant with company rules.Step 2: Compare options to this role
Only To enforce rules and ensure resources comply with organizational standards describes enforcing rules and compliance, which matches Azure Policy's purpose.Final Answer:
To enforce rules and ensure resources comply with organizational standards -> Option CQuick Check:
Azure Policy = Enforce rules [OK]
- Confusing Azure Policy with Azure Monitor
- Thinking Azure Policy creates resources
- Mixing Azure Policy with backup services
Solution
Step 1: Identify the JSON structure of Azure Policy
Azure Policy uses "if" to define conditions and "then" to specify what happens, but the specific action is defined by "effect".Step 2: Confirm the element that defines the action
The "effect" element tells Azure Policy what to do, like deny or audit, when the condition is met.Final Answer:
"effect" -> Option AQuick Check:
Action in Azure Policy = effect [OK]
- Confusing "then" with the action element
- Using "condition" instead of "if"
- Missing the "effect" element entirely
{
"if": {
"field": "Microsoft.Storage/storageAccounts/encryption.enabled",
"equals": false
},
"then": {
"effect": "deny"
}
}Solution
Step 1: Analyze the condition in the policy
The policy checks if encryption.enabled is false (not enabled).Step 2: Understand the effect when condition matches
The effect is "deny", so if encryption is false, creation is blocked.Final Answer:
The storage account creation will be denied -> Option BQuick Check:
Condition false + effect deny = block creation [OK]
- Thinking "deny" allows creation but logs it
- Confusing "deny" with "audit" effect
- Ignoring the condition check on encryption
{
"if": {
"field": "Microsoft.Storage/storageAccounts/encryption.enabled",
"equals": "false"
},
"then": {
"effect": "deny"
}
}Solution
Step 1: Check the data type of the "equals" value
The policy uses "equals": "false" which is a string, but encryption.enabled is a boolean.Step 2: Correct the data type to boolean
Changing "false" (string) to false (boolean) fixes the condition to match properly.Final Answer:
The value "false" should be a boolean false, not a string -> Option AQuick Check:
Boolean false, not string "false" fixes policy [OK]
- Using string "false" instead of boolean false
- Changing effect to audit instead of deny
- Assuming field name is wrong without checking
Solution
Step 1: Understand the requirement to report but not block
You want to find resources missing the tag but still allow creation.Step 2: Identify the effect that audits without blocking
The "audit" effect reports non-compliance but does not prevent resource creation.Step 3: Compare other effects
"deny" blocks creation, "append" adds properties, "deployIfNotExists" deploys resources, none just audit.Final Answer:
"audit" -> Option DQuick Check:
Audit effect reports without blocking [OK]
- Using "deny" which blocks resource creation
- Confusing "append" with audit
- Choosing "deployIfNotExists" which deploys resources
Ready to prove it?
Pass the test and this pattern moves unknown
