From 2dd64a7816598d08fb06c17d27cbfb5b8c0e81da Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Fri, 5 Jun 2020 12:08:10 -0700 Subject: [PATCH] plans: Update error message for apply validation (#21312) * Update error message for apply validation Add a hint that the validation failure has occurred at the root of the resource schema to the error message. This is because the root resource has an empty path when being validated and the path is being relied upon to provide context into the error message. --- plans/objchange/compatible.go | 9 +++++++-- terraform/eval_apply.go | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/plans/objchange/compatible.go b/plans/objchange/compatible.go index d85086c97..8b3aeedbf 100644 --- a/plans/objchange/compatible.go +++ b/plans/objchange/compatible.go @@ -28,12 +28,17 @@ func AssertObjectCompatible(schema *configschema.Block, planned, actual cty.Valu func assertObjectCompatible(schema *configschema.Block, planned, actual cty.Value, path cty.Path) []error { var errs []error + var atRoot string + if len(path) == 0 { + atRoot = "Root resource " + } + if planned.IsNull() && !actual.IsNull() { - errs = append(errs, path.NewErrorf("was absent, but now present")) + errs = append(errs, path.NewErrorf(fmt.Sprintf("%swas absent, but now present", atRoot))) return errs } if actual.IsNull() && !planned.IsNull() { - errs = append(errs, path.NewErrorf("was present, but now absent")) + errs = append(errs, path.NewErrorf(fmt.Sprintf("%swas present, but now absent", atRoot))) return errs } if planned.IsNull() { diff --git a/terraform/eval_apply.go b/terraform/eval_apply.go index 6c9ed41ba..00af310bb 100644 --- a/terraform/eval_apply.go +++ b/terraform/eval_apply.go @@ -245,7 +245,7 @@ func (n *EvalApply) Eval(ctx EvalContext) (interface{}, error) { tfdiags.Error, "Provider produced inconsistent result after apply", fmt.Sprintf( - "When applying changes to %s, provider %q produced an unexpected new value for %s.\n\nThis is a bug in the provider, which should be reported in the provider's own issue tracker.", + "When applying changes to %s, provider %q produced an unexpected new value: %s.\n\nThis is a bug in the provider, which should be reported in the provider's own issue tracker.", absAddr, n.ProviderAddr.Provider.String(), tfdiags.FormatError(err), ), ))