Skip to content

Commit be49fbd

Browse files
committed
generate nicer errors
1 parent 2084154 commit be49fbd

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

internal/terraform/node_action_validate.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,28 @@ func (n *NodeValidatableAction) Execute(ctx EvalContext, _ walkOperation) tfdiag
8282
return diags
8383
}
8484

85-
// If the action has no "config" attribute at all, we'll send the provider
86-
// an empty body - config = {} and omitted config entirely are the same, internally.
87-
var config hcl.Body
85+
config := n.Config.Config
8886
if n.Config.Config == nil {
8987
config = hcl.EmptyBody()
90-
} else {
91-
config = n.Config.Config
9288
}
89+
9390
configVal, _, valDiags := ctx.EvaluateBlock(config, schema.ConfigSchema, nil, keyData)
94-
diags = diags.Append(valDiags)
9591
if valDiags.HasErrors() {
96-
return diags
92+
// If there was no config block at all, we'll build a more-detailed diagnostic with Subject range
93+
if n.Config.Config == nil {
94+
for _, diag := range valDiags {
95+
diags = diags.Append(&hcl.Diagnostic{
96+
Severity: diag.Severity().ToHCL(),
97+
Summary: diag.Description().Summary,
98+
Detail: diag.Description().Detail,
99+
Subject: &n.Config.DeclRange,
100+
})
101+
}
102+
return diags
103+
} else {
104+
diags = diags.Append(valDiags)
105+
return diags
106+
}
97107
}
98108

99109
// Use unmarked value for validate request

0 commit comments

Comments
 (0)