validate depends_on in module calls

Add depends_on validation to module calls, and accumulate diagnostics
for all calls rather than returning early.
This commit is contained in:
James Bardin 2020-06-16 12:39:50 -04:00
parent a8884b18e3
commit bdf5acd627
1 changed files with 13 additions and 8 deletions

View File

@ -7,6 +7,7 @@ import (
"github.com/hashicorp/terraform/configs" "github.com/hashicorp/terraform/configs"
"github.com/hashicorp/terraform/dag" "github.com/hashicorp/terraform/dag"
"github.com/hashicorp/terraform/lang" "github.com/hashicorp/terraform/lang"
"github.com/hashicorp/terraform/tfdiags"
) )
type ConcreteModuleNodeFunc func(n *nodeExpandModule) dag.Vertex type ConcreteModuleNodeFunc func(n *nodeExpandModule) dag.Vertex
@ -271,6 +272,7 @@ type evalValidateModule struct {
func (n *evalValidateModule) Eval(ctx EvalContext) (interface{}, error) { func (n *evalValidateModule) Eval(ctx EvalContext) (interface{}, error) {
_, call := n.Addr.Call() _, call := n.Addr.Call()
var diags tfdiags.Diagnostics
expander := ctx.InstanceExpander() expander := ctx.InstanceExpander()
// Modules all evaluate to single instances during validation, only to // Modules all evaluate to single instances during validation, only to
@ -285,20 +287,23 @@ func (n *evalValidateModule) Eval(ctx EvalContext) (interface{}, error) {
// a full expansion, presuming these errors will be caught in later steps // a full expansion, presuming these errors will be caught in later steps
switch { switch {
case n.ModuleCall.Count != nil: case n.ModuleCall.Count != nil:
_, diags := evaluateCountExpressionValue(n.ModuleCall.Count, ctx) _, countDiags := evaluateCountExpressionValue(n.ModuleCall.Count, ctx)
if diags.HasErrors() { diags = diags.Append(countDiags)
return nil, diags.Err()
}
case n.ModuleCall.ForEach != nil: case n.ModuleCall.ForEach != nil:
_, diags := evaluateForEachExpressionValue(n.ModuleCall.ForEach, ctx) _, forEachDiags := evaluateForEachExpressionValue(n.ModuleCall.ForEach, ctx)
if diags.HasErrors() { diags = diags.Append(forEachDiags)
return nil, diags.Err()
}
} }
diags = diags.Append(validateDependsOn(ctx, n.ModuleCall.DependsOn))
// now set our own mode to single // now set our own mode to single
expander.SetModuleSingle(module, call) expander.SetModuleSingle(module, call)
} }
if diags.HasErrors() {
return nil, diags.ErrWithWarnings()
}
return nil, nil return nil, nil
} }