From 48309835b7c94061add8cccc079c9e3d26208b42 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Mon, 23 May 2022 13:24:07 -0400 Subject: [PATCH] add unknown paths to diags for debugging When a user reports a "Configuration contains unknown value" error, there is no information on what might have been unknown during apply. Add unknown attribute paths to the diagnostic message to provide some more information when a reproduction may not be possible. Sine this is one of those "should never happen" types of errors which will be reported to the developers directly, we can leave the format as the raw internal representation for simplicity. --- .../node_resource_abstract_instance.go | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/internal/terraform/node_resource_abstract_instance.go b/internal/terraform/node_resource_abstract_instance.go index d7a7af5df8..d1e0928c00 100644 --- a/internal/terraform/node_resource_abstract_instance.go +++ b/internal/terraform/node_resource_abstract_instance.go @@ -2016,9 +2016,25 @@ func (n *NodeAbstractResourceInstance) apply( } if !configVal.IsWhollyKnown() { - diags = diags.Append(fmt.Errorf( - "configuration for %s still contains unknown values during apply (this is a bug in Terraform; please report it!)", - n.Addr, + // We don't have a pretty format function for a path, but since this is + // such a rare error, we can just drop the raw GoString values in here + // to make sure we have something to debug with. + var unknownPaths []string + cty.Transform(configVal, func(p cty.Path, v cty.Value) (cty.Value, error) { + if !v.IsKnown() { + unknownPaths = append(unknownPaths, fmt.Sprintf("%#v", p)) + } + return v, nil + }) + + diags = diags.Append(tfdiags.Sourceless( + tfdiags.Error, + "Configuration contains unknown value", + fmt.Sprintf("configuration for %s still contains unknown values during apply (this is a bug in Terraform; please report it!)\n"+ + "The following paths in the resource configuration are unknown:\n%s", + n.Addr, + strings.Join(unknownPaths, "\n"), + ), )) return nil, keyData, diags }