always report condition errors

The status in the face of errors didn't matter before, because we never
wrote out a plan with errors.
This commit is contained in:
James Bardin 2022-12-14 14:45:01 -05:00
parent 5aa088e385
commit bb5f360747
2 changed files with 14 additions and 1 deletions

View File

@ -3379,10 +3379,15 @@ func TestContext2Plan_preconditionErrors(t *testing.T) {
`, tc.condition)
m := testModuleInline(t, map[string]string{"main.tf": main})
_, diags := ctx.Plan(m, states.NewState(), DefaultPlanOpts)
plan, diags := ctx.Plan(m, states.NewState(), DefaultPlanOpts)
if !diags.HasErrors() {
t.Fatal("succeeded; want errors")
}
if !plan.Errored {
t.Fatal("plan failed to record error")
}
diag := diags[0]
if got, want := diag.Description().Summary, tc.wantSummary; got != want {
t.Errorf("unexpected summary\n got: %s\nwant: %s", got, want)
@ -3390,6 +3395,13 @@ func TestContext2Plan_preconditionErrors(t *testing.T) {
if got, want := diag.Description().Detail, tc.wantDetail; !strings.Contains(got, want) {
t.Errorf("unexpected summary\ngot: %s\nwant to contain %q", got, want)
}
for _, kv := range plan.Checks.ConfigResults.Elements() {
// All these are configuration or evaluation errors
if kv.Value.Status != checks.StatusError {
t.Errorf("incorrect status, got %s", kv.Value.Status)
}
}
})
}
}

View File

@ -103,6 +103,7 @@ func evalCheckRule(typ addrs.CheckType, rule *configs.CheckRule, ctx EvalContext
if diags.HasErrors() {
log.Printf("[TRACE] evalCheckRule: %s: %s", typ, diags.Err().Error())
return checkResult{Status: checks.StatusError}, diags
}
if !resultVal.IsKnown() {