fix: preserve Atlantis apply lock after plan #5570
fix: preserve Atlantis apply lock after plan #5570jamengual merged 3 commits intorunatlantis:mainfrom
Conversation
Signed-off-by: yasinlachiny <your-email@example.com>
7711a4f to
559c7a5
Compare
…kError_False Signed-off-by: yasinlachiny <yasin.lachiny@gmail.com>
|
Hi @jamengual, Could you please re-run the test? It passes on my local machine: Thanks in advance! |
jamengual
left a comment
There was a problem hiding this comment.
The change looks good to me @yasinlachiny thanks for the contribution
Signed-off-by: yasinlachiny <your-email@example.com> Signed-off-by: yasinlachiny <yasin.lachiny@gmail.com> Co-authored-by: yasinlachiny <your_email@example.com> Co-authored-by: PePe Amengual <2208324+jamengual@users.noreply.github.com> Signed-off-by: PePe Amengual <2208324+jamengual@users.noreply.github.com>
Signed-off-by: yasinlachiny <your-email@example.com> Signed-off-by: yasinlachiny <yasin.lachiny@gmail.com> Co-authored-by: yasinlachiny <your_email@example.com> Co-authored-by: PePe Amengual <2208324+jamengual@users.noreply.github.com> Signed-off-by: Joseph McDonald <jojosr2000@gmail.com>
|
We've observed similar behavior where the lock was being removed on re-plan. This is definitely an improvement over what we've currently observed. However, is "remove the lock if a subsequent plan has changes" really the expected correct behavior? I would expect the lock to be held from the time an apply is made until the PR is merged unless explicitly unlocked. |
|
Holding the lock even after changes are made can lead to a major issue: if we update the PR, the same PR still holds the lock, preventing us from applying again. So, in cases where there are changes, it's necessary to release the lock to allow a new apply to proceed. |
|
I'm not familiar with the internals here, but I would expect the lock to be associated with the PR and subsequent applies to be allowed for the same PR holding the lock. |
|
atlantis apply doesn't allow this, even within the same PR, because it would enable multiple apply operations to run at the same time. |
|
Is that true? Doesn't that mean multiple apply operations could run at the same time as-is after removing the lock when new changes are detected since no lock exists? |
|
It removes lock on plan not apply |
Signed-off-by: yasinlachiny <your-email@example.com> Signed-off-by: yasinlachiny <yasin.lachiny@gmail.com> Co-authored-by: yasinlachiny <your_email@example.com> Co-authored-by: PePe Amengual <2208324+jamengual@users.noreply.github.com> Signed-off-by: Moritz Wirth <mw@flanga.io>
This reverts commit 59f16ef.
This fixes a critical bug introduced in commit 59f16ef (PR #5570) where the unlock key format didn't match the lock key format, causing locks to never be released properly. The issue: - Locks are created with key format: repo/path/workspace - Unlocks were attempted with format: repo/pullnum/projectname/workspace - This mismatch meant locks were never actually released This particularly affected users with multiple projects in the same directory using different .tfvars files, as they would encounter "workspace is currently locked" errors when trying to apply multiple projects. The fix: - Changed unlock key to match the lock key format: repo/path/workspace - Updated corresponding test to expect the correct format Fixes #5722 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
When PR #5570 added logic to preserve apply locks after plan when no changes are detected, it introduced a bug in the unlock key format. The lock key uses: repo/path/workspace But the unlock key was using: repo/pullnum/projectname/workspace This mismatch caused locks to never be released, blocking subsequent operations on projects in the same directory. This commit fixes the unlock key to match the lock key format. Fixes #5722 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
When PR #5570 added logic to preserve apply locks after plan when no changes are detected, it introduced a bug in the unlock key format. The lock key uses: repo/path/workspace But the unlock key was using: repo/pullnum/projectname/workspace This mismatch caused locks to never be released, blocking subsequent operations on projects in the same directory. This commit fixes the unlock key to match the lock key format. Fixes #5722 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…deletion Remove the premature lock deletion logic introduced in PR #5570 that was causing e2e test failures. This logic incorrectly unlocked projects immediately after plan operations when changes were detected, which broke the intended workflow where locks should remain until PR close/merge. The issue was causing "missing expected replies" errors in e2e tests because: 1. Plan detects changes → locks get deleted immediately after plan 2. PR gets merged → UnlockByPull finds no locks to unlock 3. No unlock comment is generated → tests expect 4 replies but get 3 This fix restores the original behavior where locks persist through the entire PR lifecycle and are only cleaned up when the PR is closed/merged, which generates the expected unlock comment. Fixes the e2e test failures reported in the CI where tests were expecting unlock comments but not receiving them. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…behavior Restore the UnlockByPull calls that were removed when PR #5570 introduced individual project unlock logic. These calls are needed in: 1. Generic plan command when deleting previous plans 2. Automerge error handling in both autoplan and plan commands 3. Test expectations reverted to original behavior This ensures locks are properly released when plans are deleted, which the original tests were verifying before PR #5570 changed the behavior. The fix maintains the original behavior where UnlockByPull is called whenever plans are deleted, ensuring proper cleanup of all locks associated with the pull request.
…deletion Remove the premature lock deletion logic introduced in PR #5570 that was causing e2e test failures. This logic incorrectly unlocked projects immediately after plan operations when changes were detected, which broke the intended workflow where locks should remain until PR close/merge. The issue was causing "missing expected replies" errors in e2e tests because: 1. Plan detects changes → locks get deleted immediately after plan 2. PR gets merged → UnlockByPull finds no locks to unlock 3. No unlock comment is generated → tests expect 4 replies but get 3 Changes made: - Remove individual project unlock loop from plan command runner - Restore UnlockByPull calls in generic plan and automerge error handling - Revert test expectations to original pre-PR#5570 behavior This fix restores the original behavior where locks persist through the entire PR lifecycle and are only cleaned up when the PR is closed/merged, which generates the expected unlock comment. Fixes the e2e test failures where tests were expecting unlock comments but not receiving them.
Signed-off-by: yasinlachiny <your-email@example.com> Signed-off-by: yasinlachiny <yasin.lachiny@gmail.com> Co-authored-by: yasinlachiny <your_email@example.com> Co-authored-by: PePe Amengual <2208324+jamengual@users.noreply.github.com> Signed-off-by: dimisjim <dimitris.moraitidis@gmail.com>
what
Updated Atlantis behavior to retain the apply lock when re-running plan if there are no changes.
Ensured the lock is only removed when actual changes are detected between re-runs
why
Addresses community-reported issue #5568 where users observed unintended lock removals during no-op plans.
Fixes an issue where Atlantis incorrectly removes the apply lock when a plan is re-run, even if no changes are detected.
Preserves expected workflow and safety in CI/CD pipelines by preventing premature unlocks
tests
✅ Manually tested locally:
Created an apply lock by running plan and apply.
Re-ran plan without making any changes — lock was preserved as expected.
Introduced a change and re-ran plan — lock was correctly removed.
Verified this behavior in a multi-project repository setup.
references
Fixes: #5568