core: Tolerate missing provider config schema in EvalValidateProvider

This should never happen in real code, but it comes up a lot in test code
where incomplete mock schemas are being used to test with very simple
configurations.
This commit is contained in:
Martin Atkins 2018-05-11 16:46:00 -07:00
parent e4e3876332
commit b8c3b8d45d

View File

@ -2,6 +2,7 @@ package terraform
import (
"fmt"
"log"
"github.com/hashicorp/hcl2/hcl"
"github.com/hashicorp/terraform/addrs"
@ -92,6 +93,13 @@ func (n *EvalValidateProvider) Eval(ctx EvalContext) (interface{}, error) {
}
configSchema := schema.Provider
if configSchema == nil {
// Should never happen in real code, but often comes up in tests where
// mock schemas are being used that tend to be incomplete.
log.Printf("[WARN] EvalValidateProvider: no config schema is available for %s, so using empty schema", n.Addr)
configSchema = &configschema.Block{}
}
configBody := buildProviderConfig(ctx, n.Addr, sourceBody)
configVal, configBody, evalDiags := ctx.EvaluateBlock(configBody, configSchema, nil, addrs.NoKey)
diags = diags.Append(evalDiags)