Resource locks (delete, read-only) in Azure - Time & Space Complexity
When managing Azure resources, applying locks helps protect them from unwanted changes. Understanding how the time to apply or check these locks grows is important for smooth operations.
We want to know: how does the time to manage locks change as the number of resources grows?
Analyze the time complexity of applying a delete lock to multiple resources.
// Loop through a list of resource IDs
foreach (var resourceId in resourceIds) {
// Apply a delete lock to each resource
azure.Locks.Define("DeleteLock")
.WithLockedResource(resourceId)
.WithDeleteLock()
.Create();
}
This sequence applies a delete lock to each resource one by one to prevent accidental deletion.
Look at what repeats as we apply locks:
- Primary operation: API call to create a lock on a single resource.
- How many times: Once for each resource in the list.
Each resource requires one API call to apply the lock. So, if you have more resources, you make more calls.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 calls |
| 100 | 100 calls |
| 1000 | 1000 calls |
Pattern observation: The number of API calls grows directly with the number of resources.
Time Complexity: O(n)
This means the time to apply locks grows in a straight line as you add more resources.
[X] Wrong: "Applying a lock to multiple resources happens all at once, so time stays the same no matter how many resources."
[OK] Correct: Each lock requires a separate API call, so more resources mean more calls and more time.
Understanding how operations scale with resource count shows you can plan and manage cloud infrastructure efficiently. This skill helps you design systems that stay reliable as they grow.
"What if we batch apply locks using a single API call for multiple resources? How would the time complexity change?"
Practice
CanNotDelete resource lock do in Azure?Solution
Step 1: Understand the purpose of CanNotDelete lock
The CanNotDelete lock is designed to stop accidental deletion of a resource but still allows changes to it.Step 2: Compare with other lock types
Unlike ReadOnly, which blocks all changes, CanNotDelete only blocks deletion but permits modifications.Final Answer:
Prevents deletion but allows modifications to the resource -> Option DQuick Check:
CanNotDelete = Prevent deletion, allow changes [OK]
- Confusing CanNotDelete with ReadOnly lock
- Thinking CanNotDelete blocks all changes
- Assuming CanNotDelete allows deletion
Solution
Step 1: Identify the correct property name for lock level
The correct property to specify the lock type is "level" with values like "ReadOnly" or "CanNotDelete".Step 2: Match the correct JSON structure
{ "level": "ReadOnly", "notes": "Block all changes" } uses "level": "ReadOnly" which is the correct syntax to create a ReadOnly lock.Final Answer:
{ "level": "ReadOnly", "notes": "Block all changes" } -> Option CQuick Check:
Lock level property = "level" with value "ReadOnly" [OK]
- Using incorrect property names like lockLevel or lock
- Confusing CanNotDelete with ReadOnly in JSON
- Missing quotes around property names or values
Solution
Step 1: Understand ReadOnly lock behavior
A ReadOnly lock blocks all changes to the resource, including updates, but allows reading.Step 2: Predict the outcome of an update attempt
Trying to update a resource with ReadOnly lock will cause a permission error and the update will fail.Final Answer:
The update will fail with a permission error -> Option AQuick Check:
ReadOnly lock blocks updates = update fails [OK]
- Assuming updates succeed with ReadOnly lock
- Confusing ReadOnly with CanNotDelete lock
- Thinking updates are queued instead of blocked
Solution
Step 1: Understand CanNotDelete lock effect
CanNotDelete lock prevents deletion of the resource it is applied to.Step 2: Analyze why deletion still happened
If deletion occurred, the lock was likely not applied or saved correctly on the storage account.Final Answer:
The lock was not saved or applied correctly -> Option BQuick Check:
Lock must be properly applied to prevent deletion [OK]
- Assuming Owner role bypasses locks (it does not)
- Confusing lock scope levels
- Thinking ReadOnly lock prevents deletion
Solution
Step 1: Determine lock for VM to prevent deletion but allow changes
Use CanNotDelete lock on VM to block deletion but allow configuration changes.Step 2: Determine lock for storage account to block all changes except reading
Use ReadOnly lock on storage account to block all changes but allow reading.Final Answer:
Apply CanNotDelete lock on VM and ReadOnly lock on storage account -> Option AQuick Check:
CanNotDelete = block delete, ReadOnly = block all changes [OK]
- Swapping lock types between resources
- Using ReadOnly lock where changes are needed
- Applying same lock to both resources without need
Ready to prove it?
Pass the test and this pattern moves unknown
