Policy assignments and compliance in Azure - Time & Space Complexity
We want to understand how the time to check policy compliance changes as we assign policies to more resources.
How does the number of policy assignments affect the work Azure does to check compliance?
Analyze the time complexity of the following operation sequence.
// Assign a policy to multiple resources
for (let resource of resources) {
await client.policyAssignments.create({
scope: resource.id,
policyDefinitionId: policyId
});
}
// Check compliance state for each assignment
for (let assignment of policyAssignments) {
await client.policyStates.listQueryResultsForResource(assignment.scope);
}
This sequence assigns a policy to many resources and then checks compliance for each assignment.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Creating policy assignments and querying compliance states.
- How many times: Once per resource for assignment and once per assignment for compliance check.
As the number of resources grows, the number of API calls grows roughly the same way.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | About 20 calls (10 assignments + 10 compliance checks) |
| 100 | About 200 calls (100 assignments + 100 compliance checks) |
| 1000 | About 2000 calls (1000 assignments + 1000 compliance checks) |
Pattern observation: The total work grows linearly with the number of resources.
Time Complexity: O(n)
This means the time to assign policies and check compliance grows directly in proportion to the number of resources.
[X] Wrong: "Assigning one policy to many resources is a single operation and takes the same time regardless of resource count."
[OK] Correct: Each resource requires a separate assignment and compliance check, so time grows with the number of resources.
Understanding how policy assignments scale helps you design efficient governance in cloud environments and shows you can think about system behavior as it grows.
"What if we batch policy assignments instead of assigning one by one? How would the time complexity change?"
Practice
Solution
Step 1: Understand policy assignment role and compare options
Policy assignments are used to enforce rules or standards on Azure resources. Only To apply rules to cloud resources to control their behavior describes applying rules to control resource behavior, which matches policy assignments.Final Answer:
To apply rules to cloud resources to control their behavior -> Option CQuick Check:
Policy assignment = apply rules [OK]
- Confusing policy assignments with resource creation
- Thinking policies monitor traffic or backup data
- Mixing policy assignments with alerts or logs
Solution
Step 1: Recall Azure CLI syntax for policy assignment and validate options
The correct command uses 'az policy assignment create' with --name, --scope, and --policy parameters. az policy assignment create --name MyPolicy --scope /subscriptions/{subId}/resourceGroups/{rgName} --policy {policyDefinitionId} matches the correct syntax. Others use incorrect commands or parameters.Final Answer:
az policy assignment create --name MyPolicy --scope /subscriptions/{subId}/resourceGroups/{rgName} --policy {policyDefinitionId} -> Option AQuick Check:
Correct CLI syntax = az policy assignment create --name MyPolicy --scope /subscriptions/{subId}/resourceGroups/{rgName} --policy {policyDefinitionId} [OK]
- Using 'az policy create' instead of 'az policy assignment create'
- Confusing resource group with scope format
- Using wrong parameter names like --definition
{"complianceState": "NonCompliant", "resourceId": "/subscriptions/123/resourceGroups/rg1/providers/Microsoft.Compute/virtualMachines/vm1"}What does this indicate?
Solution
Step 1: Interpret complianceState value and match to meaning
The value 'NonCompliant' means the resource does not meet the policy requirements. Since vm1 is NonCompliant, it does not follow the assigned policy rules.Final Answer:
The virtual machine vm1 does not follow the assigned policy rules -> Option DQuick Check:
NonCompliant means policy not followed [OK]
- Assuming NonCompliant means policy applied successfully
- Confusing NonCompliant with Unknown or Compliant
- Thinking complianceState shows assignment failure
Solution
Step 1: Understand policy evaluation timing and eliminate other causes
Policy compliance data can take time to appear after assignment due to evaluation delays. Incorrect scope or missing parameters usually cause errors, not empty compliance. Wrong CLI command would fail assignment.Final Answer:
The resources are not evaluated yet or policy evaluation is delayed -> Option AQuick Check:
Compliance delay causes no data [OK]
- Assuming wrong CLI command always causes no data
- Thinking missing parameters prevent compliance data
- Ignoring evaluation delay after assignment
Solution
Step 1: Understand policy exclusion parameter effect and confirm behavior on excluded resources
Excluding a resource group means resources there are not evaluated or enforced by the policy. Excluded storage accounts are ignored by the policy, so no enforcement or compliance checks occur.Final Answer:
They will not be evaluated or enforced by the policy -> Option BQuick Check:
Exclusion skips evaluation and enforcement [OK]
- Thinking excluded resources are still checked but allowed
- Assuming policy forces compliance despite exclusions
- Believing exclusions cause assignment failure
Ready to prove it?
Pass the test and this pattern moves unknown
