Skip to content

Commit

Permalink
Fix code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gezb committed Aug 4, 2021
1 parent 2aa183d commit 391ce5d
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions server/events/project_command_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,26 +316,27 @@ func (p *DefaultProjectCommandRunner) doPlan(ctx models.ProjectCommandContext) (

lockFileName := ".terraform.lock.hcl"
lockfilePath := filepath.Join(projAbsPath, lockFileName)
lockFileExistsProirToPlan := common.FileExists(lockfilePath)
lockFileExistsPriorToPlan := common.FileExists(lockfilePath)

outputs, err := p.runSteps(ctx.Steps, ctx, projAbsPath)
if err != nil {
if unlockErr := lockAttempt.UnlockFn(); unlockErr != nil {
ctx.Log.Err("error unlocking state after plan error: %v", unlockErr)
}
if !lockFileExistsProirToPlan && common.FileExists(lockfilePath) {
// if the lock file did not exist before running the plan delete the lock file that was generated
// by terraform init so that on subsequent actions modules and providers are not locked to the versions
// detected as a part of this plan
ctx.Log.Debug("Deleting `%s` that was generated by terraform init", lockFileName)
delErr := os.Remove(lockfilePath)
if delErr != nil {
ctx.Log.Info("Error Deleting `%s`", lockFileName)
}
}
return nil, "", fmt.Errorf("%s\n%s", err, strings.Join(outputs, "\n"))
}

if !lockFileExistsPriorToPlan && common.FileExists(lockfilePath) {
// if the lock file did not exist before running the plan delete the lock file that was generated
// by terraform init so that on subsequent actions modules and providers are not locked to the versions
// detected as a part of this plan
ctx.Log.Debug("Deleting `%s` that was generated by terraform init", lockFileName)
delErr := os.Remove(lockfilePath)
if delErr != nil {
ctx.Log.Info("Error Deleting `%s`", lockFileName)
}
}

return &models.PlanSuccess{
LockURL: p.LockURLGenerator.GenerateLockURL(lockAttempt.LockKey),
TerraformOutput: strings.Join(outputs, "\n"),
Expand Down

0 comments on commit 391ce5d

Please sign in to comment.