atlantis: Atlantis unlock fails to delete plan of environment with project name
https://github.com/runatlantis/atlantis/issues/3750 changed the behaviour of atlantis unlock which used to trigger a deletion of the whole directory where the PR is checked out in favour of only deleting the plan file.
The delete lock command however doesn’t handle configuration with project names configured, which causes issues: https://github.com/runatlantis/atlantis/blob/v0.26.0/server/events/delete_lock_command.go#L60
Reproduction Steps
Atlantis version: v0.26.0
Given an atlantis.yaml:
---
version: 3
projects:
- name: dev
dir: clusters/dev/config
workflow: dev
terraform_version: v1.5.7
autoplan:
enabled: true
when_modified:
- "*.tf*"
When an atlantis unlock is issued:
{"level":"info","ts":"2023-10-11T15:53:45.296Z","caller":"events/unlock_command_runner.go:35","msg":"Unlocking all locks","json":{"repo":"<repo>","pull":"1004"}}
{"level":"info","ts":"2023-10-11T15:53:45.300Z","caller":"events/working_dir.go:418","msg":"Deleting plan: /home/atlantis/.atlantis/repos/<repo>/1004/default/clusters/dev/config/default.tfplan","json":{}}
{"level":"warn","ts":"2023-10-11T15:53:45.300Z","caller":"events/delete_lock_command.go:68","msg":"Failed to delete plan: remove /home/atlantis/.atlantis/repos/<repo>/1004/default/clusters/dev/config/default.tfplan: no such file or directory","json":{},"stacktrace":"github.com/runatlantis/atlantis/server/events.(*DefaultDeleteLockCommand).DeleteLocksByPull\n\t/tmp/atlantis-v0.26.0/server/events/delete_lock_command.go:68\ngithub.com/runatlantis/atlantis/server/events.(*UnlockCommandRunner).Run\n\t/tmp/atlantis-v0.26.0/server/events/unlock_command_runner.go:37\ngithub.com/runatlantis/atlantis/server/events.(*DefaultCommandRunner).RunCommentCommand\n\t/tmp/atlantis-v0.26.0/server/events/command_runner.go:328"}
{"level":"error","ts":"2023-10-11T15:53:45.300Z","caller":"events/unlock_command_runner.go:40","msg":"failed to delete locks by pull remove /home/atlantis/.atlantis/repos/<repo>/1004/default/clusters/dev/config/default.tfplan: no such file or directory","json":{"repo":"<repo>","pull":"1004"},"stacktrace":"github.com/runatlantis/atlantis/server/events.(*UnlockCommandRunner).Run\n\t/tmp/atlantis-v0.26.0/server/events/unlock_command_runner.go:40\ngithub.com/runatlantis/atlantis/server/events.(*DefaultCommandRunner).RunCommentCommand\n\t/tmp/atlantis-v0.26.0/server/events/command_runner.go:328"}
The plan file is actually named dev-default.tfplan after fmt.Sprintf("%s-%s.tfplan", projName, workspace).
A workaround is to remove project names from the Atlantis config and rely only on dir names.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 28
- Comments: 27 (19 by maintainers)
Hello everyone, we will revert #3751. I approved the change and actually was worried about this very issue. We have been working to better understand the differences between locks and filesystem operations. I apologize for the disruptions.
The code is spread out across the lock controllers, command controllers, and a special library for file system operation for “WorkingDir”. I appreciate everyones patience as we continue to streamline and optimize these operations. It makes more sense to properly support project locks across the codebase before making these changes.
No
The workaround doesn’t cover my use case as well. Is there any way to get to the previous behaviour?
@X-Guardian
Unfortunately this workaround does not suit me. Without project name it is really inconvenient since the path is really long and in gh issue summary(CI block check) contains base path that is common for all all projects +
...As a result I do not know what the project this(Not informative). Also previously i used atlantis plan -p <project name> and without project name the command is different and need to pass directory and workspace.Moreover I liked that Atlantis removed the whole workspace during unlock(when I need to free disk space) and for me it would be better to control via option(like -cleanup-worksapce-on-unclock): https://github.com/runatlantis/atlantis/pull/3751
Are you planing to fix this?
To clarify, this revert may not result in a “full revert” but there will be at a minimum, a revert in functionality. We are still debating options internally on the core team. Most likely solution is a new PR that will keep both behaviors, gated by a configuration flag.
FYI, I do not use the
nameparameter and I still hit this issue. Snippet from my root level atlantis.yamlHi @jamengual 😃
We just upgraded our Atlantis version to get the fix for this issue and unfortunately it came back after some time, i.e, we tried to run the atlantis unlock on a PR and then we got the Failed to delete PR locks message. Checking our Atlantis logs, we found the following:
failed to delete locks by pull remove /atlantis-data/repos/*****/****/1006/default/staging/*****.tfplan: no such file or directoryHave you seen any error similar to this one since this fix is live?
@jamengual Indeed, this did not happen in a new PR, ensuring that it was opened after atlantis was upgraded to 0.27.2
Thanks!
OK, meanwhile I will have to rollback to 0.25.0 because I have a pileup of PRs that won’t unlock that I keep having to unlock manually.
For those who have issues with the way that unlock is working now, I will ask that if you have the time and golang knowledge to fix it, please create a PR for it. #3751 fixed other issues with unlock that people took for granted, but in fact, this behaviour was not correct from the beginning.
We are trying to avoid adding more flags so we could add this to the repo.config if is needed.