core: EvalValidateProvider must always call provider.Validate

Previously we were skipping all of the validation steps if a provider was
being configured implicitly, and thus had no block in configuration.

This is incorrect, since a provider must still get an opportunity to
configure itself with an empty configuration and possibly reject that
empty configuration with errors.
This commit is contained in:
Martin Atkins 2018-05-11 16:37:58 -07:00
parent b031e18332
commit e4e3876332

View File

@ -71,11 +71,15 @@ type EvalValidateProvider struct {
func (n *EvalValidateProvider) Eval(ctx EvalContext) (interface{}, error) { func (n *EvalValidateProvider) Eval(ctx EvalContext) (interface{}, error) {
var diags tfdiags.Diagnostics var diags tfdiags.Diagnostics
provider := *n.Provider provider := *n.Provider
config := n.Config
if n.Config == nil { var sourceBody hcl.Body
// Nothing to validate, then. if n.Config != nil && n.Config.Config != nil {
return nil, nil sourceBody = n.Config.Config
} else {
// If the provider configuration is implicit (no block in configuration
// but referred to by resources) then we'll assume an empty body
// as a placeholder.
sourceBody = hcl.EmptyBody()
} }
schema, err := provider.GetSchema(&ProviderSchemaRequest{}) schema, err := provider.GetSchema(&ProviderSchemaRequest{})
@ -88,7 +92,7 @@ func (n *EvalValidateProvider) Eval(ctx EvalContext) (interface{}, error) {
} }
configSchema := schema.Provider configSchema := schema.Provider
configBody := buildProviderConfig(ctx, n.Addr, config.Config) configBody := buildProviderConfig(ctx, n.Addr, sourceBody)
configVal, configBody, evalDiags := ctx.EvaluateBlock(configBody, configSchema, nil, addrs.NoKey) configVal, configBody, evalDiags := ctx.EvaluateBlock(configBody, configSchema, nil, addrs.NoKey)
diags = diags.Append(evalDiags) diags = diags.Append(evalDiags)
if evalDiags.HasErrors() { if evalDiags.HasErrors() {