move empty provider logic to node_provider
This commit is contained in:
parent
22440539c1
commit
cd7d78968c
|
@ -48,6 +48,13 @@ func (n *NodeApplyableProvider) ValidateProvider(ctx EvalContext, provider provi
|
|||
|
||||
configBody := buildProviderConfig(ctx, n.Addr, n.ProviderConfig())
|
||||
|
||||
// if provider config is empty, return early
|
||||
emptySchema := &configschema.Block{}
|
||||
_, _, evalDiags := ctx.EvaluateBlock(configBody, emptySchema, nil, EvalDataForNoInstanceKey)
|
||||
if !evalDiags.HasErrors() {
|
||||
return nil
|
||||
}
|
||||
|
||||
resp := provider.GetSchema()
|
||||
diags = diags.Append(resp.Diagnostics)
|
||||
if diags.HasErrors() {
|
||||
|
@ -59,7 +66,7 @@ func (n *NodeApplyableProvider) ValidateProvider(ctx EvalContext, provider provi
|
|||
// 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] ValidateProvider: no config schema is available for %s, so using empty schema", n.Addr)
|
||||
configSchema = &configschema.Block{}
|
||||
configSchema = emptySchema
|
||||
}
|
||||
|
||||
configVal, configBody, evalDiags := ctx.EvaluateBlock(configBody, configSchema, nil, EvalDataForNoInstanceKey)
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform/addrs"
|
||||
"github.com/hashicorp/terraform/configs"
|
||||
"github.com/hashicorp/terraform/configs/configschema"
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
)
|
||||
|
||||
|
@ -115,3 +116,37 @@ func TestNodeApplyableProviderExecute_unknownApply(t *testing.T) {
|
|||
t.Errorf("wrong configuration value\ngot: %#v\nwant: %#v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNodeApplyableProviderExecute_emptyValidate(t *testing.T) {
|
||||
config := &configs.Provider{
|
||||
Name: "foo",
|
||||
Config: configs.SynthBody("", map[string]cty.Value{}),
|
||||
}
|
||||
provider := mockProviderWithConfigSchema(&configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"test_string": {
|
||||
Type: cty.String,
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
providerAddr := addrs.AbsProviderConfig{
|
||||
Module: addrs.RootModule,
|
||||
Provider: addrs.NewDefaultProvider("foo"),
|
||||
}
|
||||
|
||||
n := &NodeApplyableProvider{&NodeAbstractProvider{
|
||||
Addr: providerAddr,
|
||||
Config: config,
|
||||
}}
|
||||
|
||||
ctx := &MockEvalContext{ProviderProvider: provider}
|
||||
ctx.installSimpleEval()
|
||||
if err := n.Execute(ctx, walkValidate); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if ctx.ConfigureProviderCalled {
|
||||
t.Fatal("should not be called")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue