From c4f44b8656f37af61b7770d04a880f4b2cec8d91 Mon Sep 17 00:00:00 2001 From: angeloskaltsikis Date: Fri, 12 Feb 2021 16:32:35 +0200 Subject: [PATCH] Force delete of old plan files in already locked PRs There is an edge case in which if the plan files for modules (1),(2) have been already created for a commit (a) in a PR and then the user understands that he made a mistake and he didn't want to change module (2) and drops the terraform code of it in commit (b), then when the user will try to run the apply command Atlantis will apply the (2) module plan file as well as the `PendingPlanFinder.Find` finds all the differences between the upstream branch and what Atlantis contains and filters out the `.tfplan` files. There is an issue connected to this bug https://github.com/runatlantis/atlantis/issues/1122 In order to mitigate the above bug after some careful consideration it seems that the best solution is to drop all the plan files in case the PR has been locked anytime in the past, which translates that it most likely have created `.tfplan` files. This commit is not expected to create any side-effects or introduce any new problems. --- server/events/project_command_builder.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/server/events/project_command_builder.go b/server/events/project_command_builder.go index 54ff76c962..e576e25a54 100644 --- a/server/events/project_command_builder.go +++ b/server/events/project_command_builder.go @@ -178,7 +178,21 @@ func (p *DefaultProjectCommandBuilder) buildPlanAllCommands(ctx *CommandContext, // the actual clone directory. } } - + pullDir, err := p.WorkingDir.GetPullDir(ctx.Pull.BaseRepo, ctx.Pull) + if err != nil { + return nil, err + } + // Check if the PR has been already locked and if so drop all pending plans + locked, err := p.WorkingDirLocker.IsPullLocked(ctx.Pull.BaseRepo.FullName, ctx.Pull.Num) + if err != nil { + return nil, err + } + if locked { + errDeletePlans := p.PendingPlanFinder.DeletePlans(pullDir) + if errDeletePlans != nil { + return nil, errDeletePlans + } + } // Need to lock the workspace we're about to clone to. workspace := DefaultWorkspace