change mock provider to use GetSchemaResponse

This ensures that test providers are using the same types as actual
providers.
This commit is contained in:
James Bardin 2021-01-11 15:45:50 -05:00
parent 5fe848b642
commit 7dd570ef6c
16 changed files with 726 additions and 614 deletions

View File

@ -94,7 +94,7 @@ func TestContext2Apply_unstable(t *testing.T) {
Type: "test_resource", Type: "test_resource",
Name: "foo", Name: "foo",
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance) }.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance)
schema := p.GetSchemaReturn.ResourceTypes["test_resource"] // automatically available in mock schema := p.GetSchemaResponse.ResourceTypes["test_resource"].Block
rds := plan.Changes.ResourceInstance(addr) rds := plan.Changes.ResourceInstance(addr)
rd, err := rds.Decode(schema.ImpliedType()) rd, err := rds.Decode(schema.ImpliedType())
if err != nil { if err != nil {
@ -1600,7 +1600,7 @@ func TestContext2Apply_destroyCrossProviders(t *testing.T) {
p_aws := testProvider("aws") p_aws := testProvider("aws")
p_aws.ApplyResourceChangeFn = testApplyFn p_aws.ApplyResourceChangeFn = testApplyFn
p_aws.PlanResourceChangeFn = testDiffFn p_aws.PlanResourceChangeFn = testDiffFn
p_aws.GetSchemaReturn = &ProviderSchema{ p_aws.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"aws_instance": { "aws_instance": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -1623,7 +1623,7 @@ func TestContext2Apply_destroyCrossProviders(t *testing.T) {
}, },
}, },
}, },
} })
providers := map[addrs.Provider]providers.Factory{ providers := map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p_aws), addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p_aws),
@ -1939,7 +1939,7 @@ func TestContext2Apply_compute(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"aws_instance": { "aws_instance": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -1974,7 +1974,7 @@ func TestContext2Apply_compute(t *testing.T) {
}, },
}, },
}, },
} })
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Config: m, Config: m,
@ -2438,7 +2438,7 @@ func TestContext2Apply_moduleDestroyOrder(t *testing.T) {
return resp return resp
} }
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"aws_instance": { "aws_instance": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -2448,7 +2448,7 @@ func TestContext2Apply_moduleDestroyOrder(t *testing.T) {
}, },
}, },
}, },
} })
state := states.NewState() state := states.NewState()
child := state.EnsureModule(addrs.RootModuleInstance.Child("child", addrs.NoKey)) child := state.EnsureModule(addrs.RootModuleInstance.Child("child", addrs.NoKey))
@ -2559,7 +2559,7 @@ func TestContext2Apply_orphanResource(t *testing.T) {
p := testProvider("test") p := testProvider("test")
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"test_thing": { "test_thing": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -2568,7 +2568,7 @@ func TestContext2Apply_orphanResource(t *testing.T) {
}, },
}, },
}, },
} })
// Step 1: create the resources and instances // Step 1: create the resources and instances
m := testModule(t, "apply-orphan-resource") m := testModule(t, "apply-orphan-resource")
@ -3172,7 +3172,7 @@ func TestContext2Apply_multiProviderDestroy(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{ Provider: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"addr": {Type: cty.String, Optional: true}, "addr": {Type: cty.String, Optional: true},
@ -3186,12 +3186,12 @@ func TestContext2Apply_multiProviderDestroy(t *testing.T) {
}, },
}, },
}, },
} })
p2 := testProvider("vault") p2 := testProvider("vault")
p2.ApplyResourceChangeFn = testApplyFn p2.ApplyResourceChangeFn = testApplyFn
p2.PlanResourceChangeFn = testDiffFn p2.PlanResourceChangeFn = testDiffFn
p2.GetSchemaReturn = &ProviderSchema{ p2.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"vault_instance": { "vault_instance": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -3199,7 +3199,7 @@ func TestContext2Apply_multiProviderDestroy(t *testing.T) {
}, },
}, },
}, },
} })
var state *states.State var state *states.State
@ -3293,7 +3293,7 @@ func TestContext2Apply_multiProviderDestroyChild(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{ Provider: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"value": {Type: cty.String, Optional: true}, "value": {Type: cty.String, Optional: true},
@ -3307,12 +3307,12 @@ func TestContext2Apply_multiProviderDestroyChild(t *testing.T) {
}, },
}, },
}, },
} })
p2 := testProvider("vault") p2 := testProvider("vault")
p2.ApplyResourceChangeFn = testApplyFn p2.ApplyResourceChangeFn = testApplyFn
p2.PlanResourceChangeFn = testDiffFn p2.PlanResourceChangeFn = testDiffFn
p2.GetSchemaReturn = &ProviderSchema{ p2.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{}, Provider: &configschema.Block{},
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"vault_instance": { "vault_instance": {
@ -3321,7 +3321,7 @@ func TestContext2Apply_multiProviderDestroyChild(t *testing.T) {
}, },
}, },
}, },
} })
var state *states.State var state *states.State
@ -3530,7 +3530,7 @@ func TestContext2Apply_multiVarComprehensive(t *testing.T) {
} }
} }
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"test_thing": { "test_thing": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -3552,7 +3552,7 @@ func TestContext2Apply_multiVarComprehensive(t *testing.T) {
}, },
}, },
}, },
} })
// First, apply with a count of 3 // First, apply with a count of 3
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
@ -3880,7 +3880,7 @@ func TestContext2Apply_multiVarMissingState(t *testing.T) {
p := testProvider("test") p := testProvider("test")
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"test_thing": { "test_thing": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -3889,7 +3889,7 @@ func TestContext2Apply_multiVarMissingState(t *testing.T) {
}, },
}, },
}, },
} })
// First, apply with a count of 3 // First, apply with a count of 3
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
@ -4447,7 +4447,7 @@ func TestContext2Apply_multiDepose_createBeforeDestroy(t *testing.T) {
m := testModule(t, "apply-multi-depose-create-before-destroy") m := testModule(t, "apply-multi-depose-create-before-destroy")
p := testProvider("aws") p := testProvider("aws")
ps := map[addrs.Provider]providers.Factory{addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p)} ps := map[addrs.Provider]providers.Factory{addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p)}
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"aws_instance": { "aws_instance": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -4456,7 +4456,7 @@ func TestContext2Apply_multiDepose_createBeforeDestroy(t *testing.T) {
}, },
}, },
}, },
} })
state := states.NewState() state := states.NewState()
root := state.EnsureModule(addrs.RootModuleInstance) root := state.EnsureModule(addrs.RootModuleInstance)
@ -6328,7 +6328,7 @@ func TestContext2Apply_errorDestroy(t *testing.T) {
m := testModule(t, "empty") m := testModule(t, "empty")
p := testProvider("test") p := testProvider("test")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"test_thing": { "test_thing": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -6336,7 +6336,7 @@ func TestContext2Apply_errorDestroy(t *testing.T) {
}, },
}, },
}, },
} })
p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse {
// Should actually be called for this test, because Terraform Core // Should actually be called for this test, because Terraform Core
// constructs the plan for a destroy operation itself. // constructs the plan for a destroy operation itself.
@ -6401,7 +6401,7 @@ func TestContext2Apply_errorCreateInvalidNew(t *testing.T) {
m := testModule(t, "apply-error") m := testModule(t, "apply-error")
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"aws_instance": { "aws_instance": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -6410,7 +6410,7 @@ func TestContext2Apply_errorCreateInvalidNew(t *testing.T) {
}, },
}, },
}, },
} })
p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse {
return providers.PlanResourceChangeResponse{ return providers.PlanResourceChangeResponse{
PlannedState: req.ProposedNewState, PlannedState: req.ProposedNewState,
@ -6465,7 +6465,7 @@ func TestContext2Apply_errorUpdateNullNew(t *testing.T) {
m := testModule(t, "apply-error") m := testModule(t, "apply-error")
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"aws_instance": { "aws_instance": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -6474,7 +6474,7 @@ func TestContext2Apply_errorUpdateNullNew(t *testing.T) {
}, },
}, },
}, },
} })
p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse {
return providers.PlanResourceChangeResponse{ return providers.PlanResourceChangeResponse{
PlannedState: req.ProposedNewState, PlannedState: req.ProposedNewState,
@ -7713,7 +7713,7 @@ func TestContext2Apply_unknownAttribute(t *testing.T) {
return resp return resp
} }
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"aws_instance": { "aws_instance": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -7724,7 +7724,7 @@ func TestContext2Apply_unknownAttribute(t *testing.T) {
}, },
}, },
}, },
} })
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Config: m, Config: m,
@ -8074,7 +8074,7 @@ func TestContext2Apply_issue7824(t *testing.T) {
p := testProvider("template") p := testProvider("template")
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"template_file": { "template_file": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -8083,7 +8083,7 @@ func TestContext2Apply_issue7824(t *testing.T) {
}, },
}, },
}, },
} })
m, snap := testModuleWithSnapshot(t, "issue-7824") m, snap := testModuleWithSnapshot(t, "issue-7824")
@ -8130,7 +8130,7 @@ func TestContext2Apply_issue5254(t *testing.T) {
p := testProvider("template") p := testProvider("template")
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"template_file": { "template_file": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -8141,7 +8141,7 @@ func TestContext2Apply_issue5254(t *testing.T) {
}, },
}, },
}, },
} })
// Apply cleanly step 0 // Apply cleanly step 0
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
@ -8297,7 +8297,7 @@ func TestContext2Apply_ignoreChangesCreate(t *testing.T) {
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
instanceSchema := p.GetSchemaReturn.ResourceTypes["aws_instance"] instanceSchema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block
instanceSchema.Attributes["required_field"] = &configschema.Attribute{ instanceSchema.Attributes["required_field"] = &configschema.Attribute{
Type: cty.String, Type: cty.String,
Required: true, Required: true,
@ -8441,7 +8441,7 @@ func TestContext2Apply_ignoreChangesWildcard(t *testing.T) {
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
instanceSchema := p.GetSchemaReturn.ResourceTypes["aws_instance"] instanceSchema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block
instanceSchema.Attributes["required_field"] = &configschema.Attribute{ instanceSchema.Attributes["required_field"] = &configschema.Attribute{
Type: cty.String, Type: cty.String,
Required: true, Required: true,
@ -9248,7 +9248,7 @@ func TestContext2Apply_scaleInMultivarRef(t *testing.T) {
func TestContext2Apply_inconsistentWithPlan(t *testing.T) { func TestContext2Apply_inconsistentWithPlan(t *testing.T) {
m := testModule(t, "apply-inconsistent-with-plan") m := testModule(t, "apply-inconsistent-with-plan")
p := testProvider("test") p := testProvider("test")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"test": { "test": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -9256,7 +9256,7 @@ func TestContext2Apply_inconsistentWithPlan(t *testing.T) {
}, },
}, },
}, },
} })
p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse {
return providers.PlanResourceChangeResponse{ return providers.PlanResourceChangeResponse{
PlannedState: cty.ObjectVal(map[string]cty.Value{ PlannedState: cty.ObjectVal(map[string]cty.Value{
@ -9301,7 +9301,7 @@ func TestContext2Apply_inconsistentWithPlan(t *testing.T) {
func TestContext2Apply_issue19908(t *testing.T) { func TestContext2Apply_issue19908(t *testing.T) {
m := testModule(t, "apply-issue19908") m := testModule(t, "apply-issue19908")
p := testProvider("test") p := testProvider("test")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"test": { "test": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -9309,7 +9309,7 @@ func TestContext2Apply_issue19908(t *testing.T) {
}, },
}, },
}, },
} })
p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse {
return providers.PlanResourceChangeResponse{ return providers.PlanResourceChangeResponse{
PlannedState: req.ProposedNewState, PlannedState: req.ProposedNewState,
@ -9382,7 +9382,7 @@ func TestContext2Apply_issue19908(t *testing.T) {
func TestContext2Apply_invalidIndexRef(t *testing.T) { func TestContext2Apply_invalidIndexRef(t *testing.T) {
p := testProvider("test") p := testProvider("test")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"test_instance": { "test_instance": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -9390,7 +9390,7 @@ func TestContext2Apply_invalidIndexRef(t *testing.T) {
}, },
}, },
}, },
} })
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
m := testModule(t, "apply-invalid-index") m := testModule(t, "apply-invalid-index")
@ -9440,11 +9440,11 @@ func TestContext2Apply_moduleReplaceCycle(t *testing.T) {
}, },
} }
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"aws_instance": instanceSchema, "aws_instance": instanceSchema,
}, },
} })
state := states.NewState() state := states.NewState()
modA := state.EnsureModule(addrs.RootModuleInstance.Child("a", addrs.NoKey)) modA := state.EnsureModule(addrs.RootModuleInstance.Child("a", addrs.NoKey))
@ -9715,7 +9715,7 @@ func TestContext2Apply_taintedDestroyFailure(t *testing.T) {
return testApplyFn(req) return testApplyFn(req)
} }
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"test_instance": { "test_instance": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -9730,7 +9730,7 @@ func TestContext2Apply_taintedDestroyFailure(t *testing.T) {
}, },
}, },
}, },
} })
state := states.NewState() state := states.NewState()
root := state.EnsureModule(addrs.RootModuleInstance) root := state.EnsureModule(addrs.RootModuleInstance)
@ -10037,7 +10037,7 @@ func TestContext2Apply_ProviderMeta_apply_set(t *testing.T) {
m := testModule(t, "provider-meta-set") m := testModule(t, "provider-meta-set")
p := testProvider("test") p := testProvider("test")
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
schema := p.GetSchemaReturn schema := p.ProviderSchema()
schema.ProviderMeta = &configschema.Block{ schema.ProviderMeta = &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"baz": { "baz": {
@ -10064,7 +10064,7 @@ func TestContext2Apply_ProviderMeta_apply_set(t *testing.T) {
NewState: cty.ObjectVal(s), NewState: cty.ObjectVal(s),
} }
} }
p.GetSchemaReturn = schema p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Config: m, Config: m,
Providers: map[addrs.Provider]providers.Factory{ Providers: map[addrs.Provider]providers.Factory{
@ -10120,7 +10120,7 @@ func TestContext2Apply_ProviderMeta_apply_unset(t *testing.T) {
m := testModule(t, "provider-meta-unset") m := testModule(t, "provider-meta-unset")
p := testProvider("test") p := testProvider("test")
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
schema := p.GetSchemaReturn schema := p.ProviderSchema()
schema.ProviderMeta = &configschema.Block{ schema.ProviderMeta = &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"baz": { "baz": {
@ -10145,7 +10145,7 @@ func TestContext2Apply_ProviderMeta_apply_unset(t *testing.T) {
NewState: cty.ObjectVal(s), NewState: cty.ObjectVal(s),
} }
} }
p.GetSchemaReturn = schema p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Config: m, Config: m,
Providers: map[addrs.Provider]providers.Factory{ Providers: map[addrs.Provider]providers.Factory{
@ -10180,7 +10180,7 @@ func TestContext2Apply_ProviderMeta_plan_set(t *testing.T) {
m := testModule(t, "provider-meta-set") m := testModule(t, "provider-meta-set")
p := testProvider("test") p := testProvider("test")
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
schema := p.GetSchemaReturn schema := p.ProviderSchema()
schema.ProviderMeta = &configschema.Block{ schema.ProviderMeta = &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"baz": { "baz": {
@ -10196,7 +10196,7 @@ func TestContext2Apply_ProviderMeta_plan_set(t *testing.T) {
PlannedState: req.ProposedNewState, PlannedState: req.ProposedNewState,
} }
} }
p.GetSchemaReturn = schema p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Config: m, Config: m,
Providers: map[addrs.Provider]providers.Factory{ Providers: map[addrs.Provider]providers.Factory{
@ -10249,7 +10249,7 @@ func TestContext2Apply_ProviderMeta_plan_unset(t *testing.T) {
m := testModule(t, "provider-meta-unset") m := testModule(t, "provider-meta-unset")
p := testProvider("test") p := testProvider("test")
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
schema := p.GetSchemaReturn schema := p.ProviderSchema()
schema.ProviderMeta = &configschema.Block{ schema.ProviderMeta = &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"baz": { "baz": {
@ -10265,7 +10265,7 @@ func TestContext2Apply_ProviderMeta_plan_unset(t *testing.T) {
PlannedState: req.ProposedNewState, PlannedState: req.ProposedNewState,
} }
} }
p.GetSchemaReturn = schema p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Config: m, Config: m,
Providers: map[addrs.Provider]providers.Factory{ Providers: map[addrs.Provider]providers.Factory{
@ -10338,7 +10338,7 @@ func TestContext2Apply_ProviderMeta_plan_setInvalid(t *testing.T) {
p := testProvider("test") p := testProvider("test")
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
schema := p.GetSchemaReturn schema := p.ProviderSchema()
schema.ProviderMeta = &configschema.Block{ schema.ProviderMeta = &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"quux": { "quux": {
@ -10347,7 +10347,7 @@ func TestContext2Apply_ProviderMeta_plan_setInvalid(t *testing.T) {
}, },
}, },
} }
p.GetSchemaReturn = schema p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Config: m, Config: m,
Providers: map[addrs.Provider]providers.Factory{ Providers: map[addrs.Provider]providers.Factory{
@ -10392,7 +10392,7 @@ func TestContext2Apply_ProviderMeta_refresh_set(t *testing.T) {
p := testProvider("test") p := testProvider("test")
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
schema := p.GetSchemaReturn schema := p.ProviderSchema()
schema.ProviderMeta = &configschema.Block{ schema.ProviderMeta = &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"baz": { "baz": {
@ -10404,14 +10404,14 @@ func TestContext2Apply_ProviderMeta_refresh_set(t *testing.T) {
rrcPMs := map[string]cty.Value{} rrcPMs := map[string]cty.Value{}
p.ReadResourceFn = func(req providers.ReadResourceRequest) (resp providers.ReadResourceResponse) { p.ReadResourceFn = func(req providers.ReadResourceRequest) (resp providers.ReadResourceResponse) {
rrcPMs[req.TypeName] = req.ProviderMeta rrcPMs[req.TypeName] = req.ProviderMeta
newState, err := p.GetSchemaReturn.ResourceTypes[req.TypeName].CoerceValue(req.PriorState) newState, err := p.GetSchemaResponse.ResourceTypes[req.TypeName].Block.CoerceValue(req.PriorState)
if err != nil { if err != nil {
panic(err) panic(err)
} }
resp.NewState = newState resp.NewState = newState
return resp return resp
} }
p.GetSchemaReturn = schema p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Config: m, Config: m,
Providers: map[addrs.Provider]providers.Factory{ Providers: map[addrs.Provider]providers.Factory{
@ -10473,7 +10473,7 @@ func TestContext2Apply_ProviderMeta_refresh_setNoSchema(t *testing.T) {
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
// we need a schema for plan/apply so they don't error // we need a schema for plan/apply so they don't error
schema := p.GetSchemaReturn schema := p.ProviderSchema()
schema.ProviderMeta = &configschema.Block{ schema.ProviderMeta = &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"baz": { "baz": {
@ -10482,7 +10482,7 @@ func TestContext2Apply_ProviderMeta_refresh_setNoSchema(t *testing.T) {
}, },
}, },
} }
p.GetSchemaReturn = schema p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Config: m, Config: m,
Providers: map[addrs.Provider]providers.Factory{ Providers: map[addrs.Provider]providers.Factory{
@ -10498,7 +10498,7 @@ func TestContext2Apply_ProviderMeta_refresh_setNoSchema(t *testing.T) {
// drop the schema before refresh, to test that it errors // drop the schema before refresh, to test that it errors
schema.ProviderMeta = nil schema.ProviderMeta = nil
p.GetSchemaReturn = schema p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
ctx = testContext2(t, &ContextOpts{ ctx = testContext2(t, &ContextOpts{
Config: m, Config: m,
Providers: map[addrs.Provider]providers.Factory{ Providers: map[addrs.Provider]providers.Factory{
@ -10542,7 +10542,7 @@ func TestContext2Apply_ProviderMeta_refresh_setInvalid(t *testing.T) {
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
// we need a matching schema for plan/apply so they don't error // we need a matching schema for plan/apply so they don't error
schema := p.GetSchemaReturn schema := p.ProviderSchema()
schema.ProviderMeta = &configschema.Block{ schema.ProviderMeta = &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"baz": { "baz": {
@ -10551,7 +10551,7 @@ func TestContext2Apply_ProviderMeta_refresh_setInvalid(t *testing.T) {
}, },
}, },
} }
p.GetSchemaReturn = schema p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Config: m, Config: m,
Providers: map[addrs.Provider]providers.Factory{ Providers: map[addrs.Provider]providers.Factory{
@ -10574,7 +10574,7 @@ func TestContext2Apply_ProviderMeta_refresh_setInvalid(t *testing.T) {
}, },
}, },
} }
p.GetSchemaReturn = schema p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
ctx = testContext2(t, &ContextOpts{ ctx = testContext2(t, &ContextOpts{
Config: m, Config: m,
Providers: map[addrs.Provider]providers.Factory{ Providers: map[addrs.Provider]providers.Factory{
@ -10620,7 +10620,7 @@ func TestContext2Apply_ProviderMeta_refreshdata_set(t *testing.T) {
p := testProvider("test") p := testProvider("test")
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
schema := p.GetSchemaReturn schema := p.ProviderSchema()
schema.ProviderMeta = &configschema.Block{ schema.ProviderMeta = &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"baz": { "baz": {
@ -10629,7 +10629,7 @@ func TestContext2Apply_ProviderMeta_refreshdata_set(t *testing.T) {
}, },
}, },
} }
p.GetSchemaReturn = schema p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Config: m, Config: m,
Providers: map[addrs.Provider]providers.Factory{ Providers: map[addrs.Provider]providers.Factory{
@ -10716,7 +10716,7 @@ func TestContext2Apply_ProviderMeta_refreshdata_unset(t *testing.T) {
p := testProvider("test") p := testProvider("test")
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
schema := p.GetSchemaReturn schema := p.ProviderSchema()
schema.ProviderMeta = &configschema.Block{ schema.ProviderMeta = &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"baz": { "baz": {
@ -10725,7 +10725,7 @@ func TestContext2Apply_ProviderMeta_refreshdata_unset(t *testing.T) {
}, },
}, },
} }
p.GetSchemaReturn = schema p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Config: m, Config: m,
Providers: map[addrs.Provider]providers.Factory{ Providers: map[addrs.Provider]providers.Factory{
@ -10831,7 +10831,7 @@ func TestContext2Apply_ProviderMeta_refreshdata_setInvalid(t *testing.T) {
p := testProvider("test") p := testProvider("test")
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
schema := p.GetSchemaReturn schema := p.ProviderSchema()
schema.ProviderMeta = &configschema.Block{ schema.ProviderMeta = &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"quux": { "quux": {
@ -10840,7 +10840,7 @@ func TestContext2Apply_ProviderMeta_refreshdata_setInvalid(t *testing.T) {
}, },
}, },
} }
p.GetSchemaReturn = schema p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Config: m, Config: m,
Providers: map[addrs.Provider]providers.Factory{ Providers: map[addrs.Provider]providers.Factory{
@ -11466,7 +11466,7 @@ output "output" {
testP.ReadResourceFn = func(req providers.ReadResourceRequest) providers.ReadResourceResponse { testP.ReadResourceFn = func(req providers.ReadResourceRequest) providers.ReadResourceResponse {
return providers.ReadResourceResponse{NewState: req.PriorState} return providers.ReadResourceResponse{NewState: req.PriorState}
} }
testP.GetSchemaReturn = schemaFn("test") testP.GetSchemaResponse = getSchemaResponseFromProviderSchema(schemaFn("test"))
providerConfig := "" providerConfig := ""
testP.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { testP.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) {
@ -11491,7 +11491,7 @@ output "output" {
nullP.ReadResourceFn = func(req providers.ReadResourceRequest) providers.ReadResourceResponse { nullP.ReadResourceFn = func(req providers.ReadResourceRequest) providers.ReadResourceResponse {
return providers.ReadResourceResponse{NewState: req.PriorState} return providers.ReadResourceResponse{NewState: req.PriorState}
} }
nullP.GetSchemaReturn = schemaFn("null") nullP.GetSchemaResponse = getSchemaResponseFromProviderSchema(schemaFn("null"))
nullP.ApplyResourceChangeFn = testApplyFn nullP.ApplyResourceChangeFn = testApplyFn
nullP.PlanResourceChangeFn = testDiffFn nullP.PlanResourceChangeFn = testDiffFn
@ -11880,7 +11880,7 @@ resource "test_resource" "foo" {
p.ReadResourceFn = func(req providers.ReadResourceRequest) providers.ReadResourceResponse { p.ReadResourceFn = func(req providers.ReadResourceRequest) providers.ReadResourceResponse {
return providers.ReadResourceResponse{NewState: req.PriorState} return providers.ReadResourceResponse{NewState: req.PriorState}
} }
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{}, Provider: &configschema.Block{},
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"test_resource": { "test_resource": {
@ -11908,7 +11908,7 @@ resource "test_resource" "foo" {
}, },
}, },
}, },
} })
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
@ -12384,7 +12384,7 @@ resource "test_instance" "a" {
return resp return resp
} }
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"test_instance": { "test_instance": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -12392,7 +12392,7 @@ resource "test_instance" "a" {
}, },
}, },
}, },
} })
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Config: m, Config: m,

View File

@ -654,7 +654,7 @@ func TestContextImport_multiState(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
m := testModule(t, "import-provider") m := testModule(t, "import-provider")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{ Provider: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
@ -672,7 +672,7 @@ func TestContextImport_multiState(t *testing.T) {
}, },
}, },
}, },
} })
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{ p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
ImportedResources: []providers.ImportedResource{ ImportedResources: []providers.ImportedResource{
@ -723,7 +723,7 @@ func TestContextImport_multiStateSame(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
m := testModule(t, "import-provider") m := testModule(t, "import-provider")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{ Provider: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
@ -741,7 +741,7 @@ func TestContextImport_multiStateSame(t *testing.T) {
}, },
}, },
}, },
} })
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{ p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
ImportedResources: []providers.ImportedResource{ ImportedResources: []providers.ImportedResource{
@ -829,7 +829,7 @@ resource "test_resource" "unused" {
`, `,
}) })
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{ Provider: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
@ -842,7 +842,7 @@ resource "test_resource" "unused" {
}, },
}, },
}, },
} })
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{ p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
ImportedResources: []providers.ImportedResource{ ImportedResources: []providers.ImportedResource{

View File

@ -19,7 +19,7 @@ func TestContext2Input_provider(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{ Provider: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": { "foo": {
@ -39,7 +39,7 @@ func TestContext2Input_provider(t *testing.T) {
}, },
}, },
}, },
} })
inp := &MockUIInput{ inp := &MockUIInput{
InputReturnMap: map[string]string{ InputReturnMap: map[string]string{
@ -91,7 +91,7 @@ func TestContext2Input_providerMulti(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{ Provider: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": { "foo": {
@ -111,7 +111,7 @@ func TestContext2Input_providerMulti(t *testing.T) {
}, },
}, },
}, },
} })
inp := &MockUIInput{ inp := &MockUIInput{
InputReturnMap: map[string]string{ InputReturnMap: map[string]string{
@ -180,7 +180,7 @@ func TestContext2Input_providerId(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{ Provider: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": { "foo": {
@ -200,7 +200,7 @@ func TestContext2Input_providerId(t *testing.T) {
}, },
}, },
}, },
} })
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Config: m, Config: m,
@ -245,7 +245,7 @@ func TestContext2Input_providerOnly(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{ Provider: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": { "foo": {
@ -263,7 +263,7 @@ func TestContext2Input_providerOnly(t *testing.T) {
}, },
}, },
}, },
} })
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Config: m, Config: m,
@ -405,7 +405,7 @@ func TestContext2Input_dataSourceRequiresRefresh(t *testing.T) {
p := testProvider("null") p := testProvider("null")
m := testModule(t, "input-module-data-vars") m := testModule(t, "input-module-data-vars")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
DataSources: map[string]*configschema.Block{ DataSources: map[string]*configschema.Block{
"null_data_source": { "null_data_source": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -413,7 +413,7 @@ func TestContext2Input_dataSourceRequiresRefresh(t *testing.T) {
}, },
}, },
}, },
} })
p.ReadDataSourceFn = func(req providers.ReadDataSourceRequest) providers.ReadDataSourceResponse { p.ReadDataSourceFn = func(req providers.ReadDataSourceRequest) providers.ReadDataSourceResponse {
return providers.ReadDataSourceResponse{ return providers.ReadDataSourceResponse{
State: req.Config, State: req.Config,

File diff suppressed because it is too large Load Diff

View File

@ -41,7 +41,7 @@ func TestContext2Refresh(t *testing.T) {
State: state, State: state,
}) })
schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block
ty := schema.ImpliedType() ty := schema.ImpliedType()
readState, err := hcl2shim.HCL2ValueFromFlatmap(map[string]string{"id": "foo", "foo": "baz"}, ty) readState, err := hcl2shim.HCL2ValueFromFlatmap(map[string]string{"id": "foo", "foo": "baz"}, ty)
if err != nil { if err != nil {
@ -105,7 +105,7 @@ func TestContext2Refresh_dynamicAttr(t *testing.T) {
}) })
p := testProvider("test") p := testProvider("test")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"test_instance": { "test_instance": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -113,7 +113,7 @@ func TestContext2Refresh_dynamicAttr(t *testing.T) {
}, },
}, },
}, },
} })
p.ReadResourceFn = func(req providers.ReadResourceRequest) providers.ReadResourceResponse { p.ReadResourceFn = func(req providers.ReadResourceRequest) providers.ReadResourceResponse {
return providers.ReadResourceResponse{ return providers.ReadResourceResponse{
NewState: readStateVal, NewState: readStateVal,
@ -132,7 +132,7 @@ func TestContext2Refresh_dynamicAttr(t *testing.T) {
State: startingState, State: startingState,
}) })
schema := p.GetSchemaReturn.ResourceTypes["test_instance"] schema := p.GetSchemaResponse.ResourceTypes["test_instance"].Block
ty := schema.ImpliedType() ty := schema.ImpliedType()
s, diags := ctx.Refresh() s, diags := ctx.Refresh()
@ -169,7 +169,7 @@ func TestContext2Refresh_dataComputedModuleVar(t *testing.T) {
return resp return resp
} }
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{}, Provider: &configschema.Block{},
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"aws_instance": { "aws_instance": {
@ -199,7 +199,7 @@ func TestContext2Refresh_dataComputedModuleVar(t *testing.T) {
}, },
}, },
}, },
} })
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Config: m, Config: m,
@ -220,7 +220,7 @@ func TestContext2Refresh_dataComputedModuleVar(t *testing.T) {
func TestContext2Refresh_targeted(t *testing.T) { func TestContext2Refresh_targeted(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{}, Provider: &configschema.Block{},
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"aws_elb": { "aws_elb": {
@ -252,7 +252,7 @@ func TestContext2Refresh_targeted(t *testing.T) {
}, },
}, },
}, },
} })
state := states.NewState() state := states.NewState()
root := state.EnsureModule(addrs.RootModuleInstance) root := state.EnsureModule(addrs.RootModuleInstance)
@ -297,7 +297,7 @@ func TestContext2Refresh_targeted(t *testing.T) {
func TestContext2Refresh_targetedCount(t *testing.T) { func TestContext2Refresh_targetedCount(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{}, Provider: &configschema.Block{},
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"aws_elb": { "aws_elb": {
@ -329,7 +329,7 @@ func TestContext2Refresh_targetedCount(t *testing.T) {
}, },
}, },
}, },
} })
state := states.NewState() state := states.NewState()
root := state.EnsureModule(addrs.RootModuleInstance) root := state.EnsureModule(addrs.RootModuleInstance)
@ -384,7 +384,7 @@ func TestContext2Refresh_targetedCount(t *testing.T) {
func TestContext2Refresh_targetedCountIndex(t *testing.T) { func TestContext2Refresh_targetedCountIndex(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{}, Provider: &configschema.Block{},
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"aws_elb": { "aws_elb": {
@ -416,7 +416,7 @@ func TestContext2Refresh_targetedCountIndex(t *testing.T) {
}, },
}, },
}, },
} })
state := states.NewState() state := states.NewState()
root := state.EnsureModule(addrs.RootModuleInstance) root := state.EnsureModule(addrs.RootModuleInstance)
@ -463,7 +463,7 @@ func TestContext2Refresh_targetedCountIndex(t *testing.T) {
func TestContext2Refresh_moduleComputedVar(t *testing.T) { func TestContext2Refresh_moduleComputedVar(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{}, Provider: &configschema.Block{},
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"aws_instance": { "aws_instance": {
@ -479,7 +479,7 @@ func TestContext2Refresh_moduleComputedVar(t *testing.T) {
}, },
}, },
}, },
} })
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
m := testModule(t, "refresh-module-computed-var") m := testModule(t, "refresh-module-computed-var")
@ -515,7 +515,7 @@ func TestContext2Refresh_delete(t *testing.T) {
p.ReadResourceFn = nil p.ReadResourceFn = nil
p.ReadResourceResponse = &providers.ReadResourceResponse{ p.ReadResourceResponse = &providers.ReadResourceResponse{
NewState: cty.NullVal(p.GetSchemaReturn.ResourceTypes["aws_instance"].ImpliedType()), NewState: cty.NullVal(p.GetSchemaResponse.ResourceTypes["aws_instance"].Block.ImpliedType()),
} }
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
@ -641,7 +641,7 @@ func TestContext2Refresh_moduleInputComputedOutput(t *testing.T) {
m := testModule(t, "refresh-module-input-computed-output") m := testModule(t, "refresh-module-input-computed-output")
p := testProvider("aws") p := testProvider("aws")
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{}, Provider: &configschema.Block{},
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"aws_instance": { "aws_instance": {
@ -658,7 +658,7 @@ func TestContext2Refresh_moduleInputComputedOutput(t *testing.T) {
}, },
}, },
}, },
} })
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Config: m, Config: m,
@ -714,7 +714,7 @@ func TestContext2Refresh_noState(t *testing.T) {
func TestContext2Refresh_output(t *testing.T) { func TestContext2Refresh_output(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{}, Provider: &configschema.Block{},
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"aws_instance": { "aws_instance": {
@ -731,7 +731,7 @@ func TestContext2Refresh_output(t *testing.T) {
}, },
}, },
}, },
} })
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
m := testModule(t, "refresh-output") m := testModule(t, "refresh-output")
@ -770,7 +770,7 @@ func TestContext2Refresh_outputPartial(t *testing.T) {
// we need to make DiffFn available to let that complete. // we need to make DiffFn available to let that complete.
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{}, Provider: &configschema.Block{},
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"aws_instance": { "aws_instance": {
@ -782,11 +782,11 @@ func TestContext2Refresh_outputPartial(t *testing.T) {
}, },
}, },
}, },
} })
p.ReadResourceFn = nil p.ReadResourceFn = nil
p.ReadResourceResponse = &providers.ReadResourceResponse{ p.ReadResourceResponse = &providers.ReadResourceResponse{
NewState: cty.NullVal(p.GetSchemaReturn.ResourceTypes["aws_instance"].ImpliedType()), NewState: cty.NullVal(p.GetSchemaResponse.ResourceTypes["aws_instance"].Block.ImpliedType()),
} }
state := states.NewState() state := states.NewState()
@ -829,7 +829,7 @@ func TestContext2Refresh_stateBasic(t *testing.T) {
State: state, State: state,
}) })
schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block
ty := schema.ImpliedType() ty := schema.ImpliedType()
readStateVal, err := schema.CoerceValue(cty.ObjectVal(map[string]cty.Value{ readStateVal, err := schema.CoerceValue(cty.ObjectVal(map[string]cty.Value{
@ -875,7 +875,7 @@ func TestContext2Refresh_dataCount(t *testing.T) {
resp.PlannedState = cty.ObjectVal(m) resp.PlannedState = cty.ObjectVal(m)
return resp return resp
} }
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"test": { "test": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -887,7 +887,7 @@ func TestContext2Refresh_dataCount(t *testing.T) {
DataSources: map[string]*configschema.Block{ DataSources: map[string]*configschema.Block{
"test": {}, "test": {},
}, },
} })
p.ReadDataSourceFn = func(req providers.ReadDataSourceRequest) providers.ReadDataSourceResponse { p.ReadDataSourceFn = func(req providers.ReadDataSourceRequest) providers.ReadDataSourceResponse {
return providers.ReadDataSourceResponse{ return providers.ReadDataSourceResponse{
@ -924,12 +924,12 @@ func TestContext2Refresh_dataState(t *testing.T) {
} }
p := testProvider("null") p := testProvider("null")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{}, Provider: &configschema.Block{},
DataSources: map[string]*configschema.Block{ DataSources: map[string]*configschema.Block{
"null_data_source": schema, "null_data_source": schema,
}, },
} })
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Config: m, Config: m,
@ -974,7 +974,7 @@ func TestContext2Refresh_dataState(t *testing.T) {
func TestContext2Refresh_dataStateRefData(t *testing.T) { func TestContext2Refresh_dataStateRefData(t *testing.T) {
p := testProvider("null") p := testProvider("null")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{}, Provider: &configschema.Block{},
DataSources: map[string]*configschema.Block{ DataSources: map[string]*configschema.Block{
"null_data_source": { "null_data_source": {
@ -994,7 +994,7 @@ func TestContext2Refresh_dataStateRefData(t *testing.T) {
}, },
}, },
}, },
} })
m := testModule(t, "refresh-data-ref-data") m := testModule(t, "refresh-data-ref-data")
state := states.NewState() state := states.NewState()
@ -1115,10 +1115,10 @@ func TestContext2Refresh_vars(t *testing.T) {
}, },
} }
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{}, Provider: &configschema.Block{},
ResourceTypes: map[string]*configschema.Block{"aws_instance": schema}, ResourceTypes: map[string]*configschema.Block{"aws_instance": schema},
} })
m := testModule(t, "refresh-vars") m := testModule(t, "refresh-vars")
state := states.NewState() state := states.NewState()
@ -1248,7 +1248,7 @@ func TestContext2Refresh_orphanModule(t *testing.T) {
func TestContext2Validate(t *testing.T) { func TestContext2Validate(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{}, Provider: &configschema.Block{},
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"aws_instance": { "aws_instance": {
@ -1264,7 +1264,7 @@ func TestContext2Validate(t *testing.T) {
}, },
}, },
}, },
} })
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
m := testModule(t, "validate-good") m := testModule(t, "validate-good")
@ -1318,7 +1318,7 @@ aws_instance.bar:
func TestContext2Refresh_schemaUpgradeFlatmap(t *testing.T) { func TestContext2Refresh_schemaUpgradeFlatmap(t *testing.T) {
m := testModule(t, "refresh-schema-upgrade") m := testModule(t, "refresh-schema-upgrade")
p := testProvider("test") p := testProvider("test")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"test_thing": { "test_thing": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -1332,7 +1332,7 @@ func TestContext2Refresh_schemaUpgradeFlatmap(t *testing.T) {
ResourceTypeSchemaVersions: map[string]uint64{ ResourceTypeSchemaVersions: map[string]uint64{
"test_thing": 5, "test_thing": 5,
}, },
} })
p.UpgradeResourceStateResponse = &providers.UpgradeResourceStateResponse{ p.UpgradeResourceStateResponse = &providers.UpgradeResourceStateResponse{
UpgradedState: cty.ObjectVal(map[string]cty.Value{ UpgradedState: cty.ObjectVal(map[string]cty.Value{
"name": cty.StringVal("foo"), "name": cty.StringVal("foo"),
@ -1405,7 +1405,7 @@ test_thing.bar:
func TestContext2Refresh_schemaUpgradeJSON(t *testing.T) { func TestContext2Refresh_schemaUpgradeJSON(t *testing.T) {
m := testModule(t, "refresh-schema-upgrade") m := testModule(t, "refresh-schema-upgrade")
p := testProvider("test") p := testProvider("test")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"test_thing": { "test_thing": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -1419,7 +1419,7 @@ func TestContext2Refresh_schemaUpgradeJSON(t *testing.T) {
ResourceTypeSchemaVersions: map[string]uint64{ ResourceTypeSchemaVersions: map[string]uint64{
"test_thing": 5, "test_thing": 5,
}, },
} })
p.UpgradeResourceStateResponse = &providers.UpgradeResourceStateResponse{ p.UpgradeResourceStateResponse = &providers.UpgradeResourceStateResponse{
UpgradedState: cty.ObjectVal(map[string]cty.Value{ UpgradedState: cty.ObjectVal(map[string]cty.Value{
"name": cty.StringVal("foo"), "name": cty.StringVal("foo"),
@ -1527,7 +1527,7 @@ data "aws_data_source" "foo" {
func TestContext2Refresh_dataResourceDependsOn(t *testing.T) { func TestContext2Refresh_dataResourceDependsOn(t *testing.T) {
m := testModule(t, "plan-data-depends-on") m := testModule(t, "plan-data-depends-on")
p := testProvider("test") p := testProvider("test")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"test_resource": { "test_resource": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -1543,7 +1543,7 @@ func TestContext2Refresh_dataResourceDependsOn(t *testing.T) {
}, },
}, },
}, },
} })
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
p.ReadDataSourceResponse = &providers.ReadDataSourceResponse{ p.ReadDataSourceResponse = &providers.ReadDataSourceResponse{
State: cty.ObjectVal(map[string]cty.Value{ State: cty.ObjectVal(map[string]cty.Value{

View File

@ -405,7 +405,7 @@ func testProvider(prefix string) *MockProvider {
return providers.ReadResourceResponse{NewState: req.PriorState} return providers.ReadResourceResponse{NewState: req.PriorState}
} }
p.GetSchemaReturn = testProviderSchema(prefix) p.GetSchemaResponse = testProviderSchema(prefix)
return p return p
} }
@ -465,8 +465,8 @@ func testCheckDeadlock(t *testing.T, f func()) {
} }
} }
func testProviderSchema(name string) *ProviderSchema { func testProviderSchema(name string) *providers.GetSchemaResponse {
return &ProviderSchema{ return getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{ Provider: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"region": { "region": {
@ -708,8 +708,7 @@ func testProviderSchema(name string) *ProviderSchema {
}, },
}, },
}, },
} })
} }
// contextForPlanViaFile is a helper that creates a temporary plan file, then // contextForPlanViaFile is a helper that creates a temporary plan file, then

View File

@ -18,13 +18,13 @@ import (
func TestContext2Validate_badCount(t *testing.T) { func TestContext2Validate_badCount(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"aws_instance": { "aws_instance": {
Attributes: map[string]*configschema.Attribute{}, Attributes: map[string]*configschema.Attribute{},
}, },
}, },
} })
m := testModule(t, "validate-bad-count") m := testModule(t, "validate-bad-count")
c := testContext2(t, &ContextOpts{ c := testContext2(t, &ContextOpts{
@ -42,13 +42,13 @@ func TestContext2Validate_badCount(t *testing.T) {
func TestContext2Validate_badResource_reference(t *testing.T) { func TestContext2Validate_badResource_reference(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"aws_instance": { "aws_instance": {
Attributes: map[string]*configschema.Attribute{}, Attributes: map[string]*configschema.Attribute{},
}, },
}, },
} })
m := testModule(t, "validate-bad-resource-count") m := testModule(t, "validate-bad-resource-count")
c := testContext2(t, &ContextOpts{ c := testContext2(t, &ContextOpts{
@ -66,7 +66,7 @@ func TestContext2Validate_badResource_reference(t *testing.T) {
func TestContext2Validate_badVar(t *testing.T) { func TestContext2Validate_badVar(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"aws_instance": { "aws_instance": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
@ -75,7 +75,7 @@ func TestContext2Validate_badVar(t *testing.T) {
}, },
}, },
}, },
} })
m := testModule(t, "validate-bad-var") m := testModule(t, "validate-bad-var")
c := testContext2(t, &ContextOpts{ c := testContext2(t, &ContextOpts{
@ -94,7 +94,7 @@ func TestContext2Validate_badVar(t *testing.T) {
func TestContext2Validate_varMapOverrideOld(t *testing.T) { func TestContext2Validate_varMapOverrideOld(t *testing.T) {
m := testModule(t, "validate-module-pc-vars") m := testModule(t, "validate-module-pc-vars")
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
Provider: &configschema.Block{ Provider: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
@ -105,7 +105,7 @@ func TestContext2Validate_varMapOverrideOld(t *testing.T) {
Attributes: map[string]*configschema.Attribute{}, Attributes: map[string]*configschema.Attribute{},
}, },
}, },
} })
_, diags := NewContext(&ContextOpts{ _, diags := NewContext(&ContextOpts{
Config: m, Config: m,
@ -133,28 +133,34 @@ func TestContext2Validate_varNoDefaultExplicitType(t *testing.T) {
func TestContext2Validate_computedVar(t *testing.T) { func TestContext2Validate_computedVar(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
Provider: &configschema.Block{ Provider: providers.Schema{
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"value": {Type: cty.String, Optional: true}, "value": {Type: cty.String, Optional: true},
}, },
}, },
ResourceTypes: map[string]*configschema.Block{ },
ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{}, Attributes: map[string]*configschema.Attribute{},
}, },
}, },
},
} }
pt := testProvider("test") pt := testProvider("test")
pt.GetSchemaReturn = &ProviderSchema{ pt.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"test_instance": { "test_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Computed: true}, "id": {Type: cty.String, Computed: true},
"value": {Type: cty.String, Optional: true}, "value": {Type: cty.String, Optional: true},
}, },
}, },
}, },
},
} }
m := testModule(t, "validate-computed-var") m := testModule(t, "validate-computed-var")
@ -186,22 +192,26 @@ func TestContext2Validate_computedVar(t *testing.T) {
func TestContext2Validate_computedInFunction(t *testing.T) { func TestContext2Validate_computedInFunction(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"attr": {Type: cty.Number, Optional: true}, "attr": {Type: cty.Number, Optional: true},
}, },
}, },
}, },
DataSources: map[string]*configschema.Block{ },
DataSources: map[string]providers.Schema{
"aws_data_source": { "aws_data_source": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"optional_attr": {Type: cty.String, Optional: true}, "optional_attr": {Type: cty.String, Optional: true},
"computed": {Type: cty.String, Computed: true}, "computed": {Type: cty.String, Computed: true},
}, },
}, },
}, },
},
} }
m := testModule(t, "validate-computed-in-function") m := testModule(t, "validate-computed-in-function")
@ -223,20 +233,24 @@ func TestContext2Validate_computedInFunction(t *testing.T) {
// can be realized during a plan. // can be realized during a plan.
func TestContext2Validate_countComputed(t *testing.T) { func TestContext2Validate_countComputed(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{}, Attributes: map[string]*configschema.Attribute{},
}, },
}, },
DataSources: map[string]*configschema.Block{ },
DataSources: map[string]providers.Schema{
"aws_data_source": { "aws_data_source": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"compute": {Type: cty.String, Optional: true}, "compute": {Type: cty.String, Optional: true},
"value": {Type: cty.String, Computed: true}, "value": {Type: cty.String, Computed: true},
}, },
}, },
}, },
},
} }
m := testModule(t, "validate-count-computed") m := testModule(t, "validate-count-computed")
@ -255,14 +269,15 @@ func TestContext2Validate_countComputed(t *testing.T) {
func TestContext2Validate_countNegative(t *testing.T) { func TestContext2Validate_countNegative(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{}, Attributes: map[string]*configschema.Attribute{},
}, },
}, },
},
} }
m := testModule(t, "validate-count-negative") m := testModule(t, "validate-count-negative")
c := testContext2(t, &ContextOpts{ c := testContext2(t, &ContextOpts{
Config: m, Config: m,
@ -279,16 +294,17 @@ func TestContext2Validate_countNegative(t *testing.T) {
func TestContext2Validate_countVariable(t *testing.T) { func TestContext2Validate_countVariable(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
}, },
}, },
}, },
},
} }
m := testModule(t, "apply-count-variable") m := testModule(t, "apply-count-variable")
c := testContext2(t, &ContextOpts{ c := testContext2(t, &ContextOpts{
Config: m, Config: m,
@ -306,16 +322,17 @@ func TestContext2Validate_countVariable(t *testing.T) {
func TestContext2Validate_countVariableNoDefault(t *testing.T) { func TestContext2Validate_countVariableNoDefault(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
m := testModule(t, "validate-count-variable") m := testModule(t, "validate-count-variable")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
}, },
}, },
}, },
},
} }
_, diags := NewContext(&ContextOpts{ _, diags := NewContext(&ContextOpts{
Config: m, Config: m,
Providers: map[addrs.Provider]providers.Factory{ Providers: map[addrs.Provider]providers.Factory{
@ -330,16 +347,17 @@ func TestContext2Validate_countVariableNoDefault(t *testing.T) {
func TestContext2Validate_moduleBadOutput(t *testing.T) { func TestContext2Validate_moduleBadOutput(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
}, },
}, },
}, },
},
} }
m := testModule(t, "validate-bad-module-output") m := testModule(t, "validate-bad-module-output")
c := testContext2(t, &ContextOpts{ c := testContext2(t, &ContextOpts{
Config: m, Config: m,
@ -356,16 +374,17 @@ func TestContext2Validate_moduleBadOutput(t *testing.T) {
func TestContext2Validate_moduleGood(t *testing.T) { func TestContext2Validate_moduleGood(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
}, },
}, },
}, },
},
} }
m := testModule(t, "validate-good-module") m := testModule(t, "validate-good-module")
c := testContext2(t, &ContextOpts{ c := testContext2(t, &ContextOpts{
Config: m, Config: m,
@ -383,12 +402,14 @@ func TestContext2Validate_moduleGood(t *testing.T) {
func TestContext2Validate_moduleBadResource(t *testing.T) { func TestContext2Validate_moduleBadResource(t *testing.T) {
m := testModule(t, "validate-module-bad-rc") m := testModule(t, "validate-module-bad-rc")
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{}, Attributes: map[string]*configschema.Attribute{},
}, },
}, },
},
} }
c := testContext2(t, &ContextOpts{ c := testContext2(t, &ContextOpts{
@ -411,14 +432,16 @@ func TestContext2Validate_moduleBadResource(t *testing.T) {
func TestContext2Validate_moduleDepsShouldNotCycle(t *testing.T) { func TestContext2Validate_moduleDepsShouldNotCycle(t *testing.T) {
m := testModule(t, "validate-module-deps-cycle") m := testModule(t, "validate-module-deps-cycle")
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Optional: true}, "id": {Type: cty.String, Optional: true},
}, },
}, },
}, },
},
} }
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
@ -437,19 +460,23 @@ func TestContext2Validate_moduleDepsShouldNotCycle(t *testing.T) {
func TestContext2Validate_moduleProviderVar(t *testing.T) { func TestContext2Validate_moduleProviderVar(t *testing.T) {
m := testModule(t, "validate-module-pc-vars") m := testModule(t, "validate-module-pc-vars")
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
Provider: &configschema.Block{ Provider: providers.Schema{
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
}, },
}, },
ResourceTypes: map[string]*configschema.Block{ },
ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
}, },
}, },
}, },
},
} }
c := testContext2(t, &ContextOpts{ c := testContext2(t, &ContextOpts{
@ -481,19 +508,23 @@ func TestContext2Validate_moduleProviderVar(t *testing.T) {
func TestContext2Validate_moduleProviderInheritUnused(t *testing.T) { func TestContext2Validate_moduleProviderInheritUnused(t *testing.T) {
m := testModule(t, "validate-module-pc-inherit-unused") m := testModule(t, "validate-module-pc-inherit-unused")
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
Provider: &configschema.Block{ Provider: providers.Schema{
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
}, },
}, },
ResourceTypes: map[string]*configschema.Block{ },
ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
}, },
}, },
}, },
},
} }
c := testContext2(t, &ContextOpts{ c := testContext2(t, &ContextOpts{
@ -518,15 +549,17 @@ func TestContext2Validate_moduleProviderInheritUnused(t *testing.T) {
func TestContext2Validate_orphans(t *testing.T) { func TestContext2Validate_orphans(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
"num": {Type: cty.String, Optional: true}, "num": {Type: cty.String, Optional: true},
}, },
}, },
}, },
},
} }
m := testModule(t, "validate-good") m := testModule(t, "validate-good")
@ -562,17 +595,21 @@ func TestContext2Validate_orphans(t *testing.T) {
func TestContext2Validate_providerConfig_bad(t *testing.T) { func TestContext2Validate_providerConfig_bad(t *testing.T) {
m := testModule(t, "validate-bad-pc") m := testModule(t, "validate-bad-pc")
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
Provider: &configschema.Block{ Provider: providers.Schema{
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
}, },
}, },
ResourceTypes: map[string]*configschema.Block{ },
ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{}, Attributes: map[string]*configschema.Attribute{},
}, },
}, },
},
} }
c := testContext2(t, &ContextOpts{ c := testContext2(t, &ContextOpts{
@ -598,17 +635,21 @@ func TestContext2Validate_providerConfig_bad(t *testing.T) {
func TestContext2Validate_providerConfig_skippedEmpty(t *testing.T) { func TestContext2Validate_providerConfig_skippedEmpty(t *testing.T) {
m := testModule(t, "validate-skipped-pc-empty") m := testModule(t, "validate-skipped-pc-empty")
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
Provider: &configschema.Block{ Provider: providers.Schema{
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
}, },
}, },
ResourceTypes: map[string]*configschema.Block{ },
ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{}, Attributes: map[string]*configschema.Attribute{},
}, },
}, },
},
} }
c := testContext2(t, &ContextOpts{ c := testContext2(t, &ContextOpts{
@ -631,17 +672,21 @@ func TestContext2Validate_providerConfig_skippedEmpty(t *testing.T) {
func TestContext2Validate_providerConfig_good(t *testing.T) { func TestContext2Validate_providerConfig_good(t *testing.T) {
m := testModule(t, "validate-bad-pc") m := testModule(t, "validate-bad-pc")
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
Provider: &configschema.Block{ Provider: providers.Schema{
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
}, },
}, },
ResourceTypes: map[string]*configschema.Block{ },
ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{}, Attributes: map[string]*configschema.Attribute{},
}, },
}, },
},
} }
c := testContext2(t, &ContextOpts{ c := testContext2(t, &ContextOpts{
@ -663,17 +708,21 @@ func TestContext2Validate_requiredProviderConfig(t *testing.T) {
m := testModule(t, "validate-required-provider-config") m := testModule(t, "validate-required-provider-config")
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
Provider: &configschema.Block{ Provider: providers.Schema{
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"required_attribute": {Type: cty.String, Required: true}, "required_attribute": {Type: cty.String, Required: true},
}, },
}, },
ResourceTypes: map[string]*configschema.Block{ },
ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{}, Attributes: map[string]*configschema.Attribute{},
}, },
}, },
},
} }
c := testContext2(t, &ContextOpts{ c := testContext2(t, &ContextOpts{
@ -692,14 +741,16 @@ func TestContext2Validate_requiredProviderConfig(t *testing.T) {
func TestContext2Validate_provisionerConfig_bad(t *testing.T) { func TestContext2Validate_provisionerConfig_bad(t *testing.T) {
m := testModule(t, "validate-bad-prov-conf") m := testModule(t, "validate-bad-prov-conf")
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
}, },
}, },
}, },
},
} }
pr := simpleMockProvisioner() pr := simpleMockProvisioner()
@ -727,14 +778,16 @@ func TestContext2Validate_provisionerConfig_bad(t *testing.T) {
func TestContext2Validate_badResourceConnection(t *testing.T) { func TestContext2Validate_badResourceConnection(t *testing.T) {
m := testModule(t, "validate-bad-resource-connection") m := testModule(t, "validate-bad-resource-connection")
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
}, },
}, },
}, },
},
} }
pr := simpleMockProvisioner() pr := simpleMockProvisioner()
@ -759,14 +812,16 @@ func TestContext2Validate_badResourceConnection(t *testing.T) {
func TestContext2Validate_badProvisionerConnection(t *testing.T) { func TestContext2Validate_badProvisionerConnection(t *testing.T) {
m := testModule(t, "validate-bad-prov-connection") m := testModule(t, "validate-bad-prov-connection")
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
}, },
}, },
}, },
},
} }
pr := simpleMockProvisioner() pr := simpleMockProvisioner()
@ -791,19 +846,23 @@ func TestContext2Validate_badProvisionerConnection(t *testing.T) {
func TestContext2Validate_provisionerConfig_good(t *testing.T) { func TestContext2Validate_provisionerConfig_good(t *testing.T) {
m := testModule(t, "validate-bad-prov-conf") m := testModule(t, "validate-bad-prov-conf")
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
Provider: &configschema.Block{ Provider: providers.Schema{
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
}, },
}, },
ResourceTypes: map[string]*configschema.Block{ },
ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
}, },
}, },
}, },
},
} }
pr := simpleMockProvisioner() pr := simpleMockProvisioner()
@ -836,16 +895,17 @@ func TestContext2Validate_provisionerConfig_good(t *testing.T) {
func TestContext2Validate_requiredVar(t *testing.T) { func TestContext2Validate_requiredVar(t *testing.T) {
m := testModule(t, "validate-required-var") m := testModule(t, "validate-required-var")
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"ami": {Type: cty.String, Optional: true}, "ami": {Type: cty.String, Optional: true},
}, },
}, },
}, },
},
} }
_, diags := NewContext(&ContextOpts{ _, diags := NewContext(&ContextOpts{
Config: m, Config: m,
Providers: map[addrs.Provider]providers.Factory{ Providers: map[addrs.Provider]providers.Factory{
@ -861,16 +921,17 @@ func TestContext2Validate_requiredVar(t *testing.T) {
func TestContext2Validate_resourceConfig_bad(t *testing.T) { func TestContext2Validate_resourceConfig_bad(t *testing.T) {
m := testModule(t, "validate-bad-rc") m := testModule(t, "validate-bad-rc")
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
}, },
}, },
}, },
},
} }
c := testContext2(t, &ContextOpts{ c := testContext2(t, &ContextOpts{
Config: m, Config: m,
Providers: map[addrs.Provider]providers.Factory{ Providers: map[addrs.Provider]providers.Factory{
@ -891,16 +952,17 @@ func TestContext2Validate_resourceConfig_bad(t *testing.T) {
func TestContext2Validate_resourceConfig_good(t *testing.T) { func TestContext2Validate_resourceConfig_good(t *testing.T) {
m := testModule(t, "validate-bad-rc") m := testModule(t, "validate-bad-rc")
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
}, },
}, },
}, },
},
} }
c := testContext2(t, &ContextOpts{ c := testContext2(t, &ContextOpts{
Config: m, Config: m,
Providers: map[addrs.Provider]providers.Factory{ Providers: map[addrs.Provider]providers.Factory{
@ -916,15 +978,17 @@ func TestContext2Validate_resourceConfig_good(t *testing.T) {
func TestContext2Validate_tainted(t *testing.T) { func TestContext2Validate_tainted(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
"num": {Type: cty.String, Optional: true}, "num": {Type: cty.String, Optional: true},
}, },
}, },
}, },
},
} }
m := testModule(t, "validate-good") m := testModule(t, "validate-good")
@ -962,15 +1026,17 @@ func TestContext2Validate_targetedDestroy(t *testing.T) {
pr := simpleMockProvisioner() pr := simpleMockProvisioner()
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
"num": {Type: cty.String, Optional: true}, "num": {Type: cty.String, Optional: true},
}, },
}, },
}, },
},
} }
state := states.NewState() state := states.NewState()
@ -1004,14 +1070,16 @@ func TestContext2Validate_targetedDestroy(t *testing.T) {
func TestContext2Validate_varRefUnknown(t *testing.T) { func TestContext2Validate_varRefUnknown(t *testing.T) {
m := testModule(t, "validate-variable-ref") m := testModule(t, "validate-variable-ref")
p := testProvider("aws") p := testProvider("aws")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
}, },
}, },
}, },
},
} }
c := testContext2(t, &ContextOpts{ c := testContext2(t, &ContextOpts{
Config: m, Config: m,
@ -1051,14 +1119,16 @@ func TestContext2Validate_interpolateVar(t *testing.T) {
p := testProvider("null") p := testProvider("null")
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"template_file": { "template_file": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"template": {Type: cty.String, Optional: true}, "template": {Type: cty.String, Optional: true},
}, },
}, },
}, },
},
} }
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
@ -1084,14 +1154,16 @@ func TestContext2Validate_interpolateComputedModuleVarDef(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
p.ApplyResourceChangeFn = testApplyFn p.ApplyResourceChangeFn = testApplyFn
p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = testDiffFn
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"aws_instance": { "aws_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"attr": {Type: cty.String, Optional: true}, "attr": {Type: cty.String, Optional: true},
}, },
}, },
}, },
},
} }
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
@ -1867,14 +1939,16 @@ resource "test_instance" "a" {
}) })
p := testProvider("test") p := testProvider("test")
p.GetSchemaReturn = &ProviderSchema{ p.GetSchemaResponse = &providers.GetSchemaResponse{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"test_instance": { "test_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Computed: true}, "id": {Type: cty.String, Computed: true},
}, },
}, },
}, },
},
} }
p.ValidateResourceTypeConfigResponse = &providers.ValidateResourceTypeConfigResponse{ p.ValidateResourceTypeConfigResponse = &providers.ValidateResourceTypeConfigResponse{

View File

@ -16,23 +16,16 @@ func TestPlanGraphBuilder_impl(t *testing.T) {
func TestPlanGraphBuilder(t *testing.T) { func TestPlanGraphBuilder(t *testing.T) {
awsProvider := &MockProvider{ awsProvider := &MockProvider{
GetSchemaReturn: &ProviderSchema{ GetSchemaResponse: &providers.GetSchemaResponse{
Provider: simpleTestSchema(), Provider: providers.Schema{Block: simpleTestSchema()},
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"aws_security_group": simpleTestSchema(), "aws_security_group": {Block: simpleTestSchema()},
"aws_instance": simpleTestSchema(), "aws_instance": {Block: simpleTestSchema()},
"aws_load_balancer": simpleTestSchema(), "aws_load_balancer": {Block: simpleTestSchema()},
},
},
}
openstackProvider := &MockProvider{
GetSchemaReturn: &ProviderSchema{
Provider: simpleTestSchema(),
ResourceTypes: map[string]*configschema.Block{
"openstack_floating_ip": simpleTestSchema(),
}, },
}, },
} }
openstackProvider := mockProviderWithResourceTypeSchema("openstack_floating_ip", simpleTestSchema())
components := &basicComponentFactory{ components := &basicComponentFactory{
providers: map[addrs.Provider]providers.Factory{ providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): providers.FactoryFixed(awsProvider), addrs.NewDefaultProvider("aws"): providers.FactoryFixed(awsProvider),
@ -45,8 +38,8 @@ func TestPlanGraphBuilder(t *testing.T) {
Components: components, Components: components,
Schemas: &Schemas{ Schemas: &Schemas{
Providers: map[addrs.Provider]*ProviderSchema{ Providers: map[addrs.Provider]*ProviderSchema{
addrs.NewDefaultProvider("aws"): awsProvider.GetSchemaReturn, addrs.NewDefaultProvider("aws"): awsProvider.ProviderSchema(),
addrs.NewDefaultProvider("openstack"): openstackProvider.GetSchemaReturn, addrs.NewDefaultProvider("openstack"): openstackProvider.ProviderSchema(),
}, },
}, },
} }
@ -68,10 +61,7 @@ func TestPlanGraphBuilder(t *testing.T) {
} }
func TestPlanGraphBuilder_dynamicBlock(t *testing.T) { func TestPlanGraphBuilder_dynamicBlock(t *testing.T) {
provider := &MockProvider{ provider := mockProviderWithResourceTypeSchema("test_thing", &configschema.Block{
GetSchemaReturn: &ProviderSchema{
ResourceTypes: map[string]*configschema.Block{
"test_thing": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Computed: true}, "id": {Type: cty.String, Computed: true},
"list": {Type: cty.List(cty.String), Computed: true}, "list": {Type: cty.List(cty.String), Computed: true},
@ -86,10 +76,7 @@ func TestPlanGraphBuilder_dynamicBlock(t *testing.T) {
}, },
}, },
}, },
}, })
},
},
}
components := &basicComponentFactory{ components := &basicComponentFactory{
providers: map[addrs.Provider]providers.Factory{ providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("test"): providers.FactoryFixed(provider), addrs.NewDefaultProvider("test"): providers.FactoryFixed(provider),
@ -101,7 +88,7 @@ func TestPlanGraphBuilder_dynamicBlock(t *testing.T) {
Components: components, Components: components,
Schemas: &Schemas{ Schemas: &Schemas{
Providers: map[addrs.Provider]*ProviderSchema{ Providers: map[addrs.Provider]*ProviderSchema{
addrs.NewDefaultProvider("test"): provider.GetSchemaReturn, addrs.NewDefaultProvider("test"): provider.ProviderSchema(),
}, },
}, },
} }
@ -144,10 +131,7 @@ test_thing.c (expand)
} }
func TestPlanGraphBuilder_attrAsBlocks(t *testing.T) { func TestPlanGraphBuilder_attrAsBlocks(t *testing.T) {
provider := &MockProvider{ provider := mockProviderWithResourceTypeSchema("test_thing", &configschema.Block{
GetSchemaReturn: &ProviderSchema{
ResourceTypes: map[string]*configschema.Block{
"test_thing": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Computed: true}, "id": {Type: cty.String, Computed: true},
"nested": { "nested": {
@ -157,10 +141,7 @@ func TestPlanGraphBuilder_attrAsBlocks(t *testing.T) {
Optional: true, Optional: true,
}, },
}, },
}, })
},
},
}
components := &basicComponentFactory{ components := &basicComponentFactory{
providers: map[addrs.Provider]providers.Factory{ providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("test"): providers.FactoryFixed(provider), addrs.NewDefaultProvider("test"): providers.FactoryFixed(provider),
@ -172,7 +153,7 @@ func TestPlanGraphBuilder_attrAsBlocks(t *testing.T) {
Components: components, Components: components,
Schemas: &Schemas{ Schemas: &Schemas{
Providers: map[addrs.Provider]*ProviderSchema{ Providers: map[addrs.Provider]*ProviderSchema{
addrs.NewDefaultProvider("test"): provider.GetSchemaReturn, addrs.NewDefaultProvider("test"): provider.ProviderSchema(),
}, },
}, },
} }
@ -233,14 +214,7 @@ func TestPlanGraphBuilder_targetModule(t *testing.T) {
} }
func TestPlanGraphBuilder_forEach(t *testing.T) { func TestPlanGraphBuilder_forEach(t *testing.T) {
awsProvider := &MockProvider{ awsProvider := mockProviderWithResourceTypeSchema("aws_instance", simpleTestSchema())
GetSchemaReturn: &ProviderSchema{
Provider: simpleTestSchema(),
ResourceTypes: map[string]*configschema.Block{
"aws_instance": simpleTestSchema(),
},
},
}
components := &basicComponentFactory{ components := &basicComponentFactory{
providers: map[addrs.Provider]providers.Factory{ providers: map[addrs.Provider]providers.Factory{
@ -253,7 +227,7 @@ func TestPlanGraphBuilder_forEach(t *testing.T) {
Components: components, Components: components,
Schemas: &Schemas{ Schemas: &Schemas{
Providers: map[addrs.Provider]*ProviderSchema{ Providers: map[addrs.Provider]*ProviderSchema{
addrs.NewDefaultProvider("aws"): awsProvider.GetSchemaReturn, addrs.NewDefaultProvider("aws"): awsProvider.ProviderSchema(),
}, },
}, },
} }

View File

@ -231,18 +231,14 @@ func TestNodeApplyableProviderExecute_emptyValidate(t *testing.T) {
} }
func TestNodeApplyableProvider_Validate(t *testing.T) { func TestNodeApplyableProvider_Validate(t *testing.T) {
provider := &MockProvider{ provider := mockProviderWithConfigSchema(&configschema.Block{
GetSchemaReturn: &ProviderSchema{
Provider: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"region": { "region": {
Type: cty.String, Type: cty.String,
Required: true, Required: true,
}, },
}, },
}, })
},
}
ctx := &MockEvalContext{ProviderProvider: provider} ctx := &MockEvalContext{ProviderProvider: provider}
ctx.installSimpleEval() ctx.installSimpleEval()
@ -307,18 +303,14 @@ func TestNodeApplyableProvider_Validate(t *testing.T) {
//TestNodeApplyableProvider_ConfigProvider_config_fn_err for //TestNodeApplyableProvider_ConfigProvider_config_fn_err for
//providers.ConfigureRequest responses. //providers.ConfigureRequest responses.
func TestNodeApplyableProvider_ConfigProvider(t *testing.T) { func TestNodeApplyableProvider_ConfigProvider(t *testing.T) {
provider := &MockProvider{ provider := mockProviderWithConfigSchema(&configschema.Block{
GetSchemaReturn: &ProviderSchema{
Provider: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"region": { "region": {
Type: cty.String, Type: cty.String,
Optional: true, Optional: true,
}, },
}, },
}, })
},
}
// For this test, we're returning an error for an optional argument. This // For this test, we're returning an error for an optional argument. This
// can happen for example if an argument is only conditionally required. // can happen for example if an argument is only conditionally required.
provider.PrepareProviderConfigFn = func(req providers.PrepareProviderConfigRequest) (resp providers.PrepareProviderConfigResponse) { provider.PrepareProviderConfigFn = func(req providers.PrepareProviderConfigRequest) (resp providers.PrepareProviderConfigResponse) {
@ -393,18 +385,14 @@ func TestNodeApplyableProvider_ConfigProvider(t *testing.T) {
//This test is similar to TestNodeApplyableProvider_ConfigProvider, but tests responses from the providers.ConfigureRequest //This test is similar to TestNodeApplyableProvider_ConfigProvider, but tests responses from the providers.ConfigureRequest
func TestNodeApplyableProvider_ConfigProvider_config_fn_err(t *testing.T) { func TestNodeApplyableProvider_ConfigProvider_config_fn_err(t *testing.T) {
provider := &MockProvider{ provider := mockProviderWithConfigSchema(&configschema.Block{
GetSchemaReturn: &ProviderSchema{
Provider: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"region": { "region": {
Type: cty.String, Type: cty.String,
Optional: true, Optional: true,
}, },
}, },
}, })
},
}
ctx := &MockEvalContext{ProviderProvider: provider} ctx := &MockEvalContext{ProviderProvider: provider}
ctx.installSimpleEval() ctx.installSimpleEval()
// For this test, provider.PrepareConfigFn will succeed every time but the // For this test, provider.PrepareConfigFn will succeed every time but the

View File

@ -143,7 +143,7 @@ func TestNodeAbstractResourceInstance_WriteResourceInstanceState(t *testing.T) {
}, },
} }
ctx.ProviderProvider = mockProvider ctx.ProviderProvider = mockProvider
ctx.ProviderSchemaSchema = mockProvider.GetSchemaReturn ctx.ProviderSchemaSchema = mockProvider.ProviderSchema()
err := node.writeResourceInstanceState(ctx, obj, nil, workingState) err := node.writeResourceInstanceState(ctx, obj, nil, workingState)
if err != nil { if err != nil {

View File

@ -157,7 +157,7 @@ func TestNodeAbstractResource_ReadResourceInstanceState(t *testing.T) {
ctx := new(MockEvalContext) ctx := new(MockEvalContext)
ctx.StateState = test.State.SyncWrapper() ctx.StateState = test.State.SyncWrapper()
ctx.PathPath = addrs.RootModuleInstance ctx.PathPath = addrs.RootModuleInstance
ctx.ProviderSchemaSchema = mockProvider.GetSchemaReturn ctx.ProviderSchemaSchema = mockProvider.ProviderSchema()
ctx.ProviderProvider = providers.Interface(mockProvider) ctx.ProviderProvider = providers.Interface(mockProvider)
got, err := test.Node.readResourceInstanceState(ctx, test.Node.Addr.Resource.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance)) got, err := test.Node.readResourceInstanceState(ctx, test.Node.Addr.Resource.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance))
@ -218,7 +218,7 @@ func TestNodeAbstractResource_ReadResourceInstanceStateDeposed(t *testing.T) {
ctx := new(MockEvalContext) ctx := new(MockEvalContext)
ctx.StateState = test.State.SyncWrapper() ctx.StateState = test.State.SyncWrapper()
ctx.PathPath = addrs.RootModuleInstance ctx.PathPath = addrs.RootModuleInstance
ctx.ProviderSchemaSchema = mockProvider.GetSchemaReturn ctx.ProviderSchemaSchema = mockProvider.ProviderSchema()
ctx.ProviderProvider = providers.Interface(mockProvider) ctx.ProviderProvider = providers.Interface(mockProvider)
key := states.DeposedKey("00000001") // shim from legacy state assigns 0th deposed index this key key := states.DeposedKey("00000001") // shim from legacy state assigns 0th deposed index this key

View File

@ -143,7 +143,7 @@ func TestNodeDestroyDeposedResourceInstanceObject_WriteResourceInstanceState(t *
}, },
}) })
ctx.ProviderProvider = mockProvider ctx.ProviderProvider = mockProvider
ctx.ProviderSchemaSchema = mockProvider.GetSchemaReturn ctx.ProviderSchemaSchema = mockProvider.ProviderSchema()
obj := &states.ResourceInstanceObject{ obj := &states.ResourceInstanceObject{
Value: cty.ObjectVal(map[string]cty.Value{ Value: cty.ObjectVal(map[string]cty.Value{

View File

@ -188,7 +188,7 @@ func TestNodeValidatableResource_ValidateResource_managedResource(t *testing.T)
ctx := &MockEvalContext{} ctx := &MockEvalContext{}
ctx.installSimpleEval() ctx.installSimpleEval()
ctx.ProviderSchemaSchema = mp.GetSchemaReturn ctx.ProviderSchemaSchema = mp.ProviderSchema()
ctx.ProviderProvider = p ctx.ProviderProvider = p
err := node.validateResource(ctx) err := node.validateResource(ctx)
@ -218,7 +218,7 @@ func TestNodeValidatableResource_ValidateResource_managedResourceCount(t *testin
ctx := &MockEvalContext{} ctx := &MockEvalContext{}
ctx.installSimpleEval() ctx.installSimpleEval()
ctx.ProviderSchemaSchema = mp.GetSchemaReturn ctx.ProviderSchemaSchema = mp.ProviderSchema()
ctx.ProviderProvider = p ctx.ProviderProvider = p
tests := []struct { tests := []struct {
@ -302,7 +302,7 @@ func TestNodeValidatableResource_ValidateResource_dataSource(t *testing.T) {
ctx := &MockEvalContext{} ctx := &MockEvalContext{}
ctx.installSimpleEval() ctx.installSimpleEval()
ctx.ProviderSchemaSchema = mp.GetSchemaReturn ctx.ProviderSchemaSchema = mp.ProviderSchema()
ctx.ProviderProvider = p ctx.ProviderProvider = p
diags := node.validateResource(ctx) diags := node.validateResource(ctx)
@ -338,7 +338,7 @@ func TestNodeValidatableResource_ValidateResource_valid(t *testing.T) {
ctx := &MockEvalContext{} ctx := &MockEvalContext{}
ctx.installSimpleEval() ctx.installSimpleEval()
ctx.ProviderSchemaSchema = mp.GetSchemaReturn ctx.ProviderSchemaSchema = mp.ProviderSchema()
ctx.ProviderProvider = p ctx.ProviderProvider = p
diags := node.validateResource(ctx) diags := node.validateResource(ctx)
@ -375,7 +375,7 @@ func TestNodeValidatableResource_ValidateResource_warningsAndErrorsPassedThrough
ctx := &MockEvalContext{} ctx := &MockEvalContext{}
ctx.installSimpleEval() ctx.installSimpleEval()
ctx.ProviderSchemaSchema = mp.GetSchemaReturn ctx.ProviderSchemaSchema = mp.ProviderSchema()
ctx.ProviderProvider = p ctx.ProviderProvider = p
diags := node.validateResource(ctx) diags := node.validateResource(ctx)
@ -437,7 +437,8 @@ func TestNodeValidatableResource_ValidateResource_invalidDependsOn(t *testing.T)
ctx := &MockEvalContext{} ctx := &MockEvalContext{}
ctx.installSimpleEval() ctx.installSimpleEval()
ctx.ProviderSchemaSchema = mp.GetSchemaReturn
ctx.ProviderSchemaSchema = mp.ProviderSchema()
ctx.ProviderProvider = p ctx.ProviderProvider = p
diags := node.validateResource(ctx) diags := node.validateResource(ctx)

View File

@ -1,12 +1,13 @@
package terraform package terraform
import ( import (
"errors" "fmt"
"sync" "sync"
ctyjson "github.com/zclconf/go-cty/cty/json" ctyjson "github.com/zclconf/go-cty/cty/json"
"github.com/zclconf/go-cty/cty/msgpack" "github.com/zclconf/go-cty/cty/msgpack"
"github.com/hashicorp/terraform/configs/configschema"
"github.com/hashicorp/terraform/configs/hcl2shim" "github.com/hashicorp/terraform/configs/hcl2shim"
"github.com/hashicorp/terraform/providers" "github.com/hashicorp/terraform/providers"
) )
@ -22,7 +23,7 @@ type MockProvider struct {
Meta interface{} Meta interface{}
GetSchemaCalled bool GetSchemaCalled bool
GetSchemaReturn *ProviderSchema // This is using ProviderSchema directly rather than providers.GetSchemaResponse for compatibility with old tests GetSchemaResponse *providers.GetSchemaResponse
PrepareProviderConfigCalled bool PrepareProviderConfigCalled bool
PrepareProviderConfigResponse *providers.PrepareProviderConfigResponse PrepareProviderConfigResponse *providers.PrepareProviderConfigResponse
@ -96,47 +97,40 @@ func (p *MockProvider) getSchema() providers.GetSchemaResponse {
// This version of getSchema doesn't do any locking, so it's suitable to // This version of getSchema doesn't do any locking, so it's suitable to
// call from other methods of this mock as long as they are already // call from other methods of this mock as long as they are already
// holding the lock. // holding the lock.
if p.GetSchemaResponse != nil {
return *p.GetSchemaResponse
}
ret := providers.GetSchemaResponse{ return providers.GetSchemaResponse{
Provider: providers.Schema{}, Provider: providers.Schema{},
DataSources: map[string]providers.Schema{}, DataSources: map[string]providers.Schema{},
ResourceTypes: map[string]providers.Schema{}, ResourceTypes: map[string]providers.Schema{},
} }
if p.GetSchemaReturn != nil {
ret.Provider.Block = p.GetSchemaReturn.Provider
ret.ProviderMeta.Block = p.GetSchemaReturn.ProviderMeta
for n, s := range p.GetSchemaReturn.DataSources {
ret.DataSources[n] = providers.Schema{
Block: s,
}
}
for n, s := range p.GetSchemaReturn.ResourceTypes {
ret.ResourceTypes[n] = providers.Schema{
Version: int64(p.GetSchemaReturn.ResourceTypeSchemaVersions[n]),
Block: s,
}
}
} }
return ret // ProviderSchema is a helper to convert from the internal GetSchemaResponse to
// a ProviderSchema.
func (p *MockProvider) ProviderSchema() *ProviderSchema {
resp := p.getSchema()
schema := &ProviderSchema{
Provider: resp.Provider.Block,
ProviderMeta: resp.ProviderMeta.Block,
ResourceTypes: map[string]*configschema.Block{},
DataSources: map[string]*configschema.Block{},
ResourceTypeSchemaVersions: map[string]uint64{},
} }
func (p *MockProvider) getResourceSchema(name string) providers.Schema { for resType, s := range resp.ResourceTypes {
schema := p.getSchema() schema.ResourceTypes[resType] = s.Block
resSchema, ok := schema.ResourceTypes[name] schema.ResourceTypeSchemaVersions[resType] = uint64(s.Version)
if !ok {
panic("unknown resource type " + name)
}
return resSchema
} }
func (p *MockProvider) getDatasourceSchema(name string) providers.Schema { for dataSource, s := range resp.DataSources {
schema := p.getSchema() schema.DataSources[dataSource] = s.Block
dataSchema, ok := schema.DataSources[name]
if !ok {
panic("unknown data source " + name)
} }
return dataSchema
return schema
} }
func (p *MockProvider) PrepareProviderConfig(r providers.PrepareProviderConfigRequest) (resp providers.PrepareProviderConfigResponse) { func (p *MockProvider) PrepareProviderConfig(r providers.PrepareProviderConfigRequest) (resp providers.PrepareProviderConfigResponse) {
@ -166,7 +160,12 @@ func (p *MockProvider) ValidateResourceTypeConfig(r providers.ValidateResourceTy
// Marshall the value to replicate behavior by the GRPC protocol, // Marshall the value to replicate behavior by the GRPC protocol,
// and return any relevant errors // and return any relevant errors
resourceSchema := p.getResourceSchema(r.TypeName) resourceSchema, ok := p.getSchema().ResourceTypes[r.TypeName]
if !ok {
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("no schema found for %q", r.TypeName))
return resp
}
_, err := msgpack.Marshal(r.Config, resourceSchema.Block.ImpliedType()) _, err := msgpack.Marshal(r.Config, resourceSchema.Block.ImpliedType())
if err != nil { if err != nil {
resp.Diagnostics = resp.Diagnostics.Append(err) resp.Diagnostics = resp.Diagnostics.Append(err)
@ -192,7 +191,11 @@ func (p *MockProvider) ValidateDataSourceConfig(r providers.ValidateDataSourceCo
p.ValidateDataSourceConfigRequest = r p.ValidateDataSourceConfigRequest = r
// Marshall the value to replicate behavior by the GRPC protocol // Marshall the value to replicate behavior by the GRPC protocol
dataSchema := p.getDatasourceSchema(r.TypeName) dataSchema, ok := p.getSchema().DataSources[r.TypeName]
if !ok {
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("no schema found for %q", r.TypeName))
return resp
}
_, err := msgpack.Marshal(r.Config, dataSchema.Block.ImpliedType()) _, err := msgpack.Marshal(r.Config, dataSchema.Block.ImpliedType())
if err != nil { if err != nil {
resp.Diagnostics = resp.Diagnostics.Append(err) resp.Diagnostics = resp.Diagnostics.Append(err)
@ -214,8 +217,12 @@ func (p *MockProvider) UpgradeResourceState(r providers.UpgradeResourceStateRequ
p.Lock() p.Lock()
defer p.Unlock() defer p.Unlock()
schemas := p.getSchema() schema, ok := p.getSchema().ResourceTypes[r.TypeName]
schema := schemas.ResourceTypes[r.TypeName] if !ok {
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("no schema found for %q", r.TypeName))
return resp
}
schemaType := schema.Block.ImpliedType() schemaType := schema.Block.ImpliedType()
p.UpgradeResourceStateCalled = true p.UpgradeResourceStateCalled = true
@ -298,7 +305,13 @@ func (p *MockProvider) ReadResource(r providers.ReadResourceRequest) (resp provi
// Make sure the NewState conforms to the schema. // Make sure the NewState conforms to the schema.
// This isn't always the case for the existing tests. // This isn't always the case for the existing tests.
newState, err := p.GetSchemaReturn.ResourceTypes[r.TypeName].CoerceValue(resp.NewState) schema, ok := p.getSchema().ResourceTypes[r.TypeName]
if !ok {
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("no schema found for %q", r.TypeName))
return resp
}
newState, err := schema.Block.CoerceValue(resp.NewState)
if err != nil { if err != nil {
resp.Diagnostics = resp.Diagnostics.Append(err) resp.Diagnostics = resp.Diagnostics.Append(err)
} }
@ -326,6 +339,12 @@ func (p *MockProvider) PlanResourceChange(r providers.PlanResourceChangeRequest)
return *p.PlanResourceChangeResponse return *p.PlanResourceChangeResponse
} }
schema, ok := p.getSchema().ResourceTypes[r.TypeName]
if !ok {
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("no schema found for %q", r.TypeName))
return resp
}
return resp return resp
} }
@ -342,6 +361,7 @@ func (p *MockProvider) ApplyResourceChange(r providers.ApplyResourceChangeReques
if p.ApplyResourceChangeResponse != nil { if p.ApplyResourceChangeResponse != nil {
return *p.ApplyResourceChangeResponse return *p.ApplyResourceChangeResponse
} }
return resp return resp
} }
@ -359,14 +379,14 @@ func (p *MockProvider) ImportResourceState(r providers.ImportResourceStateReques
resp = *p.ImportResourceStateResponse resp = *p.ImportResourceStateResponse
// fixup the cty value to match the schema // fixup the cty value to match the schema
for i, res := range resp.ImportedResources { for i, res := range resp.ImportedResources {
schema := p.GetSchemaReturn.ResourceTypes[res.TypeName] schema, ok := p.getSchema().ResourceTypes[res.TypeName]
if schema == nil { if !ok {
resp.Diagnostics = resp.Diagnostics.Append(errors.New("no schema found for " + res.TypeName)) resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("no schema found for %q", res.TypeName))
return resp return resp
} }
var err error var err error
res.State, err = schema.CoerceValue(res.State) res.State, err = schema.Block.CoerceValue(res.State)
if err != nil { if err != nil {
resp.Diagnostics = resp.Diagnostics.Append(err) resp.Diagnostics = resp.Diagnostics.Append(err)
return resp return resp
@ -393,6 +413,7 @@ func (p *MockProvider) ReadDataSource(r providers.ReadDataSourceRequest) (resp p
if p.ReadDataSourceResponse != nil { if p.ReadDataSourceResponse != nil {
resp = *p.ReadDataSourceResponse resp = *p.ReadDataSourceResponse
} }
return resp return resp
} }

View File

@ -2,6 +2,7 @@ package terraform
import ( import (
"github.com/hashicorp/terraform/configs/configschema" "github.com/hashicorp/terraform/configs/configschema"
"github.com/hashicorp/terraform/providers"
"github.com/zclconf/go-cty/cty" "github.com/zclconf/go-cty/cty"
) )
@ -9,8 +10,8 @@ import (
// provider with the given schema for its own configuration. // provider with the given schema for its own configuration.
func mockProviderWithConfigSchema(schema *configschema.Block) *MockProvider { func mockProviderWithConfigSchema(schema *configschema.Block) *MockProvider {
return &MockProvider{ return &MockProvider{
GetSchemaReturn: &ProviderSchema{ GetSchemaResponse: &providers.GetSchemaResponse{
Provider: schema, Provider: providers.Schema{Block: schema},
}, },
} }
} }
@ -19,8 +20,9 @@ func mockProviderWithConfigSchema(schema *configschema.Block) *MockProvider {
// provider with a schema containing a single resource type. // provider with a schema containing a single resource type.
func mockProviderWithResourceTypeSchema(name string, schema *configschema.Block) *MockProvider { func mockProviderWithResourceTypeSchema(name string, schema *configschema.Block) *MockProvider {
return &MockProvider{ return &MockProvider{
GetSchemaReturn: &ProviderSchema{ GetSchemaResponse: &providers.GetSchemaResponse{
Provider: &configschema.Block{ Provider: providers.Schema{
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"string": { "string": {
Type: cty.String, Type: cty.String,
@ -36,13 +38,65 @@ func mockProviderWithResourceTypeSchema(name string, schema *configschema.Block)
}, },
}, },
}, },
ResourceTypes: map[string]*configschema.Block{ },
name: schema, ResourceTypes: map[string]providers.Schema{
name: providers.Schema{Block: schema},
}, },
}, },
} }
} }
// mockProviderWithProviderSchema is a test helper to create a mock provider
// from an existing ProviderSchema.
func mockProviderWithProviderSchema(providerSchema ProviderSchema) *MockProvider {
p := &MockProvider{
GetSchemaResponse: &providers.GetSchemaResponse{
Provider: providers.Schema{
Block: providerSchema.Provider,
},
ResourceTypes: map[string]providers.Schema{},
DataSources: map[string]providers.Schema{},
},
}
for name, schema := range providerSchema.ResourceTypes {
p.GetSchemaResponse.ResourceTypes[name] = providers.Schema{
Block: schema,
Version: int64(providerSchema.ResourceTypeSchemaVersions[name]),
}
}
for name, schema := range providerSchema.DataSources {
p.GetSchemaResponse.DataSources[name] = providers.Schema{Block: schema}
}
return p
}
// getSchemaResponseFromProviderSchema is a test helper to convert a
// ProviderSchema to a GetSchemaResponse for use when building a mock provider.
func getSchemaResponseFromProviderSchema(providerSchema *ProviderSchema) *providers.GetSchemaResponse {
resp := &providers.GetSchemaResponse{
Provider: providers.Schema{Block: providerSchema.Provider},
ProviderMeta: providers.Schema{Block: providerSchema.ProviderMeta},
ResourceTypes: map[string]providers.Schema{},
DataSources: map[string]providers.Schema{},
}
for name, schema := range providerSchema.ResourceTypes {
resp.ResourceTypes[name] = providers.Schema{
Block: schema,
Version: int64(providerSchema.ResourceTypeSchemaVersions[name]),
}
}
for name, schema := range providerSchema.DataSources {
resp.DataSources[name] = providers.Schema{Block: schema}
}
return resp
}
// simpleMockProvider returns a MockProvider that is pre-configured // simpleMockProvider returns a MockProvider that is pre-configured
// with schema for its own config, for a resource type called "test_object" and // with schema for its own config, for a resource type called "test_object" and
// for a data source also called "test_object". // for a data source also called "test_object".
@ -62,13 +116,13 @@ func mockProviderWithResourceTypeSchema(name string, schema *configschema.Block)
// objects so that callers can mutate without affecting mock objects. // objects so that callers can mutate without affecting mock objects.
func simpleMockProvider() *MockProvider { func simpleMockProvider() *MockProvider {
return &MockProvider{ return &MockProvider{
GetSchemaReturn: &ProviderSchema{ GetSchemaResponse: &providers.GetSchemaResponse{
Provider: simpleTestSchema(), Provider: providers.Schema{Block: simpleTestSchema()},
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"test_object": simpleTestSchema(), "test_object": providers.Schema{Block: simpleTestSchema()},
}, },
DataSources: map[string]*configschema.Block{ DataSources: map[string]providers.Schema{
"test_object": simpleTestSchema(), "test_object": providers.Schema{Block: simpleTestSchema()},
}, },
}, },
} }

View File

@ -8,9 +8,10 @@ import (
func simpleTestSchemas() *Schemas { func simpleTestSchemas() *Schemas {
provider := simpleMockProvider() provider := simpleMockProvider()
provisioner := simpleMockProvisioner() provisioner := simpleMockProvisioner()
return &Schemas{ return &Schemas{
Providers: map[addrs.Provider]*ProviderSchema{ Providers: map[addrs.Provider]*ProviderSchema{
addrs.NewDefaultProvider("test"): provider.GetSchemaReturn, addrs.NewDefaultProvider("test"): provider.ProviderSchema(),
}, },
Provisioners: map[string]*configschema.Block{ Provisioners: map[string]*configschema.Block{
"test": provisioner.GetSchemaResponse.Provisioner, "test": provisioner.GetSchemaResponse.Provisioner,