Skip to content

Commit

Permalink
Force delete of old plan files in already locked PRs
Browse files Browse the repository at this point in the history
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 runatlantis#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.
  • Loading branch information
angeloskaltsikis committed Feb 12, 2021
1 parent 8aa531e commit 9b3114e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion server/events/project_command_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 9b3114e

Please sign in to comment.