don't persist a nil state from Apply

Apply should not return a nil state to be persisted.
This commit is contained in:
James Bardin 2021-12-17 11:29:12 -05:00
parent 58e001c22a
commit 8c4031ef15
1 changed files with 8 additions and 0 deletions

View File

@ -168,6 +168,14 @@ func (b *Local) opApply(
}
diags = diags.Append(applyDiags)
// Even on error with an empty state, the state value should not be nil.
// Return early here to prevent corrupting any existing state.
if diags.HasErrors() && applyState == nil {
log.Printf("[ERROR] backend/local: apply returned nil state")
op.ReportResult(runningOp, diags)
return
}
// Store the final state
runningOp.State = applyState
err := statemgr.WriteAndPersist(opState, applyState)