Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unknown paths to diags for debugging #31111

Merged
merged 1 commit into from May 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 19 additions & 3 deletions internal/terraform/node_resource_abstract_instance.go
Expand Up @@ -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"+
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this always a problem in Core, or could it be a provider bug?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a core bug in that we should have caught an unknown value before we even get here. Once we've gotten this far it's kind of too late, but hopefully at least showing which part of the config was unknown can help track down the source of the unknown value.

"The following paths in the resource configuration are unknown:\n%s",
n.Addr,
strings.Join(unknownPaths, "\n"),
),
))
return nil, keyData, diags
}
Expand Down