feat: add azapi locks to agent pool resources to prevent concurrent modifications#160
Merged
matt-FFFFFF merged 1 commit intomainfrom Feb 24, 2026
Merged
feat: add azapi locks to agent pool resources to prevent concurrent modifications#160matt-FFFFFF merged 1 commit intomainfrom
matt-FFFFFF merged 1 commit intomainfrom
Conversation
|
Important The "Needs: Triage 🔍" label must be removed once the triage process is complete! Tip For additional guidance on how to triage this issue/PR, see the Terraform Issue Triage documentation. |
There was a problem hiding this comment.
Pull request overview
This PR adds resource locking to prevent concurrent modifications to AKS agent pools, addressing race conditions that occur when multiple agent pools are managed under a single cluster. The AKS API does not support concurrent operations on agent pools within the same cluster, leading to 409 Conflict errors during parallel Terraform operations.
Changes:
- Added
locks = [var.parent_id]to agent pool resources in the agentpool module to serialize operations on the parent cluster - Added
locks = [azapi_resource.this.id]to the default agent pool update resource to maintain consistency - Applied formatting changes from
terraform fmtto align property definitions
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
modules/agentpool/main.tf |
Added locks parameter to both azapi_resource.this and azapi_resource.this_create_before_destroy resources, locking on var.parent_id to prevent concurrent agent pool modifications on the same cluster |
main.default_agent_pool.tf |
Added locks parameter to azapi_update_resource.default_agent_pool, locking on azapi_resource.this.id to ensure consistent locking behavior for the default agent pool |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
locksto allazapi_resourceandazapi_update_resourceblocks for agent pools, locking on the parent AKS cluster resource ID (parent_idorazapi_resource.this.id)Motivation
When multiple agent pools are managed under a single AKS cluster, Terraform may attempt to create, update, or delete them concurrently. The AKS API does not support concurrent modifications to agent pools on the same cluster, which can lead to:
409 Conflicterrors from the Azure APIThe
locksargument inazapiensures that operations on agent pools targeting the same parent cluster are serialized, eliminating these race conditions.Changes
main.default_agent_pool.tflocks = [azapi_resource.this.id]toazapi_update_resource.default_agent_poolmodules/agentpool/main.tflocks = [var.parent_id]to bothazapi_resource.thisandazapi_resource.this_create_before_destroyTesting
./avm pre-commitpassed./avm pr-checkpassed (linting, docs, tflint, grept, mapotf, avmfix, well-architected)