core: EvalApplyProvisioners correct handling of errors

The error handling here is a bit tricky due to the ability for users to
opt out of aborting on error. It's important that we keep straight the
distinction between applyDiags and diags so we can tell the difference
between the errors from _this_ provisioner and the errors for the entire
run so far.
This commit is contained in:
Martin Atkins 2018-09-14 12:25:42 -07:00
parent 4581769ba1
commit 9afb0c6c0c
3 changed files with 21 additions and 15 deletions

View File

@ -5151,7 +5151,7 @@ func TestContext2Apply_provisionerDestroyFailContinueFail(t *testing.T) {
state, diags := ctx.Apply() state, diags := ctx.Apply()
if diags == nil { if diags == nil {
t.Fatal("should error") t.Fatal("apply succeeded; wanted error from second provisioner")
} }
checkStateString(t, state, ` checkStateString(t, state, `

View File

@ -469,12 +469,18 @@ func (n *EvalApplyProvisioners) apply(ctx EvalContext, provs []*configs.Provisio
return h.PostProvisionInstanceStep(absAddr, prov.Type, applyDiags.Err()) return h.PostProvisionInstanceStep(absAddr, prov.Type, applyDiags.Err())
}) })
if diags.HasErrors() {
switch prov.OnFailure { switch prov.OnFailure {
case configs.ProvisionerOnFailureContinue: case configs.ProvisionerOnFailureContinue:
if applyDiags.HasErrors() {
log.Printf("[WARN] Errors while provisioning %s with %q, but continuing as requested in configuration", n.Addr, prov.Type) log.Printf("[WARN] Errors while provisioning %s with %q, but continuing as requested in configuration", n.Addr, prov.Type)
} else {
// Maybe there are warnings that we still want to see
diags = diags.Append(applyDiags)
}
default: default:
diags = diags.Append(applyDiags) diags = diags.Append(applyDiags)
if applyDiags.HasErrors() {
log.Printf("[WARN] Errors while provisioning %s with %q, so aborting", n.Addr, prov.Type)
return diags.Err() return diags.Err()
} }
} }