@ -6,6 +6,8 @@ import (
"path/filepath"
"path/filepath"
"strings"
"strings"
"github.com/zclconf/go-cty/cty"
"github.com/hashicorp/terraform/terraform"
"github.com/hashicorp/terraform/terraform"
"github.com/hashicorp/terraform/tfdiags"
"github.com/hashicorp/terraform/tfdiags"
)
)
@ -119,8 +121,27 @@ func (c *ValidateCommand) validate(dir string) tfdiags.Diagnostics {
return diags
return diags
}
}
// "validate" is to check if the given module is valid regardless of
// input values, current state, etc. Therefore we populate all of the
// input values with unknown values of the expected type, allowing us
// to perform a type check without assuming any particular values.
varValues := make ( terraform . InputValues )
for name , variable := range cfg . Module . Variables {
ty := variable . Type
if ty == cty . NilType {
// Can't predict the type at all, so we'll just mark it as
// cty.DynamicVal (unknown value of cty.DynamicPseudoType).
ty = cty . DynamicPseudoType
}
varValues [ name ] = & terraform . InputValue {
Value : cty . UnknownVal ( ty ) ,
SourceType : terraform . ValueFromCLIArg ,
}
}
opts := c . contextOpts ( )
opts := c . contextOpts ( )
opts . Config = cfg
opts . Config = cfg
opts . Variables = varValues
tfCtx , ctxDiags := terraform . NewContext ( opts )
tfCtx , ctxDiags := terraform . NewContext ( opts )
diags = diags . Append ( ctxDiags )
diags = diags . Append ( ctxDiags )