From 7dd570ef6cba8287e5e9608ab1639fa49609d63c Mon Sep 17 00:00:00 2001 From: James Bardin Date: Mon, 11 Jan 2021 15:45:50 -0500 Subject: [PATCH] change mock provider to use GetSchemaResponse This ensures that test providers are using the same types as actual providers. --- terraform/context_apply_test.go | 156 +++---- terraform/context_import_test.go | 12 +- terraform/context_input_test.go | 20 +- terraform/context_plan_test.go | 274 ++++++------ terraform/context_refresh_test.go | 78 ++-- terraform/context_test.go | 9 +- terraform/context_validate_test.go | 416 +++++++++++------- terraform/graph_builder_plan_test.go | 92 ++-- terraform/node_provider_test.go | 48 +- .../node_resource_abstract_instance_test.go | 2 +- terraform/node_resource_abstract_test.go | 4 +- .../node_resource_destroy_deposed_test.go | 2 +- terraform/node_resource_validate_test.go | 13 +- terraform/provider_mock.go | 109 +++-- terraform/resource_provider_mock_test.go | 102 ++++- terraform/schemas_test.go | 3 +- 16 files changed, 726 insertions(+), 614 deletions(-) diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index f8a7979c99..3b5901d962 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -94,7 +94,7 @@ func TestContext2Apply_unstable(t *testing.T) { Type: "test_resource", Name: "foo", }.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) rd, err := rds.Decode(schema.ImpliedType()) if err != nil { @@ -1600,7 +1600,7 @@ func TestContext2Apply_destroyCrossProviders(t *testing.T) { p_aws := testProvider("aws") p_aws.ApplyResourceChangeFn = testApplyFn p_aws.PlanResourceChangeFn = testDiffFn - p_aws.GetSchemaReturn = &ProviderSchema{ + p_aws.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -1623,7 +1623,7 @@ func TestContext2Apply_destroyCrossProviders(t *testing.T) { }, }, }, - } + }) providers := map[addrs.Provider]providers.Factory{ addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p_aws), @@ -1939,7 +1939,7 @@ func TestContext2Apply_compute(t *testing.T) { p := testProvider("aws") p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -1974,7 +1974,7 @@ func TestContext2Apply_compute(t *testing.T) { }, }, }, - } + }) ctx := testContext2(t, &ContextOpts{ Config: m, @@ -2438,7 +2438,7 @@ func TestContext2Apply_moduleDestroyOrder(t *testing.T) { return resp } - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -2448,7 +2448,7 @@ func TestContext2Apply_moduleDestroyOrder(t *testing.T) { }, }, }, - } + }) state := states.NewState() child := state.EnsureModule(addrs.RootModuleInstance.Child("child", addrs.NoKey)) @@ -2559,7 +2559,7 @@ func TestContext2Apply_orphanResource(t *testing.T) { p := testProvider("test") p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test_thing": { Attributes: map[string]*configschema.Attribute{ @@ -2568,7 +2568,7 @@ func TestContext2Apply_orphanResource(t *testing.T) { }, }, }, - } + }) // Step 1: create the resources and instances m := testModule(t, "apply-orphan-resource") @@ -3172,7 +3172,7 @@ func TestContext2Apply_multiProviderDestroy(t *testing.T) { p := testProvider("aws") p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "addr": {Type: cty.String, Optional: true}, @@ -3186,12 +3186,12 @@ func TestContext2Apply_multiProviderDestroy(t *testing.T) { }, }, }, - } + }) p2 := testProvider("vault") p2.ApplyResourceChangeFn = testApplyFn p2.PlanResourceChangeFn = testDiffFn - p2.GetSchemaReturn = &ProviderSchema{ + p2.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "vault_instance": { Attributes: map[string]*configschema.Attribute{ @@ -3199,7 +3199,7 @@ func TestContext2Apply_multiProviderDestroy(t *testing.T) { }, }, }, - } + }) var state *states.State @@ -3293,7 +3293,7 @@ func TestContext2Apply_multiProviderDestroyChild(t *testing.T) { p := testProvider("aws") p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "value": {Type: cty.String, Optional: true}, @@ -3307,12 +3307,12 @@ func TestContext2Apply_multiProviderDestroyChild(t *testing.T) { }, }, }, - } + }) p2 := testProvider("vault") p2.ApplyResourceChangeFn = testApplyFn p2.PlanResourceChangeFn = testDiffFn - p2.GetSchemaReturn = &ProviderSchema{ + p2.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{}, ResourceTypes: map[string]*configschema.Block{ "vault_instance": { @@ -3321,7 +3321,7 @@ func TestContext2Apply_multiProviderDestroyChild(t *testing.T) { }, }, }, - } + }) 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{ "test_thing": { Attributes: map[string]*configschema.Attribute{ @@ -3552,7 +3552,7 @@ func TestContext2Apply_multiVarComprehensive(t *testing.T) { }, }, }, - } + }) // First, apply with a count of 3 ctx := testContext2(t, &ContextOpts{ @@ -3880,7 +3880,7 @@ func TestContext2Apply_multiVarMissingState(t *testing.T) { p := testProvider("test") p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test_thing": { Attributes: map[string]*configschema.Attribute{ @@ -3889,7 +3889,7 @@ func TestContext2Apply_multiVarMissingState(t *testing.T) { }, }, }, - } + }) // First, apply with a count of 3 ctx := testContext2(t, &ContextOpts{ @@ -4447,7 +4447,7 @@ func TestContext2Apply_multiDepose_createBeforeDestroy(t *testing.T) { m := testModule(t, "apply-multi-depose-create-before-destroy") p := testProvider("aws") ps := map[addrs.Provider]providers.Factory{addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p)} - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -4456,7 +4456,7 @@ func TestContext2Apply_multiDepose_createBeforeDestroy(t *testing.T) { }, }, }, - } + }) state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -6328,7 +6328,7 @@ func TestContext2Apply_errorDestroy(t *testing.T) { m := testModule(t, "empty") p := testProvider("test") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test_thing": { Attributes: map[string]*configschema.Attribute{ @@ -6336,7 +6336,7 @@ func TestContext2Apply_errorDestroy(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { // Should actually be called for this test, because Terraform Core // constructs the plan for a destroy operation itself. @@ -6401,7 +6401,7 @@ func TestContext2Apply_errorCreateInvalidNew(t *testing.T) { m := testModule(t, "apply-error") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -6410,7 +6410,7 @@ func TestContext2Apply_errorCreateInvalidNew(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { return providers.PlanResourceChangeResponse{ PlannedState: req.ProposedNewState, @@ -6465,7 +6465,7 @@ func TestContext2Apply_errorUpdateNullNew(t *testing.T) { m := testModule(t, "apply-error") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -6474,7 +6474,7 @@ func TestContext2Apply_errorUpdateNullNew(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { return providers.PlanResourceChangeResponse{ PlannedState: req.ProposedNewState, @@ -7713,7 +7713,7 @@ func TestContext2Apply_unknownAttribute(t *testing.T) { return resp } - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -7724,7 +7724,7 @@ func TestContext2Apply_unknownAttribute(t *testing.T) { }, }, }, - } + }) ctx := testContext2(t, &ContextOpts{ Config: m, @@ -8074,7 +8074,7 @@ func TestContext2Apply_issue7824(t *testing.T) { p := testProvider("template") p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "template_file": { Attributes: map[string]*configschema.Attribute{ @@ -8083,7 +8083,7 @@ func TestContext2Apply_issue7824(t *testing.T) { }, }, }, - } + }) m, snap := testModuleWithSnapshot(t, "issue-7824") @@ -8130,7 +8130,7 @@ func TestContext2Apply_issue5254(t *testing.T) { p := testProvider("template") p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "template_file": { Attributes: map[string]*configschema.Attribute{ @@ -8141,7 +8141,7 @@ func TestContext2Apply_issue5254(t *testing.T) { }, }, }, - } + }) // Apply cleanly step 0 ctx := testContext2(t, &ContextOpts{ @@ -8297,7 +8297,7 @@ func TestContext2Apply_ignoreChangesCreate(t *testing.T) { p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn - instanceSchema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + instanceSchema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block instanceSchema.Attributes["required_field"] = &configschema.Attribute{ Type: cty.String, Required: true, @@ -8441,7 +8441,7 @@ func TestContext2Apply_ignoreChangesWildcard(t *testing.T) { p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn - instanceSchema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + instanceSchema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block instanceSchema.Attributes["required_field"] = &configschema.Attribute{ Type: cty.String, Required: true, @@ -9248,7 +9248,7 @@ func TestContext2Apply_scaleInMultivarRef(t *testing.T) { func TestContext2Apply_inconsistentWithPlan(t *testing.T) { m := testModule(t, "apply-inconsistent-with-plan") p := testProvider("test") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test": { Attributes: map[string]*configschema.Attribute{ @@ -9256,7 +9256,7 @@ func TestContext2Apply_inconsistentWithPlan(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { return providers.PlanResourceChangeResponse{ PlannedState: cty.ObjectVal(map[string]cty.Value{ @@ -9301,7 +9301,7 @@ func TestContext2Apply_inconsistentWithPlan(t *testing.T) { func TestContext2Apply_issue19908(t *testing.T) { m := testModule(t, "apply-issue19908") p := testProvider("test") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test": { Attributes: map[string]*configschema.Attribute{ @@ -9309,7 +9309,7 @@ func TestContext2Apply_issue19908(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { return providers.PlanResourceChangeResponse{ PlannedState: req.ProposedNewState, @@ -9382,7 +9382,7 @@ func TestContext2Apply_issue19908(t *testing.T) { func TestContext2Apply_invalidIndexRef(t *testing.T) { p := testProvider("test") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test_instance": { Attributes: map[string]*configschema.Attribute{ @@ -9390,7 +9390,7 @@ func TestContext2Apply_invalidIndexRef(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = testDiffFn 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{ "aws_instance": instanceSchema, }, - } + }) state := states.NewState() modA := state.EnsureModule(addrs.RootModuleInstance.Child("a", addrs.NoKey)) @@ -9715,7 +9715,7 @@ func TestContext2Apply_taintedDestroyFailure(t *testing.T) { return testApplyFn(req) } - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test_instance": { Attributes: map[string]*configschema.Attribute{ @@ -9730,7 +9730,7 @@ func TestContext2Apply_taintedDestroyFailure(t *testing.T) { }, }, }, - } + }) state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -10037,7 +10037,7 @@ func TestContext2Apply_ProviderMeta_apply_set(t *testing.T) { m := testModule(t, "provider-meta-set") p := testProvider("test") p.PlanResourceChangeFn = testDiffFn - schema := p.GetSchemaReturn + schema := p.ProviderSchema() schema.ProviderMeta = &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "baz": { @@ -10064,7 +10064,7 @@ func TestContext2Apply_ProviderMeta_apply_set(t *testing.T) { NewState: cty.ObjectVal(s), } } - p.GetSchemaReturn = schema + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema) ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -10120,7 +10120,7 @@ func TestContext2Apply_ProviderMeta_apply_unset(t *testing.T) { m := testModule(t, "provider-meta-unset") p := testProvider("test") p.PlanResourceChangeFn = testDiffFn - schema := p.GetSchemaReturn + schema := p.ProviderSchema() schema.ProviderMeta = &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "baz": { @@ -10145,7 +10145,7 @@ func TestContext2Apply_ProviderMeta_apply_unset(t *testing.T) { NewState: cty.ObjectVal(s), } } - p.GetSchemaReturn = schema + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema) ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -10180,7 +10180,7 @@ func TestContext2Apply_ProviderMeta_plan_set(t *testing.T) { m := testModule(t, "provider-meta-set") p := testProvider("test") p.ApplyResourceChangeFn = testApplyFn - schema := p.GetSchemaReturn + schema := p.ProviderSchema() schema.ProviderMeta = &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "baz": { @@ -10196,7 +10196,7 @@ func TestContext2Apply_ProviderMeta_plan_set(t *testing.T) { PlannedState: req.ProposedNewState, } } - p.GetSchemaReturn = schema + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema) ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -10249,7 +10249,7 @@ func TestContext2Apply_ProviderMeta_plan_unset(t *testing.T) { m := testModule(t, "provider-meta-unset") p := testProvider("test") p.ApplyResourceChangeFn = testApplyFn - schema := p.GetSchemaReturn + schema := p.ProviderSchema() schema.ProviderMeta = &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "baz": { @@ -10265,7 +10265,7 @@ func TestContext2Apply_ProviderMeta_plan_unset(t *testing.T) { PlannedState: req.ProposedNewState, } } - p.GetSchemaReturn = schema + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema) ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -10338,7 +10338,7 @@ func TestContext2Apply_ProviderMeta_plan_setInvalid(t *testing.T) { p := testProvider("test") p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn - schema := p.GetSchemaReturn + schema := p.ProviderSchema() schema.ProviderMeta = &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "quux": { @@ -10347,7 +10347,7 @@ func TestContext2Apply_ProviderMeta_plan_setInvalid(t *testing.T) { }, }, } - p.GetSchemaReturn = schema + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema) ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -10392,7 +10392,7 @@ func TestContext2Apply_ProviderMeta_refresh_set(t *testing.T) { p := testProvider("test") p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn - schema := p.GetSchemaReturn + schema := p.ProviderSchema() schema.ProviderMeta = &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "baz": { @@ -10404,14 +10404,14 @@ func TestContext2Apply_ProviderMeta_refresh_set(t *testing.T) { rrcPMs := map[string]cty.Value{} p.ReadResourceFn = func(req providers.ReadResourceRequest) (resp providers.ReadResourceResponse) { 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 { panic(err) } resp.NewState = newState return resp } - p.GetSchemaReturn = schema + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema) ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -10473,7 +10473,7 @@ func TestContext2Apply_ProviderMeta_refresh_setNoSchema(t *testing.T) { p.PlanResourceChangeFn = testDiffFn // we need a schema for plan/apply so they don't error - schema := p.GetSchemaReturn + schema := p.ProviderSchema() schema.ProviderMeta = &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "baz": { @@ -10482,7 +10482,7 @@ func TestContext2Apply_ProviderMeta_refresh_setNoSchema(t *testing.T) { }, }, } - p.GetSchemaReturn = schema + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema) ctx := testContext2(t, &ContextOpts{ Config: m, 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 schema.ProviderMeta = nil - p.GetSchemaReturn = schema + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema) ctx = testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -10542,7 +10542,7 @@ func TestContext2Apply_ProviderMeta_refresh_setInvalid(t *testing.T) { p.PlanResourceChangeFn = testDiffFn // we need a matching schema for plan/apply so they don't error - schema := p.GetSchemaReturn + schema := p.ProviderSchema() schema.ProviderMeta = &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "baz": { @@ -10551,7 +10551,7 @@ func TestContext2Apply_ProviderMeta_refresh_setInvalid(t *testing.T) { }, }, } - p.GetSchemaReturn = schema + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema) ctx := testContext2(t, &ContextOpts{ Config: m, 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{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -10620,7 +10620,7 @@ func TestContext2Apply_ProviderMeta_refreshdata_set(t *testing.T) { p := testProvider("test") p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn - schema := p.GetSchemaReturn + schema := p.ProviderSchema() schema.ProviderMeta = &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "baz": { @@ -10629,7 +10629,7 @@ func TestContext2Apply_ProviderMeta_refreshdata_set(t *testing.T) { }, }, } - p.GetSchemaReturn = schema + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema) ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -10716,7 +10716,7 @@ func TestContext2Apply_ProviderMeta_refreshdata_unset(t *testing.T) { p := testProvider("test") p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn - schema := p.GetSchemaReturn + schema := p.ProviderSchema() schema.ProviderMeta = &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "baz": { @@ -10725,7 +10725,7 @@ func TestContext2Apply_ProviderMeta_refreshdata_unset(t *testing.T) { }, }, } - p.GetSchemaReturn = schema + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema) ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -10831,7 +10831,7 @@ func TestContext2Apply_ProviderMeta_refreshdata_setInvalid(t *testing.T) { p := testProvider("test") p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn - schema := p.GetSchemaReturn + schema := p.ProviderSchema() schema.ProviderMeta = &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "quux": { @@ -10840,7 +10840,7 @@ func TestContext2Apply_ProviderMeta_refreshdata_setInvalid(t *testing.T) { }, }, } - p.GetSchemaReturn = schema + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema) ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -11466,7 +11466,7 @@ output "output" { testP.ReadResourceFn = func(req providers.ReadResourceRequest) providers.ReadResourceResponse { return providers.ReadResourceResponse{NewState: req.PriorState} } - testP.GetSchemaReturn = schemaFn("test") + testP.GetSchemaResponse = getSchemaResponseFromProviderSchema(schemaFn("test")) providerConfig := "" testP.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { @@ -11491,7 +11491,7 @@ output "output" { nullP.ReadResourceFn = func(req providers.ReadResourceRequest) providers.ReadResourceResponse { return providers.ReadResourceResponse{NewState: req.PriorState} } - nullP.GetSchemaReturn = schemaFn("null") + nullP.GetSchemaResponse = getSchemaResponseFromProviderSchema(schemaFn("null")) nullP.ApplyResourceChangeFn = testApplyFn nullP.PlanResourceChangeFn = testDiffFn @@ -11880,7 +11880,7 @@ resource "test_resource" "foo" { p.ReadResourceFn = func(req providers.ReadResourceRequest) providers.ReadResourceResponse { return providers.ReadResourceResponse{NewState: req.PriorState} } - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{}, ResourceTypes: map[string]*configschema.Block{ "test_resource": { @@ -11908,7 +11908,7 @@ resource "test_resource" "foo" { }, }, }, - } + }) p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn @@ -12384,7 +12384,7 @@ resource "test_instance" "a" { return resp } - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test_instance": { Attributes: map[string]*configschema.Attribute{ @@ -12392,7 +12392,7 @@ resource "test_instance" "a" { }, }, }, - } + }) ctx := testContext2(t, &ContextOpts{ Config: m, diff --git a/terraform/context_import_test.go b/terraform/context_import_test.go index bd03438bc5..6aa5892f2f 100644 --- a/terraform/context_import_test.go +++ b/terraform/context_import_test.go @@ -654,7 +654,7 @@ func TestContextImport_multiState(t *testing.T) { p := testProvider("aws") m := testModule(t, "import-provider") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "foo": {Type: cty.String, Optional: true}, @@ -672,7 +672,7 @@ func TestContextImport_multiState(t *testing.T) { }, }, }, - } + }) p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{ ImportedResources: []providers.ImportedResource{ @@ -723,7 +723,7 @@ func TestContextImport_multiStateSame(t *testing.T) { p := testProvider("aws") m := testModule(t, "import-provider") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "foo": {Type: cty.String, Optional: true}, @@ -741,7 +741,7 @@ func TestContextImport_multiStateSame(t *testing.T) { }, }, }, - } + }) p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{ ImportedResources: []providers.ImportedResource{ @@ -829,7 +829,7 @@ resource "test_resource" "unused" { `, }) - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "foo": {Type: cty.String, Optional: true}, @@ -842,7 +842,7 @@ resource "test_resource" "unused" { }, }, }, - } + }) p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{ ImportedResources: []providers.ImportedResource{ diff --git a/terraform/context_input_test.go b/terraform/context_input_test.go index 1887ac97c7..59ec318b08 100644 --- a/terraform/context_input_test.go +++ b/terraform/context_input_test.go @@ -19,7 +19,7 @@ func TestContext2Input_provider(t *testing.T) { p := testProvider("aws") p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "foo": { @@ -39,7 +39,7 @@ func TestContext2Input_provider(t *testing.T) { }, }, }, - } + }) inp := &MockUIInput{ InputReturnMap: map[string]string{ @@ -91,7 +91,7 @@ func TestContext2Input_providerMulti(t *testing.T) { p := testProvider("aws") p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "foo": { @@ -111,7 +111,7 @@ func TestContext2Input_providerMulti(t *testing.T) { }, }, }, - } + }) inp := &MockUIInput{ InputReturnMap: map[string]string{ @@ -180,7 +180,7 @@ func TestContext2Input_providerId(t *testing.T) { p := testProvider("aws") p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "foo": { @@ -200,7 +200,7 @@ func TestContext2Input_providerId(t *testing.T) { }, }, }, - } + }) ctx := testContext2(t, &ContextOpts{ Config: m, @@ -245,7 +245,7 @@ func TestContext2Input_providerOnly(t *testing.T) { p := testProvider("aws") p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "foo": { @@ -263,7 +263,7 @@ func TestContext2Input_providerOnly(t *testing.T) { }, }, }, - } + }) ctx := testContext2(t, &ContextOpts{ Config: m, @@ -405,7 +405,7 @@ func TestContext2Input_dataSourceRequiresRefresh(t *testing.T) { p := testProvider("null") m := testModule(t, "input-module-data-vars") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ DataSources: map[string]*configschema.Block{ "null_data_source": { Attributes: map[string]*configschema.Attribute{ @@ -413,7 +413,7 @@ func TestContext2Input_dataSourceRequiresRefresh(t *testing.T) { }, }, }, - } + }) p.ReadDataSourceFn = func(req providers.ReadDataSourceRequest) providers.ReadDataSourceResponse { return providers.ReadDataSourceResponse{ State: req.Config, diff --git a/terraform/context_plan_test.go b/terraform/context_plan_test.go index a06ba4e826..58cd84dfe7 100644 --- a/terraform/context_plan_test.go +++ b/terraform/context_plan_test.go @@ -56,7 +56,7 @@ func TestContext2Plan_basic(t *testing.T) { t.Fatalf("expected empty state, got %#v\n", ctx.State()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() for _, r := range plan.Changes.Resources { ric, err := r.Decode(ty) @@ -136,7 +136,7 @@ func TestContext2Plan_createBefore_deposed(t *testing.T) { t.Fatalf("\nexpected: %q\ngot: %q\n", expectedState, ctx.State().String()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() type InstanceGen struct { @@ -301,7 +301,7 @@ func TestContext2Plan_escapedVar(t *testing.T) { t.Fatalf("expected resource creation, got %s", res.Action) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() ric, err := res.Decode(ty) @@ -377,7 +377,7 @@ func TestContext2Plan_modules(t *testing.T) { t.Error("expected 3 resource in plan, got", len(plan.Changes.Resources)) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() expectFoo := objectVal(t, schema, map[string]cty.Value{ @@ -433,7 +433,7 @@ func TestContext2Plan_moduleExpand(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() expected := map[string]struct{}{ @@ -470,7 +470,7 @@ func TestContext2Plan_moduleExpand(t *testing.T) { func TestContext2Plan_moduleCycle(t *testing.T) { m := testModule(t, "plan-module-cycle") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -480,7 +480,7 @@ func TestContext2Plan_moduleCycle(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ @@ -495,7 +495,7 @@ func TestContext2Plan_moduleCycle(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -550,7 +550,7 @@ func TestContext2Plan_moduleDeadlock(t *testing.T) { t.Fatalf("err: %s", err) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() for _, res := range plan.Changes.Resources { @@ -595,7 +595,7 @@ func TestContext2Plan_moduleInput(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -650,7 +650,7 @@ func TestContext2Plan_moduleInputComputed(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -708,7 +708,7 @@ func TestContext2Plan_moduleInputFromVar(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -746,7 +746,7 @@ func TestContext2Plan_moduleInputFromVar(t *testing.T) { func TestContext2Plan_moduleMultiVar(t *testing.T) { m := testModule(t, "plan-module-multi-var") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -756,7 +756,7 @@ func TestContext2Plan_moduleMultiVar(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ @@ -771,7 +771,7 @@ func TestContext2Plan_moduleMultiVar(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 5 { @@ -846,7 +846,7 @@ func TestContext2Plan_moduleOrphans(t *testing.T) { if diags.HasErrors() { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -942,7 +942,7 @@ func TestContext2Plan_moduleOrphansWithProvisioner(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 3 { @@ -1008,7 +1008,7 @@ func TestContext2Plan_moduleProviderInherit(t *testing.T) { defer l.Unlock() p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "from": {Type: cty.String, Optional: true}, @@ -1021,7 +1021,7 @@ func TestContext2Plan_moduleProviderInherit(t *testing.T) { }, }, }, - } + }) p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { from := req.Config.GetAttr("from") if from.IsNull() || from.AsString() != "root" { @@ -1072,7 +1072,7 @@ func TestContext2Plan_moduleProviderInheritDeep(t *testing.T) { var from string p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "from": {Type: cty.String, Optional: true}, @@ -1083,7 +1083,7 @@ func TestContext2Plan_moduleProviderInheritDeep(t *testing.T) { Attributes: map[string]*configschema.Attribute{}, }, }, - } + }) p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { v := req.Config.GetAttr("from") @@ -1127,7 +1127,7 @@ func TestContext2Plan_moduleProviderDefaultsVar(t *testing.T) { defer l.Unlock() p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "to": {Type: cty.String, Optional: true}, @@ -1141,7 +1141,7 @@ func TestContext2Plan_moduleProviderDefaultsVar(t *testing.T) { }, }, }, - } + }) p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { var buf bytes.Buffer from := req.Config.GetAttr("from") @@ -1189,7 +1189,7 @@ func TestContext2Plan_moduleProviderDefaultsVar(t *testing.T) { func TestContext2Plan_moduleProviderVar(t *testing.T) { m := testModule(t, "plan-module-provider-var") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "value": {Type: cty.String, Optional: true}, @@ -1202,7 +1202,7 @@ func TestContext2Plan_moduleProviderVar(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ @@ -1217,7 +1217,7 @@ func TestContext2Plan_moduleProviderVar(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 1 { @@ -1260,7 +1260,7 @@ func TestContext2Plan_moduleVar(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -1365,7 +1365,7 @@ func TestContext2Plan_moduleVarComputed(t *testing.T) { if diags.HasErrors() { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -1515,7 +1515,7 @@ func TestContext2Plan_preventDestroy_countBad(t *testing.T) { func TestContext2Plan_preventDestroy_countGood(t *testing.T) { m := testModule(t, "plan-prevent-destroy-count-good") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -1524,7 +1524,7 @@ func TestContext2Plan_preventDestroy_countGood(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = testDiffFn state := states.NewState() @@ -1567,7 +1567,7 @@ func TestContext2Plan_preventDestroy_countGood(t *testing.T) { func TestContext2Plan_preventDestroy_countGoodNoChange(t *testing.T) { m := testModule(t, "plan-prevent-destroy-count-good") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -1577,7 +1577,7 @@ func TestContext2Plan_preventDestroy_countGoodNoChange(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = testDiffFn state := states.NewState() @@ -1682,7 +1682,7 @@ func TestContext2Plan_computed(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -1722,7 +1722,7 @@ func TestContext2Plan_computed(t *testing.T) { func TestContext2Plan_blockNestingGroup(t *testing.T) { m := testModule(t, "plan-block-nesting-group") p := testProvider("test") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test": { BlockTypes: map[string]*configschema.NestedBlock{ @@ -1737,7 +1737,7 @@ func TestContext2Plan_blockNestingGroup(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { return providers.PlanResourceChangeResponse{ PlannedState: req.ProposedNewState, @@ -1794,7 +1794,7 @@ func TestContext2Plan_blockNestingGroup(t *testing.T) { func TestContext2Plan_computedDataResource(t *testing.T) { m := testModule(t, "plan-computed-data-resource") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -1811,7 +1811,7 @@ func TestContext2Plan_computedDataResource(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ @@ -1825,7 +1825,7 @@ func TestContext2Plan_computedDataResource(t *testing.T) { if diags.HasErrors() { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.DataSources["aws_vpc"] + schema := p.GetSchemaResponse.DataSources["aws_vpc"].Block ty := schema.ImpliedType() if rc := plan.Changes.ResourceInstance(addrs.Resource{Mode: addrs.ManagedResourceMode, Type: "aws_instance", Name: "foo"}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance)); rc == nil { @@ -1856,7 +1856,7 @@ func TestContext2Plan_computedDataResource(t *testing.T) { func TestContext2Plan_computedInFunction(t *testing.T) { m := testModule(t, "plan-computed-in-function") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -1871,7 +1871,7 @@ func TestContext2Plan_computedInFunction(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = testDiffFn p.ReadDataSourceResponse = &providers.ReadDataSourceResponse{ State: cty.ObjectVal(map[string]cty.Value{ @@ -1902,7 +1902,7 @@ func TestContext2Plan_computedInFunction(t *testing.T) { func TestContext2Plan_computedDataCountResource(t *testing.T) { m := testModule(t, "plan-computed-data-count") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -1919,7 +1919,7 @@ func TestContext2Plan_computedDataCountResource(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ @@ -1982,7 +1982,7 @@ func TestContext2Plan_dataResourceBecomesComputed(t *testing.T) { m := testModule(t, "plan-data-resource-becomes-computed") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -1999,7 +1999,7 @@ func TestContext2Plan_dataResourceBecomesComputed(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { fooVal := req.ProposedNewState.GetAttr("foo") @@ -2012,7 +2012,7 @@ func TestContext2Plan_dataResourceBecomesComputed(t *testing.T) { } } - schema := p.GetSchemaReturn.DataSources["aws_data_source"] + schema := p.GetSchemaResponse.DataSources["aws_data_source"].Block ty := schema.ImpliedType() p.ReadDataSourceResponse = &providers.ReadDataSourceResponse{ @@ -2075,7 +2075,7 @@ func TestContext2Plan_dataResourceBecomesComputed(t *testing.T) { func TestContext2Plan_computedList(t *testing.T) { m := testModule(t, "plan-computed-list") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -2086,7 +2086,7 @@ func TestContext2Plan_computedList(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ @@ -2101,7 +2101,7 @@ func TestContext2Plan_computedList(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -2141,7 +2141,7 @@ func TestContext2Plan_computedMultiIndex(t *testing.T) { p := testProvider("aws") p.PlanResourceChangeFn = testDiffFn - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -2151,7 +2151,7 @@ func TestContext2Plan_computedMultiIndex(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = testDiffFn @@ -2167,7 +2167,7 @@ func TestContext2Plan_computedMultiIndex(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 3 { @@ -2222,7 +2222,7 @@ func TestContext2Plan_count(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 6 { @@ -2334,7 +2334,7 @@ func TestContext2Plan_countModuleStatic(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 3 { @@ -2388,7 +2388,7 @@ func TestContext2Plan_countModuleStaticGrandchild(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 3 { @@ -2442,7 +2442,7 @@ func TestContext2Plan_countIndex(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -2498,7 +2498,7 @@ func TestContext2Plan_countVar(t *testing.T) { if diags.HasErrors() { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 4 { @@ -2548,7 +2548,7 @@ func TestContext2Plan_countVar(t *testing.T) { func TestContext2Plan_countZero(t *testing.T) { m := testModule(t, "plan-count-zero") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -2556,7 +2556,7 @@ func TestContext2Plan_countZero(t *testing.T) { }, }, }, - } + }) // This schema contains a DynamicPseudoType, and therefore can't go through any shim functions p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { @@ -2576,7 +2576,7 @@ func TestContext2Plan_countZero(t *testing.T) { if diags.HasErrors() { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 1 { @@ -2618,7 +2618,7 @@ func TestContext2Plan_countOneIndex(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -2697,7 +2697,7 @@ func TestContext2Plan_countDecreaseToOne(t *testing.T) { if diags.HasErrors() { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 4 { @@ -2783,7 +2783,7 @@ func TestContext2Plan_countIncreaseFromNotSet(t *testing.T) { if diags.HasErrors() { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 4 { @@ -2862,7 +2862,7 @@ func TestContext2Plan_countIncreaseFromOne(t *testing.T) { if diags.HasErrors() { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 4 { @@ -2955,7 +2955,7 @@ func TestContext2Plan_countIncreaseFromOneCorrupted(t *testing.T) { if diags.HasErrors() { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 5 { @@ -3022,7 +3022,7 @@ func TestContext2Plan_countIncreaseFromOneCorrupted(t *testing.T) { func TestContext2Plan_countIncreaseWithSplatReference(t *testing.T) { m := testModule(t, "plan-count-splat-reference") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -3032,7 +3032,7 @@ func TestContext2Plan_countIncreaseWithSplatReference(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = testDiffFn state := states.NewState() @@ -3083,7 +3083,7 @@ func TestContext2Plan_countIncreaseWithSplatReference(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 6 { @@ -3139,7 +3139,7 @@ func TestContext2Plan_forEach(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 8 { @@ -3228,7 +3228,7 @@ func TestContext2Plan_destroy(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -3291,7 +3291,7 @@ func TestContext2Plan_moduleDestroy(t *testing.T) { if diags.HasErrors() { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -3356,7 +3356,7 @@ func TestContext2Plan_moduleDestroyCycle(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -3419,7 +3419,7 @@ func TestContext2Plan_moduleDestroyMultivar(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -3452,7 +3452,7 @@ func TestContext2Plan_pathVar(t *testing.T) { m := testModule(t, "plan-path-var") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -3462,7 +3462,7 @@ func TestContext2Plan_pathVar(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ @@ -3477,7 +3477,7 @@ func TestContext2Plan_pathVar(t *testing.T) { t.Fatalf("err: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 1 { @@ -3535,7 +3535,7 @@ func TestContext2Plan_diffVar(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -3656,7 +3656,7 @@ func TestContext2Plan_orphan(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -3738,7 +3738,7 @@ func TestContext2Plan_state(t *testing.T) { if len(plan.Changes.Resources) < 2 { t.Fatalf("bad: %#v", plan.Changes.Resources) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -3817,7 +3817,7 @@ func TestContext2Plan_taint(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -3853,7 +3853,7 @@ func TestContext2Plan_taint(t *testing.T) { func TestContext2Plan_taintIgnoreChanges(t *testing.T) { m := testModule(t, "plan-taint-ignore-changes") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -3863,7 +3863,7 @@ func TestContext2Plan_taintIgnoreChanges(t *testing.T) { }, }, }, - } + }) p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn @@ -3891,7 +3891,7 @@ func TestContext2Plan_taintIgnoreChanges(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 1 { @@ -3971,7 +3971,7 @@ func TestContext2Plan_taintDestroyInterpolatedCountRace(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 3 { @@ -4028,7 +4028,7 @@ func TestContext2Plan_targeted(t *testing.T) { if diags.HasErrors() { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 1 { @@ -4077,7 +4077,7 @@ func TestContext2Plan_targetedCrossModule(t *testing.T) { if diags.HasErrors() { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -4114,7 +4114,7 @@ func TestContext2Plan_targetedCrossModule(t *testing.T) { func TestContext2Plan_targetedModuleWithProvider(t *testing.T) { m := testModule(t, "plan-targeted-module-with-provider") p := testProvider("null") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "key": {Type: cty.String, Optional: true}, @@ -4125,7 +4125,7 @@ func TestContext2Plan_targetedModuleWithProvider(t *testing.T) { Attributes: map[string]*configschema.Attribute{}, }, }, - } + }) p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ @@ -4143,7 +4143,7 @@ func TestContext2Plan_targetedModuleWithProvider(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["null_resource"] + schema := p.GetSchemaResponse.ResourceTypes["null_resource"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 1 { @@ -4204,7 +4204,7 @@ func TestContext2Plan_targetedOrphan(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 1 { @@ -4272,7 +4272,7 @@ func TestContext2Plan_targetedModuleOrphan(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 1 { @@ -4315,7 +4315,7 @@ func TestContext2Plan_targetedModuleUntargetedVariable(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -4422,7 +4422,7 @@ func TestContext2Plan_targetedOverTen(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() for _, res := range plan.Changes.Resources { @@ -4521,7 +4521,7 @@ func TestContext2Plan_ignoreChanges(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 1 { @@ -4594,7 +4594,7 @@ func TestContext2Plan_ignoreChangesWildcard(t *testing.T) { func TestContext2Plan_ignoreChangesInMap(t *testing.T) { p := testProvider("test") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test_ignore_changes_map": { Attributes: map[string]*configschema.Attribute{ @@ -4602,7 +4602,7 @@ func TestContext2Plan_ignoreChangesInMap(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { return providers.PlanResourceChangeResponse{ PlannedState: req.ProposedNewState, @@ -4643,7 +4643,7 @@ func TestContext2Plan_ignoreChangesInMap(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["test_ignore_changes_map"] + schema := p.GetSchemaResponse.ResourceTypes["test_ignore_changes_map"].Block ty := schema.ImpliedType() if got, want := len(plan.Changes.Resources), 1; got != want { @@ -4706,7 +4706,7 @@ func TestContext2Plan_ignoreChangesSensitive(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 1 { @@ -4733,7 +4733,7 @@ func TestContext2Plan_ignoreChangesSensitive(t *testing.T) { func TestContext2Plan_moduleMapLiteral(t *testing.T) { m := testModule(t, "plan-module-map-literal") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -4742,7 +4742,7 @@ func TestContext2Plan_moduleMapLiteral(t *testing.T) { }, }, }, - } + }) p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { s := req.ProposedNewState.AsValueMap() @@ -4774,7 +4774,7 @@ func TestContext2Plan_moduleMapLiteral(t *testing.T) { func TestContext2Plan_computedValueInMap(t *testing.T) { m := testModule(t, "plan-computed-value-in-map") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -4787,7 +4787,7 @@ func TestContext2Plan_computedValueInMap(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = testDiffFn p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { resp = testDiffFn(req) @@ -4819,7 +4819,7 @@ func TestContext2Plan_computedValueInMap(t *testing.T) { } for _, res := range plan.Changes.Resources { - schema := p.GetSchemaReturn.ResourceTypes[res.Addr.Resource.Resource.Type] + schema := p.GetSchemaResponse.ResourceTypes[res.Addr.Resource.Resource.Type].Block ric, err := res.Decode(schema.ImpliedType()) if err != nil { @@ -4849,7 +4849,7 @@ func TestContext2Plan_moduleVariableFromSplat(t *testing.T) { m := testModule(t, "plan-module-variable-from-splat") p := testProvider("aws") p.PlanResourceChangeFn = testDiffFn - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -4857,7 +4857,7 @@ func TestContext2Plan_moduleVariableFromSplat(t *testing.T) { }, }, }, - } + }) ctx := testContext2(t, &ContextOpts{ Config: m, @@ -4876,7 +4876,7 @@ func TestContext2Plan_moduleVariableFromSplat(t *testing.T) { } for _, res := range plan.Changes.Resources { - schema := p.GetSchemaReturn.ResourceTypes[res.Addr.Resource.Resource.Type] + schema := p.GetSchemaResponse.ResourceTypes[res.Addr.Resource.Resource.Type].Block ric, err := res.Decode(schema.ImpliedType()) if err != nil { @@ -4904,7 +4904,7 @@ func TestContext2Plan_moduleVariableFromSplat(t *testing.T) { func TestContext2Plan_createBeforeDestroy_depends_datasource(t *testing.T) { m := testModule(t, "plan-cbd-depends-datasource") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -4921,7 +4921,7 @@ func TestContext2Plan_createBeforeDestroy_depends_datasource(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { computedVal := req.ProposedNewState.GetAttr("computed") if computedVal.IsNull() { @@ -4959,9 +4959,9 @@ func TestContext2Plan_createBeforeDestroy_depends_datasource(t *testing.T) { var schema *configschema.Block switch res.Addr.Resource.Resource.Mode { case addrs.DataResourceMode: - schema = p.GetSchemaReturn.DataSources[res.Addr.Resource.Resource.Type] + schema = p.GetSchemaResponse.DataSources[res.Addr.Resource.Resource.Type].Block case addrs.ManagedResourceMode: - schema = p.GetSchemaReturn.ResourceTypes[res.Addr.Resource.Resource.Type] + schema = p.GetSchemaResponse.ResourceTypes[res.Addr.Resource.Resource.Type].Block } ric, err := res.Decode(schema.ImpliedType()) @@ -5010,7 +5010,7 @@ func TestContext2Plan_listOrder(t *testing.T) { p := testProvider("aws") p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -5018,7 +5018,7 @@ func TestContext2Plan_listOrder(t *testing.T) { }, }, }, - } + }) ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -5056,7 +5056,7 @@ func TestContext2Plan_ignoreChangesWithFlatmaps(t *testing.T) { m := testModule(t, "plan-ignore-changes-with-flatmaps") p := testProvider("aws") p.PlanResourceChangeFn = testDiffFn - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -5072,7 +5072,7 @@ func TestContext2Plan_ignoreChangesWithFlatmaps(t *testing.T) { }, }, }, - } + }) state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -5107,7 +5107,7 @@ func TestContext2Plan_ignoreChangesWithFlatmaps(t *testing.T) { } res := plan.Changes.Resources[0] - schema := p.GetSchemaReturn.ResourceTypes[res.Addr.Resource.Resource.Type] + schema := p.GetSchemaResponse.ResourceTypes[res.Addr.Resource.Resource.Type].Block ric, err := res.Decode(schema.ImpliedType()) if err != nil { @@ -5288,7 +5288,7 @@ func TestContext2Plan_computedAttrRefTypeMismatch(t *testing.T) { func TestContext2Plan_selfRef(t *testing.T) { p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -5296,7 +5296,7 @@ func TestContext2Plan_selfRef(t *testing.T) { }, }, }, - } + }) m := testModule(t, "plan-self-ref") c := testContext2(t, &ContextOpts{ @@ -5325,7 +5325,7 @@ func TestContext2Plan_selfRef(t *testing.T) { func TestContext2Plan_selfRefMulti(t *testing.T) { p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -5333,7 +5333,7 @@ func TestContext2Plan_selfRefMulti(t *testing.T) { }, }, }, - } + }) m := testModule(t, "plan-self-ref-multi") c := testContext2(t, &ContextOpts{ @@ -5362,7 +5362,7 @@ func TestContext2Plan_selfRefMulti(t *testing.T) { func TestContext2Plan_selfRefMultiAll(t *testing.T) { p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -5370,7 +5370,7 @@ func TestContext2Plan_selfRefMultiAll(t *testing.T) { }, }, }, - } + }) m := testModule(t, "plan-self-ref-multi-all") c := testContext2(t, &ContextOpts{ @@ -5548,7 +5548,7 @@ func TestContext2Plan_variableSensitivity(t *testing.T) { if diags.HasErrors() { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 1 { @@ -5615,7 +5615,7 @@ func TestContext2Plan_variableSensitivityModule(t *testing.T) { if diags.HasErrors() { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 1 { @@ -5688,7 +5688,7 @@ func objectVal(t *testing.T, schema *configschema.Block, m map[string]cty.Value) func TestContext2Plan_requiredModuleOutput(t *testing.T) { m := testModule(t, "plan-required-output") p := testProvider("test") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test_resource": { Attributes: map[string]*configschema.Attribute{ @@ -5697,7 +5697,7 @@ func TestContext2Plan_requiredModuleOutput(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ @@ -5712,7 +5712,7 @@ func TestContext2Plan_requiredModuleOutput(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["test_resource"] + schema := p.GetSchemaResponse.ResourceTypes["test_resource"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -5753,7 +5753,7 @@ func TestContext2Plan_requiredModuleOutput(t *testing.T) { func TestContext2Plan_requiredModuleObject(t *testing.T) { m := testModule(t, "plan-required-whole-mod") p := testProvider("test") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test_resource": { Attributes: map[string]*configschema.Attribute{ @@ -5762,7 +5762,7 @@ func TestContext2Plan_requiredModuleObject(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ @@ -5777,7 +5777,7 @@ func TestContext2Plan_requiredModuleObject(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["test_resource"] + schema := p.GetSchemaResponse.ResourceTypes["test_resource"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 2 { @@ -6097,7 +6097,7 @@ data "test_data_source" "foo" {} }) p := new(MockProvider) - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ DataSources: map[string]*configschema.Block{ "test_data_source": { Attributes: map[string]*configschema.Attribute{ @@ -6112,7 +6112,7 @@ data "test_data_source" "foo" {} }, }, }, - } + }) p.ReadDataSourceResponse = &providers.ReadDataSourceResponse{ State: cty.ObjectVal(map[string]cty.Value{ @@ -6224,7 +6224,7 @@ func TestContext2Plan_targetedModuleInstance(t *testing.T) { if diags.HasErrors() { t.Fatalf("unexpected errors: %s", diags.Err()) } - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() if len(plan.Changes.Resources) != 1 { @@ -6458,7 +6458,7 @@ resource "test_instance" "a" { return resp } - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test_instance": { Attributes: map[string]*configschema.Attribute{ @@ -6466,7 +6466,7 @@ resource "test_instance" "a" { }, }, }, - } + }) ctx := testContext2(t, &ContextOpts{ Config: m, @@ -6515,7 +6515,7 @@ resource "test_instance" "a" { return resp } - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test_instance": { Attributes: map[string]*configschema.Attribute{ @@ -6524,7 +6524,7 @@ resource "test_instance" "a" { }, }, }, - } + }) state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -6569,7 +6569,7 @@ resource "test_instance" "a" { }) p := testProvider("test") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test_instance": { Attributes: map[string]*configschema.Attribute{ @@ -6578,7 +6578,7 @@ resource "test_instance" "a" { }, }, }, - } + }) p.PlanResourceChangeFn = testDiffFn p.ValidateResourceTypeConfigFn = func(req providers.ValidateResourceTypeConfigRequest) providers.ValidateResourceTypeConfigResponse { var diags tfdiags.Diagnostics diff --git a/terraform/context_refresh_test.go b/terraform/context_refresh_test.go index 77d03bf549..51601d9be0 100644 --- a/terraform/context_refresh_test.go +++ b/terraform/context_refresh_test.go @@ -41,7 +41,7 @@ func TestContext2Refresh(t *testing.T) { State: state, }) - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() readState, err := hcl2shim.HCL2ValueFromFlatmap(map[string]string{"id": "foo", "foo": "baz"}, ty) if err != nil { @@ -105,7 +105,7 @@ func TestContext2Refresh_dynamicAttr(t *testing.T) { }) p := testProvider("test") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test_instance": { Attributes: map[string]*configschema.Attribute{ @@ -113,7 +113,7 @@ func TestContext2Refresh_dynamicAttr(t *testing.T) { }, }, }, - } + }) p.ReadResourceFn = func(req providers.ReadResourceRequest) providers.ReadResourceResponse { return providers.ReadResourceResponse{ NewState: readStateVal, @@ -132,7 +132,7 @@ func TestContext2Refresh_dynamicAttr(t *testing.T) { State: startingState, }) - schema := p.GetSchemaReturn.ResourceTypes["test_instance"] + schema := p.GetSchemaResponse.ResourceTypes["test_instance"].Block ty := schema.ImpliedType() s, diags := ctx.Refresh() @@ -169,7 +169,7 @@ func TestContext2Refresh_dataComputedModuleVar(t *testing.T) { return resp } - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{}, ResourceTypes: map[string]*configschema.Block{ "aws_instance": { @@ -199,7 +199,7 @@ func TestContext2Refresh_dataComputedModuleVar(t *testing.T) { }, }, }, - } + }) ctx := testContext2(t, &ContextOpts{ Config: m, @@ -220,7 +220,7 @@ func TestContext2Refresh_dataComputedModuleVar(t *testing.T) { func TestContext2Refresh_targeted(t *testing.T) { p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{}, ResourceTypes: map[string]*configschema.Block{ "aws_elb": { @@ -252,7 +252,7 @@ func TestContext2Refresh_targeted(t *testing.T) { }, }, }, - } + }) state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -297,7 +297,7 @@ func TestContext2Refresh_targeted(t *testing.T) { func TestContext2Refresh_targetedCount(t *testing.T) { p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{}, ResourceTypes: map[string]*configschema.Block{ "aws_elb": { @@ -329,7 +329,7 @@ func TestContext2Refresh_targetedCount(t *testing.T) { }, }, }, - } + }) state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -384,7 +384,7 @@ func TestContext2Refresh_targetedCount(t *testing.T) { func TestContext2Refresh_targetedCountIndex(t *testing.T) { p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{}, ResourceTypes: map[string]*configschema.Block{ "aws_elb": { @@ -416,7 +416,7 @@ func TestContext2Refresh_targetedCountIndex(t *testing.T) { }, }, }, - } + }) state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -463,7 +463,7 @@ func TestContext2Refresh_targetedCountIndex(t *testing.T) { func TestContext2Refresh_moduleComputedVar(t *testing.T) { p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{}, ResourceTypes: map[string]*configschema.Block{ "aws_instance": { @@ -479,7 +479,7 @@ func TestContext2Refresh_moduleComputedVar(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = testDiffFn m := testModule(t, "refresh-module-computed-var") @@ -515,7 +515,7 @@ func TestContext2Refresh_delete(t *testing.T) { p.ReadResourceFn = nil 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 @@ -641,7 +641,7 @@ func TestContext2Refresh_moduleInputComputedOutput(t *testing.T) { m := testModule(t, "refresh-module-input-computed-output") p := testProvider("aws") p.PlanResourceChangeFn = testDiffFn - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{}, ResourceTypes: map[string]*configschema.Block{ "aws_instance": { @@ -658,7 +658,7 @@ func TestContext2Refresh_moduleInputComputedOutput(t *testing.T) { }, }, }, - } + }) ctx := testContext2(t, &ContextOpts{ Config: m, @@ -714,7 +714,7 @@ func TestContext2Refresh_noState(t *testing.T) { func TestContext2Refresh_output(t *testing.T) { p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{}, ResourceTypes: map[string]*configschema.Block{ "aws_instance": { @@ -731,7 +731,7 @@ func TestContext2Refresh_output(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = testDiffFn 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. p.PlanResourceChangeFn = testDiffFn - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{}, ResourceTypes: map[string]*configschema.Block{ "aws_instance": { @@ -782,11 +782,11 @@ func TestContext2Refresh_outputPartial(t *testing.T) { }, }, }, - } + }) p.ReadResourceFn = nil 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() @@ -829,7 +829,7 @@ func TestContext2Refresh_stateBasic(t *testing.T) { State: state, }) - schema := p.GetSchemaReturn.ResourceTypes["aws_instance"] + schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block ty := schema.ImpliedType() 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) return resp } - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test": { Attributes: map[string]*configschema.Attribute{ @@ -887,7 +887,7 @@ func TestContext2Refresh_dataCount(t *testing.T) { DataSources: map[string]*configschema.Block{ "test": {}, }, - } + }) p.ReadDataSourceFn = func(req providers.ReadDataSourceRequest) providers.ReadDataSourceResponse { return providers.ReadDataSourceResponse{ @@ -924,12 +924,12 @@ func TestContext2Refresh_dataState(t *testing.T) { } p := testProvider("null") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{}, DataSources: map[string]*configschema.Block{ "null_data_source": schema, }, - } + }) ctx := testContext2(t, &ContextOpts{ Config: m, @@ -974,7 +974,7 @@ func TestContext2Refresh_dataState(t *testing.T) { func TestContext2Refresh_dataStateRefData(t *testing.T) { p := testProvider("null") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{}, DataSources: map[string]*configschema.Block{ "null_data_source": { @@ -994,7 +994,7 @@ func TestContext2Refresh_dataStateRefData(t *testing.T) { }, }, }, - } + }) m := testModule(t, "refresh-data-ref-data") state := states.NewState() @@ -1115,10 +1115,10 @@ func TestContext2Refresh_vars(t *testing.T) { }, } - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{}, ResourceTypes: map[string]*configschema.Block{"aws_instance": schema}, - } + }) m := testModule(t, "refresh-vars") state := states.NewState() @@ -1248,7 +1248,7 @@ func TestContext2Refresh_orphanModule(t *testing.T) { func TestContext2Validate(t *testing.T) { p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{}, ResourceTypes: map[string]*configschema.Block{ "aws_instance": { @@ -1264,7 +1264,7 @@ func TestContext2Validate(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = testDiffFn m := testModule(t, "validate-good") @@ -1318,7 +1318,7 @@ aws_instance.bar: func TestContext2Refresh_schemaUpgradeFlatmap(t *testing.T) { m := testModule(t, "refresh-schema-upgrade") p := testProvider("test") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test_thing": { Attributes: map[string]*configschema.Attribute{ @@ -1332,7 +1332,7 @@ func TestContext2Refresh_schemaUpgradeFlatmap(t *testing.T) { ResourceTypeSchemaVersions: map[string]uint64{ "test_thing": 5, }, - } + }) p.UpgradeResourceStateResponse = &providers.UpgradeResourceStateResponse{ UpgradedState: cty.ObjectVal(map[string]cty.Value{ "name": cty.StringVal("foo"), @@ -1405,7 +1405,7 @@ test_thing.bar: func TestContext2Refresh_schemaUpgradeJSON(t *testing.T) { m := testModule(t, "refresh-schema-upgrade") p := testProvider("test") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test_thing": { Attributes: map[string]*configschema.Attribute{ @@ -1419,7 +1419,7 @@ func TestContext2Refresh_schemaUpgradeJSON(t *testing.T) { ResourceTypeSchemaVersions: map[string]uint64{ "test_thing": 5, }, - } + }) p.UpgradeResourceStateResponse = &providers.UpgradeResourceStateResponse{ UpgradedState: cty.ObjectVal(map[string]cty.Value{ "name": cty.StringVal("foo"), @@ -1527,7 +1527,7 @@ data "aws_data_source" "foo" { func TestContext2Refresh_dataResourceDependsOn(t *testing.T) { m := testModule(t, "plan-data-depends-on") p := testProvider("test") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test_resource": { Attributes: map[string]*configschema.Attribute{ @@ -1543,7 +1543,7 @@ func TestContext2Refresh_dataResourceDependsOn(t *testing.T) { }, }, }, - } + }) p.PlanResourceChangeFn = testDiffFn p.ReadDataSourceResponse = &providers.ReadDataSourceResponse{ State: cty.ObjectVal(map[string]cty.Value{ diff --git a/terraform/context_test.go b/terraform/context_test.go index e934606cf0..9da413b3e7 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -405,7 +405,7 @@ func testProvider(prefix string) *MockProvider { return providers.ReadResourceResponse{NewState: req.PriorState} } - p.GetSchemaReturn = testProviderSchema(prefix) + p.GetSchemaResponse = testProviderSchema(prefix) return p } @@ -465,8 +465,8 @@ func testCheckDeadlock(t *testing.T, f func()) { } } -func testProviderSchema(name string) *ProviderSchema { - return &ProviderSchema{ +func testProviderSchema(name string) *providers.GetSchemaResponse { + return getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "region": { @@ -708,8 +708,7 @@ func testProviderSchema(name string) *ProviderSchema { }, }, }, - } - + }) } // contextForPlanViaFile is a helper that creates a temporary plan file, then diff --git a/terraform/context_validate_test.go b/terraform/context_validate_test.go index 9db6eb51c1..aeddbf35b6 100644 --- a/terraform/context_validate_test.go +++ b/terraform/context_validate_test.go @@ -18,13 +18,13 @@ import ( func TestContext2Validate_badCount(t *testing.T) { p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{}, }, }, - } + }) m := testModule(t, "validate-bad-count") c := testContext2(t, &ContextOpts{ @@ -42,13 +42,13 @@ func TestContext2Validate_badCount(t *testing.T) { func TestContext2Validate_badResource_reference(t *testing.T) { p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{}, }, }, - } + }) m := testModule(t, "validate-bad-resource-count") c := testContext2(t, &ContextOpts{ @@ -66,7 +66,7 @@ func TestContext2Validate_badResource_reference(t *testing.T) { func TestContext2Validate_badVar(t *testing.T) { p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ @@ -75,7 +75,7 @@ func TestContext2Validate_badVar(t *testing.T) { }, }, }, - } + }) m := testModule(t, "validate-bad-var") c := testContext2(t, &ContextOpts{ @@ -94,7 +94,7 @@ func TestContext2Validate_badVar(t *testing.T) { func TestContext2Validate_varMapOverrideOld(t *testing.T) { m := testModule(t, "validate-module-pc-vars") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ + p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{ Provider: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "foo": {Type: cty.String, Optional: true}, @@ -105,7 +105,7 @@ func TestContext2Validate_varMapOverrideOld(t *testing.T) { Attributes: map[string]*configschema.Attribute{}, }, }, - } + }) _, diags := NewContext(&ContextOpts{ Config: m, @@ -133,25 +133,31 @@ func TestContext2Validate_varNoDefaultExplicitType(t *testing.T) { func TestContext2Validate_computedVar(t *testing.T) { p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - Provider: &configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "value": {Type: cty.String, Optional: true}, + p.GetSchemaResponse = &providers.GetSchemaResponse{ + Provider: providers.Schema{ + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "value": {Type: cty.String, Optional: true}, + }, }, }, - ResourceTypes: map[string]*configschema.Block{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{}, + }, }, }, } pt := testProvider("test") - pt.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + pt.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "test_instance": { - Attributes: map[string]*configschema.Attribute{ - "id": {Type: cty.String, Computed: true}, - "value": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Computed: true}, + "value": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -186,19 +192,23 @@ func TestContext2Validate_computedVar(t *testing.T) { func TestContext2Validate_computedInFunction(t *testing.T) { p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{ - "attr": {Type: cty.Number, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "attr": {Type: cty.Number, Optional: true}, + }, }, }, }, - DataSources: map[string]*configschema.Block{ + DataSources: map[string]providers.Schema{ "aws_data_source": { - Attributes: map[string]*configschema.Attribute{ - "optional_attr": {Type: cty.String, Optional: true}, - "computed": {Type: cty.String, Computed: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "optional_attr": {Type: cty.String, Optional: true}, + "computed": {Type: cty.String, Computed: true}, + }, }, }, }, @@ -223,17 +233,21 @@ func TestContext2Validate_computedInFunction(t *testing.T) { // can be realized during a plan. func TestContext2Validate_countComputed(t *testing.T) { p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{}, + }, }, }, - DataSources: map[string]*configschema.Block{ + DataSources: map[string]providers.Schema{ "aws_data_source": { - Attributes: map[string]*configschema.Attribute{ - "compute": {Type: cty.String, Optional: true}, - "value": {Type: cty.String, Computed: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "compute": {Type: cty.String, Optional: true}, + "value": {Type: cty.String, Computed: true}, + }, }, }, }, @@ -255,14 +269,15 @@ func TestContext2Validate_countComputed(t *testing.T) { func TestContext2Validate_countNegative(t *testing.T) { p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{}, + }, }, }, } - m := testModule(t, "validate-count-negative") c := testContext2(t, &ContextOpts{ Config: m, @@ -279,16 +294,17 @@ func TestContext2Validate_countNegative(t *testing.T) { func TestContext2Validate_countVariable(t *testing.T) { p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{ - "foo": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "foo": {Type: cty.String, Optional: true}, + }, }, }, }, } - m := testModule(t, "apply-count-variable") c := testContext2(t, &ContextOpts{ Config: m, @@ -306,16 +322,17 @@ func TestContext2Validate_countVariable(t *testing.T) { func TestContext2Validate_countVariableNoDefault(t *testing.T) { p := testProvider("aws") m := testModule(t, "validate-count-variable") - p.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{ - "foo": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "foo": {Type: cty.String, Optional: true}, + }, }, }, }, } - _, diags := NewContext(&ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -330,16 +347,17 @@ func TestContext2Validate_countVariableNoDefault(t *testing.T) { func TestContext2Validate_moduleBadOutput(t *testing.T) { p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{ - "foo": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "foo": {Type: cty.String, Optional: true}, + }, }, }, }, } - m := testModule(t, "validate-bad-module-output") c := testContext2(t, &ContextOpts{ Config: m, @@ -356,16 +374,17 @@ func TestContext2Validate_moduleBadOutput(t *testing.T) { func TestContext2Validate_moduleGood(t *testing.T) { p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{ - "foo": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "foo": {Type: cty.String, Optional: true}, + }, }, }, }, } - m := testModule(t, "validate-good-module") c := testContext2(t, &ContextOpts{ Config: m, @@ -383,10 +402,12 @@ func TestContext2Validate_moduleGood(t *testing.T) { func TestContext2Validate_moduleBadResource(t *testing.T) { m := testModule(t, "validate-module-bad-rc") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{}, + }, }, }, } @@ -411,11 +432,13 @@ func TestContext2Validate_moduleBadResource(t *testing.T) { func TestContext2Validate_moduleDepsShouldNotCycle(t *testing.T) { m := testModule(t, "validate-module-deps-cycle") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{ - "id": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -437,19 +460,23 @@ func TestContext2Validate_moduleDepsShouldNotCycle(t *testing.T) { func TestContext2Validate_moduleProviderVar(t *testing.T) { m := testModule(t, "validate-module-pc-vars") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - Provider: &configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "foo": {Type: cty.String, Optional: true}, - }, - }, - ResourceTypes: map[string]*configschema.Block{ - "aws_instance": { + p.GetSchemaResponse = &providers.GetSchemaResponse{ + Provider: providers.Schema{ + Block: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "foo": {Type: cty.String, Optional: true}, }, }, }, + ResourceTypes: map[string]providers.Schema{ + "aws_instance": { + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "foo": {Type: cty.String, Optional: true}, + }, + }, + }, + }, } c := testContext2(t, &ContextOpts{ @@ -481,19 +508,23 @@ func TestContext2Validate_moduleProviderVar(t *testing.T) { func TestContext2Validate_moduleProviderInheritUnused(t *testing.T) { m := testModule(t, "validate-module-pc-inherit-unused") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - Provider: &configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "foo": {Type: cty.String, Optional: true}, - }, - }, - ResourceTypes: map[string]*configschema.Block{ - "aws_instance": { + p.GetSchemaResponse = &providers.GetSchemaResponse{ + Provider: providers.Schema{ + Block: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "foo": {Type: cty.String, Optional: true}, }, }, }, + ResourceTypes: map[string]providers.Schema{ + "aws_instance": { + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "foo": {Type: cty.String, Optional: true}, + }, + }, + }, + }, } c := testContext2(t, &ContextOpts{ @@ -518,12 +549,14 @@ func TestContext2Validate_moduleProviderInheritUnused(t *testing.T) { func TestContext2Validate_orphans(t *testing.T) { p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{ - "foo": {Type: cty.String, Optional: true}, - "num": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "foo": {Type: cty.String, Optional: true}, + "num": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -562,15 +595,19 @@ func TestContext2Validate_orphans(t *testing.T) { func TestContext2Validate_providerConfig_bad(t *testing.T) { m := testModule(t, "validate-bad-pc") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - Provider: &configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "foo": {Type: cty.String, Optional: true}, + p.GetSchemaResponse = &providers.GetSchemaResponse{ + Provider: providers.Schema{ + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "foo": {Type: cty.String, Optional: true}, + }, }, }, - ResourceTypes: map[string]*configschema.Block{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{}, + }, }, }, } @@ -598,15 +635,19 @@ func TestContext2Validate_providerConfig_bad(t *testing.T) { func TestContext2Validate_providerConfig_skippedEmpty(t *testing.T) { m := testModule(t, "validate-skipped-pc-empty") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - Provider: &configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "foo": {Type: cty.String, Optional: true}, + p.GetSchemaResponse = &providers.GetSchemaResponse{ + Provider: providers.Schema{ + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "foo": {Type: cty.String, Optional: true}, + }, }, }, - ResourceTypes: map[string]*configschema.Block{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{}, + }, }, }, } @@ -631,15 +672,19 @@ func TestContext2Validate_providerConfig_skippedEmpty(t *testing.T) { func TestContext2Validate_providerConfig_good(t *testing.T) { m := testModule(t, "validate-bad-pc") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - Provider: &configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "foo": {Type: cty.String, Optional: true}, + p.GetSchemaResponse = &providers.GetSchemaResponse{ + Provider: providers.Schema{ + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "foo": {Type: cty.String, Optional: true}, + }, }, }, - ResourceTypes: map[string]*configschema.Block{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{}, + }, }, }, } @@ -663,15 +708,19 @@ func TestContext2Validate_requiredProviderConfig(t *testing.T) { m := testModule(t, "validate-required-provider-config") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - Provider: &configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "required_attribute": {Type: cty.String, Required: true}, + p.GetSchemaResponse = &providers.GetSchemaResponse{ + Provider: providers.Schema{ + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "required_attribute": {Type: cty.String, Required: true}, + }, }, }, - ResourceTypes: map[string]*configschema.Block{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{}, + }, }, }, } @@ -692,11 +741,13 @@ func TestContext2Validate_requiredProviderConfig(t *testing.T) { func TestContext2Validate_provisionerConfig_bad(t *testing.T) { m := testModule(t, "validate-bad-prov-conf") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{ - "foo": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "foo": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -727,11 +778,13 @@ func TestContext2Validate_provisionerConfig_bad(t *testing.T) { func TestContext2Validate_badResourceConnection(t *testing.T) { m := testModule(t, "validate-bad-resource-connection") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{ - "foo": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "foo": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -759,11 +812,13 @@ func TestContext2Validate_badResourceConnection(t *testing.T) { func TestContext2Validate_badProvisionerConnection(t *testing.T) { m := testModule(t, "validate-bad-prov-connection") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{ - "foo": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "foo": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -791,19 +846,23 @@ func TestContext2Validate_badProvisionerConnection(t *testing.T) { func TestContext2Validate_provisionerConfig_good(t *testing.T) { m := testModule(t, "validate-bad-prov-conf") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - Provider: &configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "foo": {Type: cty.String, Optional: true}, - }, - }, - ResourceTypes: map[string]*configschema.Block{ - "aws_instance": { + p.GetSchemaResponse = &providers.GetSchemaResponse{ + Provider: providers.Schema{ + Block: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "foo": {Type: cty.String, Optional: true}, }, }, }, + ResourceTypes: map[string]providers.Schema{ + "aws_instance": { + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "foo": {Type: cty.String, Optional: true}, + }, + }, + }, + }, } pr := simpleMockProvisioner() @@ -836,16 +895,17 @@ func TestContext2Validate_provisionerConfig_good(t *testing.T) { func TestContext2Validate_requiredVar(t *testing.T) { m := testModule(t, "validate-required-var") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{ - "ami": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "ami": {Type: cty.String, Optional: true}, + }, }, }, }, } - _, diags := NewContext(&ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -861,16 +921,17 @@ func TestContext2Validate_requiredVar(t *testing.T) { func TestContext2Validate_resourceConfig_bad(t *testing.T) { m := testModule(t, "validate-bad-rc") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{ - "foo": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "foo": {Type: cty.String, Optional: true}, + }, }, }, }, } - c := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -891,16 +952,17 @@ func TestContext2Validate_resourceConfig_bad(t *testing.T) { func TestContext2Validate_resourceConfig_good(t *testing.T) { m := testModule(t, "validate-bad-rc") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{ - "foo": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "foo": {Type: cty.String, Optional: true}, + }, }, }, }, } - c := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -916,12 +978,14 @@ func TestContext2Validate_resourceConfig_good(t *testing.T) { func TestContext2Validate_tainted(t *testing.T) { p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{ - "foo": {Type: cty.String, Optional: true}, - "num": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "foo": {Type: cty.String, Optional: true}, + "num": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -962,12 +1026,14 @@ func TestContext2Validate_targetedDestroy(t *testing.T) { pr := simpleMockProvisioner() p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn - p.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{ - "foo": {Type: cty.String, Optional: true}, - "num": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "foo": {Type: cty.String, Optional: true}, + "num": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -1004,11 +1070,13 @@ func TestContext2Validate_targetedDestroy(t *testing.T) { func TestContext2Validate_varRefUnknown(t *testing.T) { m := testModule(t, "validate-variable-ref") p := testProvider("aws") - p.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{ - "foo": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "foo": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -1051,11 +1119,13 @@ func TestContext2Validate_interpolateVar(t *testing.T) { p := testProvider("null") p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn - p.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "template_file": { - Attributes: map[string]*configschema.Attribute{ - "template": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "template": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -1084,11 +1154,13 @@ func TestContext2Validate_interpolateComputedModuleVarDef(t *testing.T) { p := testProvider("aws") p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = testDiffFn - p.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "aws_instance": { - Attributes: map[string]*configschema.Attribute{ - "attr": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "attr": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -1867,11 +1939,13 @@ resource "test_instance" "a" { }) p := testProvider("test") - p.GetSchemaReturn = &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "test_instance": { - Attributes: map[string]*configschema.Attribute{ - "id": {Type: cty.String, Computed: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Computed: true}, + }, }, }, }, diff --git a/terraform/graph_builder_plan_test.go b/terraform/graph_builder_plan_test.go index 84fec87403..3da3cf16a7 100644 --- a/terraform/graph_builder_plan_test.go +++ b/terraform/graph_builder_plan_test.go @@ -16,23 +16,16 @@ func TestPlanGraphBuilder_impl(t *testing.T) { func TestPlanGraphBuilder(t *testing.T) { awsProvider := &MockProvider{ - GetSchemaReturn: &ProviderSchema{ - Provider: simpleTestSchema(), - ResourceTypes: map[string]*configschema.Block{ - "aws_security_group": simpleTestSchema(), - "aws_instance": simpleTestSchema(), - "aws_load_balancer": simpleTestSchema(), - }, - }, - } - openstackProvider := &MockProvider{ - GetSchemaReturn: &ProviderSchema{ - Provider: simpleTestSchema(), - ResourceTypes: map[string]*configschema.Block{ - "openstack_floating_ip": simpleTestSchema(), + GetSchemaResponse: &providers.GetSchemaResponse{ + Provider: providers.Schema{Block: simpleTestSchema()}, + ResourceTypes: map[string]providers.Schema{ + "aws_security_group": {Block: simpleTestSchema()}, + "aws_instance": {Block: simpleTestSchema()}, + "aws_load_balancer": {Block: simpleTestSchema()}, }, }, } + openstackProvider := mockProviderWithResourceTypeSchema("openstack_floating_ip", simpleTestSchema()) components := &basicComponentFactory{ providers: map[addrs.Provider]providers.Factory{ addrs.NewDefaultProvider("aws"): providers.FactoryFixed(awsProvider), @@ -45,8 +38,8 @@ func TestPlanGraphBuilder(t *testing.T) { Components: components, Schemas: &Schemas{ Providers: map[addrs.Provider]*ProviderSchema{ - addrs.NewDefaultProvider("aws"): awsProvider.GetSchemaReturn, - addrs.NewDefaultProvider("openstack"): openstackProvider.GetSchemaReturn, + addrs.NewDefaultProvider("aws"): awsProvider.ProviderSchema(), + addrs.NewDefaultProvider("openstack"): openstackProvider.ProviderSchema(), }, }, } @@ -68,28 +61,22 @@ func TestPlanGraphBuilder(t *testing.T) { } func TestPlanGraphBuilder_dynamicBlock(t *testing.T) { - provider := &MockProvider{ - GetSchemaReturn: &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ - "test_thing": { + provider := mockProviderWithResourceTypeSchema("test_thing", &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Computed: true}, + "list": {Type: cty.List(cty.String), Computed: true}, + }, + BlockTypes: map[string]*configschema.NestedBlock{ + "nested": { + Nesting: configschema.NestingList, + Block: configschema.Block{ Attributes: map[string]*configschema.Attribute{ - "id": {Type: cty.String, Computed: true}, - "list": {Type: cty.List(cty.String), Computed: true}, - }, - BlockTypes: map[string]*configschema.NestedBlock{ - "nested": { - Nesting: configschema.NestingList, - Block: configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "foo": {Type: cty.String, Optional: true}, - }, - }, - }, + "foo": {Type: cty.String, Optional: true}, }, }, }, }, - } + }) components := &basicComponentFactory{ providers: map[addrs.Provider]providers.Factory{ addrs.NewDefaultProvider("test"): providers.FactoryFixed(provider), @@ -101,7 +88,7 @@ func TestPlanGraphBuilder_dynamicBlock(t *testing.T) { Components: components, Schemas: &Schemas{ Providers: map[addrs.Provider]*ProviderSchema{ - addrs.NewDefaultProvider("test"): provider.GetSchemaReturn, + addrs.NewDefaultProvider("test"): provider.ProviderSchema(), }, }, } @@ -144,23 +131,17 @@ test_thing.c (expand) } func TestPlanGraphBuilder_attrAsBlocks(t *testing.T) { - provider := &MockProvider{ - GetSchemaReturn: &ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ - "test_thing": { - Attributes: map[string]*configschema.Attribute{ - "id": {Type: cty.String, Computed: true}, - "nested": { - Type: cty.List(cty.Object(map[string]cty.Type{ - "foo": cty.String, - })), - Optional: true, - }, - }, - }, + provider := mockProviderWithResourceTypeSchema("test_thing", &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Computed: true}, + "nested": { + Type: cty.List(cty.Object(map[string]cty.Type{ + "foo": cty.String, + })), + Optional: true, }, }, - } + }) components := &basicComponentFactory{ providers: map[addrs.Provider]providers.Factory{ addrs.NewDefaultProvider("test"): providers.FactoryFixed(provider), @@ -172,7 +153,7 @@ func TestPlanGraphBuilder_attrAsBlocks(t *testing.T) { Components: components, Schemas: &Schemas{ 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) { - awsProvider := &MockProvider{ - GetSchemaReturn: &ProviderSchema{ - Provider: simpleTestSchema(), - ResourceTypes: map[string]*configschema.Block{ - "aws_instance": simpleTestSchema(), - }, - }, - } + awsProvider := mockProviderWithResourceTypeSchema("aws_instance", simpleTestSchema()) components := &basicComponentFactory{ providers: map[addrs.Provider]providers.Factory{ @@ -253,7 +227,7 @@ func TestPlanGraphBuilder_forEach(t *testing.T) { Components: components, Schemas: &Schemas{ Providers: map[addrs.Provider]*ProviderSchema{ - addrs.NewDefaultProvider("aws"): awsProvider.GetSchemaReturn, + addrs.NewDefaultProvider("aws"): awsProvider.ProviderSchema(), }, }, } diff --git a/terraform/node_provider_test.go b/terraform/node_provider_test.go index 6a20049cde..5b42979382 100644 --- a/terraform/node_provider_test.go +++ b/terraform/node_provider_test.go @@ -231,18 +231,14 @@ func TestNodeApplyableProviderExecute_emptyValidate(t *testing.T) { } func TestNodeApplyableProvider_Validate(t *testing.T) { - provider := &MockProvider{ - GetSchemaReturn: &ProviderSchema{ - Provider: &configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "region": { - Type: cty.String, - Required: true, - }, - }, + provider := mockProviderWithConfigSchema(&configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "region": { + Type: cty.String, + Required: true, }, }, - } + }) ctx := &MockEvalContext{ProviderProvider: provider} ctx.installSimpleEval() @@ -307,18 +303,14 @@ func TestNodeApplyableProvider_Validate(t *testing.T) { //TestNodeApplyableProvider_ConfigProvider_config_fn_err for //providers.ConfigureRequest responses. func TestNodeApplyableProvider_ConfigProvider(t *testing.T) { - provider := &MockProvider{ - GetSchemaReturn: &ProviderSchema{ - Provider: &configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "region": { - Type: cty.String, - Optional: true, - }, - }, + provider := mockProviderWithConfigSchema(&configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "region": { + Type: cty.String, + Optional: true, }, }, - } + }) // For this test, we're returning an error for an optional argument. This // can happen for example if an argument is only conditionally required. 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 func TestNodeApplyableProvider_ConfigProvider_config_fn_err(t *testing.T) { - provider := &MockProvider{ - GetSchemaReturn: &ProviderSchema{ - Provider: &configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "region": { - Type: cty.String, - Optional: true, - }, - }, + provider := mockProviderWithConfigSchema(&configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "region": { + Type: cty.String, + Optional: true, }, }, - } + }) ctx := &MockEvalContext{ProviderProvider: provider} ctx.installSimpleEval() // For this test, provider.PrepareConfigFn will succeed every time but the diff --git a/terraform/node_resource_abstract_instance_test.go b/terraform/node_resource_abstract_instance_test.go index 3802937512..ff00147c8c 100644 --- a/terraform/node_resource_abstract_instance_test.go +++ b/terraform/node_resource_abstract_instance_test.go @@ -143,7 +143,7 @@ func TestNodeAbstractResourceInstance_WriteResourceInstanceState(t *testing.T) { }, } ctx.ProviderProvider = mockProvider - ctx.ProviderSchemaSchema = mockProvider.GetSchemaReturn + ctx.ProviderSchemaSchema = mockProvider.ProviderSchema() err := node.writeResourceInstanceState(ctx, obj, nil, workingState) if err != nil { diff --git a/terraform/node_resource_abstract_test.go b/terraform/node_resource_abstract_test.go index c92b110cdc..a0075889dc 100644 --- a/terraform/node_resource_abstract_test.go +++ b/terraform/node_resource_abstract_test.go @@ -157,7 +157,7 @@ func TestNodeAbstractResource_ReadResourceInstanceState(t *testing.T) { ctx := new(MockEvalContext) ctx.StateState = test.State.SyncWrapper() ctx.PathPath = addrs.RootModuleInstance - ctx.ProviderSchemaSchema = mockProvider.GetSchemaReturn + ctx.ProviderSchemaSchema = mockProvider.ProviderSchema() ctx.ProviderProvider = providers.Interface(mockProvider) 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.StateState = test.State.SyncWrapper() ctx.PathPath = addrs.RootModuleInstance - ctx.ProviderSchemaSchema = mockProvider.GetSchemaReturn + ctx.ProviderSchemaSchema = mockProvider.ProviderSchema() ctx.ProviderProvider = providers.Interface(mockProvider) key := states.DeposedKey("00000001") // shim from legacy state assigns 0th deposed index this key diff --git a/terraform/node_resource_destroy_deposed_test.go b/terraform/node_resource_destroy_deposed_test.go index 86d9657dfe..8f4d50b27f 100644 --- a/terraform/node_resource_destroy_deposed_test.go +++ b/terraform/node_resource_destroy_deposed_test.go @@ -143,7 +143,7 @@ func TestNodeDestroyDeposedResourceInstanceObject_WriteResourceInstanceState(t * }, }) ctx.ProviderProvider = mockProvider - ctx.ProviderSchemaSchema = mockProvider.GetSchemaReturn + ctx.ProviderSchemaSchema = mockProvider.ProviderSchema() obj := &states.ResourceInstanceObject{ Value: cty.ObjectVal(map[string]cty.Value{ diff --git a/terraform/node_resource_validate_test.go b/terraform/node_resource_validate_test.go index 8be38eaad9..9cc8726ffc 100644 --- a/terraform/node_resource_validate_test.go +++ b/terraform/node_resource_validate_test.go @@ -188,7 +188,7 @@ func TestNodeValidatableResource_ValidateResource_managedResource(t *testing.T) ctx := &MockEvalContext{} ctx.installSimpleEval() - ctx.ProviderSchemaSchema = mp.GetSchemaReturn + ctx.ProviderSchemaSchema = mp.ProviderSchema() ctx.ProviderProvider = p err := node.validateResource(ctx) @@ -218,7 +218,7 @@ func TestNodeValidatableResource_ValidateResource_managedResourceCount(t *testin ctx := &MockEvalContext{} ctx.installSimpleEval() - ctx.ProviderSchemaSchema = mp.GetSchemaReturn + ctx.ProviderSchemaSchema = mp.ProviderSchema() ctx.ProviderProvider = p tests := []struct { @@ -302,7 +302,7 @@ func TestNodeValidatableResource_ValidateResource_dataSource(t *testing.T) { ctx := &MockEvalContext{} ctx.installSimpleEval() - ctx.ProviderSchemaSchema = mp.GetSchemaReturn + ctx.ProviderSchemaSchema = mp.ProviderSchema() ctx.ProviderProvider = p diags := node.validateResource(ctx) @@ -338,7 +338,7 @@ func TestNodeValidatableResource_ValidateResource_valid(t *testing.T) { ctx := &MockEvalContext{} ctx.installSimpleEval() - ctx.ProviderSchemaSchema = mp.GetSchemaReturn + ctx.ProviderSchemaSchema = mp.ProviderSchema() ctx.ProviderProvider = p diags := node.validateResource(ctx) @@ -375,7 +375,7 @@ func TestNodeValidatableResource_ValidateResource_warningsAndErrorsPassedThrough ctx := &MockEvalContext{} ctx.installSimpleEval() - ctx.ProviderSchemaSchema = mp.GetSchemaReturn + ctx.ProviderSchemaSchema = mp.ProviderSchema() ctx.ProviderProvider = p diags := node.validateResource(ctx) @@ -437,7 +437,8 @@ func TestNodeValidatableResource_ValidateResource_invalidDependsOn(t *testing.T) ctx := &MockEvalContext{} ctx.installSimpleEval() - ctx.ProviderSchemaSchema = mp.GetSchemaReturn + + ctx.ProviderSchemaSchema = mp.ProviderSchema() ctx.ProviderProvider = p diags := node.validateResource(ctx) diff --git a/terraform/provider_mock.go b/terraform/provider_mock.go index bfa1e704d0..789ec94488 100644 --- a/terraform/provider_mock.go +++ b/terraform/provider_mock.go @@ -1,12 +1,13 @@ package terraform import ( - "errors" + "fmt" "sync" ctyjson "github.com/zclconf/go-cty/cty/json" "github.com/zclconf/go-cty/cty/msgpack" + "github.com/hashicorp/terraform/configs/configschema" "github.com/hashicorp/terraform/configs/hcl2shim" "github.com/hashicorp/terraform/providers" ) @@ -21,8 +22,8 @@ type MockProvider struct { // Anything you want, in case you need to store extra data with the mock. Meta interface{} - GetSchemaCalled bool - GetSchemaReturn *ProviderSchema // This is using ProviderSchema directly rather than providers.GetSchemaResponse for compatibility with old tests + GetSchemaCalled bool + GetSchemaResponse *providers.GetSchemaResponse PrepareProviderConfigCalled bool 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 // call from other methods of this mock as long as they are already // holding the lock. + if p.GetSchemaResponse != nil { + return *p.GetSchemaResponse + } - ret := providers.GetSchemaResponse{ + return providers.GetSchemaResponse{ Provider: providers.Schema{}, DataSources: 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 } -func (p *MockProvider) getResourceSchema(name string) providers.Schema { - schema := p.getSchema() - resSchema, ok := schema.ResourceTypes[name] - if !ok { - panic("unknown resource type " + name) - } - return resSchema -} +// ProviderSchema is a helper to convert from the internal GetSchemaResponse to +// a ProviderSchema. +func (p *MockProvider) ProviderSchema() *ProviderSchema { + resp := p.getSchema() -func (p *MockProvider) getDatasourceSchema(name string) providers.Schema { - schema := p.getSchema() - dataSchema, ok := schema.DataSources[name] - if !ok { - panic("unknown data source " + name) + schema := &ProviderSchema{ + Provider: resp.Provider.Block, + ProviderMeta: resp.ProviderMeta.Block, + ResourceTypes: map[string]*configschema.Block{}, + DataSources: map[string]*configschema.Block{}, + ResourceTypeSchemaVersions: map[string]uint64{}, } - return dataSchema + + for resType, s := range resp.ResourceTypes { + schema.ResourceTypes[resType] = s.Block + schema.ResourceTypeSchemaVersions[resType] = uint64(s.Version) + } + + for dataSource, s := range resp.DataSources { + schema.DataSources[dataSource] = s.Block + } + + return schema } 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, // 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()) if err != nil { resp.Diagnostics = resp.Diagnostics.Append(err) @@ -192,7 +191,11 @@ func (p *MockProvider) ValidateDataSourceConfig(r providers.ValidateDataSourceCo p.ValidateDataSourceConfigRequest = r // 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()) if err != nil { resp.Diagnostics = resp.Diagnostics.Append(err) @@ -214,8 +217,12 @@ func (p *MockProvider) UpgradeResourceState(r providers.UpgradeResourceStateRequ p.Lock() defer p.Unlock() - schemas := p.getSchema() - schema := schemas.ResourceTypes[r.TypeName] + 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 + } + schemaType := schema.Block.ImpliedType() p.UpgradeResourceStateCalled = true @@ -298,7 +305,13 @@ func (p *MockProvider) ReadResource(r providers.ReadResourceRequest) (resp provi // Make sure the NewState conforms to the schema. // 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 { resp.Diagnostics = resp.Diagnostics.Append(err) } @@ -326,6 +339,12 @@ func (p *MockProvider) PlanResourceChange(r providers.PlanResourceChangeRequest) 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 } @@ -342,6 +361,7 @@ func (p *MockProvider) ApplyResourceChange(r providers.ApplyResourceChangeReques if p.ApplyResourceChangeResponse != nil { return *p.ApplyResourceChangeResponse } + return resp } @@ -359,14 +379,14 @@ func (p *MockProvider) ImportResourceState(r providers.ImportResourceStateReques resp = *p.ImportResourceStateResponse // fixup the cty value to match the schema for i, res := range resp.ImportedResources { - schema := p.GetSchemaReturn.ResourceTypes[res.TypeName] - if schema == nil { - resp.Diagnostics = resp.Diagnostics.Append(errors.New("no schema found for " + res.TypeName)) + schema, ok := p.getSchema().ResourceTypes[res.TypeName] + if !ok { + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("no schema found for %q", res.TypeName)) return resp } var err error - res.State, err = schema.CoerceValue(res.State) + res.State, err = schema.Block.CoerceValue(res.State) if err != nil { resp.Diagnostics = resp.Diagnostics.Append(err) return resp @@ -393,6 +413,7 @@ func (p *MockProvider) ReadDataSource(r providers.ReadDataSourceRequest) (resp p if p.ReadDataSourceResponse != nil { resp = *p.ReadDataSourceResponse } + return resp } diff --git a/terraform/resource_provider_mock_test.go b/terraform/resource_provider_mock_test.go index 1b7414f59b..3bf73d7f9c 100644 --- a/terraform/resource_provider_mock_test.go +++ b/terraform/resource_provider_mock_test.go @@ -2,6 +2,7 @@ package terraform import ( "github.com/hashicorp/terraform/configs/configschema" + "github.com/hashicorp/terraform/providers" "github.com/zclconf/go-cty/cty" ) @@ -9,8 +10,8 @@ import ( // provider with the given schema for its own configuration. func mockProviderWithConfigSchema(schema *configschema.Block) *MockProvider { return &MockProvider{ - GetSchemaReturn: &ProviderSchema{ - Provider: schema, + GetSchemaResponse: &providers.GetSchemaResponse{ + Provider: providers.Schema{Block: schema}, }, } } @@ -19,30 +20,83 @@ func mockProviderWithConfigSchema(schema *configschema.Block) *MockProvider { // provider with a schema containing a single resource type. func mockProviderWithResourceTypeSchema(name string, schema *configschema.Block) *MockProvider { return &MockProvider{ - GetSchemaReturn: &ProviderSchema{ - Provider: &configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "string": { - Type: cty.String, - Optional: true, - }, - "list": { - Type: cty.List(cty.String), - Optional: true, - }, - "root": { - Type: cty.Map(cty.String), - Optional: true, + GetSchemaResponse: &providers.GetSchemaResponse{ + Provider: providers.Schema{ + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "string": { + Type: cty.String, + Optional: true, + }, + "list": { + Type: cty.List(cty.String), + Optional: true, + }, + "root": { + Type: cty.Map(cty.String), + Optional: true, + }, }, }, }, - 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 // with schema for its own config, for a resource type called "test_object" and // 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. func simpleMockProvider() *MockProvider { return &MockProvider{ - GetSchemaReturn: &ProviderSchema{ - Provider: simpleTestSchema(), - ResourceTypes: map[string]*configschema.Block{ - "test_object": simpleTestSchema(), + GetSchemaResponse: &providers.GetSchemaResponse{ + Provider: providers.Schema{Block: simpleTestSchema()}, + ResourceTypes: map[string]providers.Schema{ + "test_object": providers.Schema{Block: simpleTestSchema()}, }, - DataSources: map[string]*configschema.Block{ - "test_object": simpleTestSchema(), + DataSources: map[string]providers.Schema{ + "test_object": providers.Schema{Block: simpleTestSchema()}, }, }, } diff --git a/terraform/schemas_test.go b/terraform/schemas_test.go index 06b20f73fc..b871884aea 100644 --- a/terraform/schemas_test.go +++ b/terraform/schemas_test.go @@ -8,9 +8,10 @@ import ( func simpleTestSchemas() *Schemas { provider := simpleMockProvider() provisioner := simpleMockProvisioner() + return &Schemas{ Providers: map[addrs.Provider]*ProviderSchema{ - addrs.NewDefaultProvider("test"): provider.GetSchemaReturn, + addrs.NewDefaultProvider("test"): provider.ProviderSchema(), }, Provisioners: map[string]*configschema.Block{ "test": provisioner.GetSchemaResponse.Provisioner,