Merge pull request #28724 from hashicorp/jbardin/apply-diags
save apply diagnostics on backend failure
This commit is contained in:
commit
e39ba2816b
|
@ -165,6 +165,7 @@ func (b *Local) opApply(
|
|||
if b.opWait(doneCh, stopCtx, cancelCtx, tfCtx, opState, op.View) {
|
||||
return
|
||||
}
|
||||
diags = diags.Append(applyDiags)
|
||||
|
||||
// Store the final state
|
||||
runningOp.State = applyState
|
||||
|
@ -183,7 +184,6 @@ func (b *Local) opApply(
|
|||
return
|
||||
}
|
||||
|
||||
diags = diags.Append(applyDiags)
|
||||
if applyDiags.HasErrors() {
|
||||
op.ReportResult(runningOp, diags)
|
||||
return
|
||||
|
|
|
@ -212,10 +212,14 @@ func TestLocal_applyBackendFail(t *testing.T) {
|
|||
defer cleanup()
|
||||
|
||||
p := TestLocalProvider(t, b, "test", applyFixtureSchema())
|
||||
p.ApplyResourceChangeResponse = &providers.ApplyResourceChangeResponse{NewState: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("yes"),
|
||||
"ami": cty.StringVal("bar"),
|
||||
})}
|
||||
|
||||
p.ApplyResourceChangeResponse = &providers.ApplyResourceChangeResponse{
|
||||
NewState: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("yes"),
|
||||
"ami": cty.StringVal("bar"),
|
||||
}),
|
||||
Diagnostics: tfdiags.Diagnostics.Append(nil, errors.New("error before backend failure")),
|
||||
}
|
||||
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
|
@ -245,14 +249,19 @@ func TestLocal_applyBackendFail(t *testing.T) {
|
|||
}
|
||||
|
||||
diagErr := output.Stderr()
|
||||
|
||||
if !strings.Contains(diagErr, "Error saving state: fake failure") {
|
||||
t.Fatalf("missing \"fake failure\" message in diags:\n%s", diagErr)
|
||||
}
|
||||
|
||||
if !strings.Contains(diagErr, "error before backend failure") {
|
||||
t.Fatalf("missing 'error before backend failure' diagnostic from apply")
|
||||
}
|
||||
|
||||
// The fallback behavior should've created a file errored.tfstate in the
|
||||
// current working directory.
|
||||
checkState(t, "errored.tfstate", `
|
||||
test_instance.foo:
|
||||
test_instance.foo: (tainted)
|
||||
ID = yes
|
||||
provider = provider["registry.terraform.io/hashicorp/test"]
|
||||
ami = bar
|
||||
|
|
Loading…
Reference in New Issue