Atlantis falsely claims a workspace is locked while it's not
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Searching for pre-existing feature requests helps us consolidate datapoints for identical requirements into a single place, thank you!
- Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
- If you are interested in working on this issue or have submitted a pull request, please leave a comment.
Overview of the Issue
Atlantis raise error claiming a workspace is locked but in the TF cloud UI, the workspace is not locked at all.
Ran Plan for dir: bootstrap/monitoring workspace: monitoring
Plan Error
the monitoring workspace at path bootstrap/monitoring is currently locked by another command that is running for this pull request.
Wait until the previous command is complete and try again
Reproduction Steps
Logs
Environment details
Additional Context
This issue is a known bug in Atlantis. The error occurs because Atlantis manages its own locking mechanism, which is separate from the Terraform Cloud UI locks. Specifically, Atlantis can falsely claim a workspace is locked due to the order of operations: the working directory is refreshed before the lock is checked, which can result in a stale or incorrect lock state being reported. This has been discussed in a recent issue, where it was confirmed that the lock should be checked before refreshing the working directory to avoid these false positives [source].
Atlantis locks the directory and workspace when a plan is run, and this lock persists until the pull request is merged, closed, or the plan is manually discarded. If you encounter a false lock, you can manually unlock the workspace by commenting atlantis unlock on the pull request or by discarding the plan using the link in the plan comment [source].
If you are seeing this issue frequently, it is likely due to the bug in the locking workflow. You may want to follow or contribute to the ongoing discussion and fixes in the referenced issue to stay updated on progress.
To continue talking to Dosu, mention @dosu-bot.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other
@dosubot,
We are encountering the same issue even when running a single project for a specific workspace and directory.
Ran Plan for dir: infrastructure/aws/prod/us-east-1/prod0-testing/services/rds/odin-db workspace: infrastructure_aws_prod_us-east-1_prod0-testing_services_rds_odin-db
Plan Error
the infrastructure_aws_prod_us-east-1_prod0-testing_services_rds_odin-db workspace at path infrastructure/aws/prod/us-east-1/prod0-testing/services/rds/odin-db is currently locked by another command that is running for this pull request. Wait until the previous command is complete and try again
Despite only one Atlantis project being defined for this path and workspace, we still encounter the lock error. There’s no indication in the atlantis logs of another active command. Any insights into what might be causing this lock or how to safely clear it would be appreciated.
tried running atlantis unlock which successfully return below message but post that manual atlantis plan again returns the same error mentioned above
All Atlantis locks for this PR have been unlocked and plans discarded
Possibly related to https://github.com/runatlantis/atlantis/pull/4192#issuecomment-3204874755.
If I understand correctly, the locks are not really so isolated as the first read of the code would suggest.