diff --git a/backend/local/backend_apply_test.go b/backend/local/backend_apply_test.go index adf7c08fe..106853e7c 100644 --- a/backend/local/backend_apply_test.go +++ b/backend/local/backend_apply_test.go @@ -27,7 +27,7 @@ func TestLocal_applyBasic(t *testing.T) { defer cleanup() p := TestLocalProvider(t, b, "test", applyFixtureSchema()) - p.ApplyResourceChangeResponse = providers.ApplyResourceChangeResponse{NewState: cty.ObjectVal(map[string]cty.Value{ + p.ApplyResourceChangeResponse = &providers.ApplyResourceChangeResponse{NewState: cty.ObjectVal(map[string]cty.Value{ "id": cty.StringVal("yes"), "ami": cty.StringVal("bar"), })} @@ -70,7 +70,7 @@ func TestLocal_applyEmptyDir(t *testing.T) { defer cleanup() p := TestLocalProvider(t, b, "test", &terraform.ProviderSchema{}) - p.ApplyResourceChangeResponse = providers.ApplyResourceChangeResponse{NewState: cty.ObjectVal(map[string]cty.Value{"id": cty.StringVal("yes")})} + p.ApplyResourceChangeResponse = &providers.ApplyResourceChangeResponse{NewState: cty.ObjectVal(map[string]cty.Value{"id": cty.StringVal("yes")})} op, configCleanup := testOperationApply(t, "./testdata/empty") defer configCleanup() @@ -101,7 +101,7 @@ func TestLocal_applyEmptyDirDestroy(t *testing.T) { defer cleanup() p := TestLocalProvider(t, b, "test", &terraform.ProviderSchema{}) - p.ApplyResourceChangeResponse = providers.ApplyResourceChangeResponse{} + p.ApplyResourceChangeResponse = &providers.ApplyResourceChangeResponse{} op, configCleanup := testOperationApply(t, "./testdata/empty") defer configCleanup() @@ -193,7 +193,7 @@ func TestLocal_applyBackendFail(t *testing.T) { defer cleanup() p := TestLocalProvider(t, b, "test", applyFixtureSchema()) - p.ApplyResourceChangeResponse = providers.ApplyResourceChangeResponse{NewState: cty.ObjectVal(map[string]cty.Value{ + p.ApplyResourceChangeResponse = &providers.ApplyResourceChangeResponse{NewState: cty.ObjectVal(map[string]cty.Value{ "id": cty.StringVal("yes"), "ami": cty.StringVal("bar"), })} diff --git a/backend/local/backend_refresh_test.go b/backend/local/backend_refresh_test.go index 73b223df3..6062ed0d6 100644 --- a/backend/local/backend_refresh_test.go +++ b/backend/local/backend_refresh_test.go @@ -24,7 +24,7 @@ func TestLocal_refresh(t *testing.T) { testStateFile(t, b.StatePath, testRefreshState()) p.ReadResourceFn = nil - p.ReadResourceResponse = providers.ReadResourceResponse{NewState: cty.ObjectVal(map[string]cty.Value{ + p.ReadResourceResponse = &providers.ReadResourceResponse{NewState: cty.ObjectVal(map[string]cty.Value{ "id": cty.StringVal("yes"), })} @@ -76,7 +76,7 @@ func TestLocal_refreshInput(t *testing.T) { testStateFile(t, b.StatePath, testRefreshState()) p.ReadResourceFn = nil - p.ReadResourceResponse = providers.ReadResourceResponse{NewState: cty.ObjectVal(map[string]cty.Value{ + p.ReadResourceResponse = &providers.ReadResourceResponse{NewState: cty.ObjectVal(map[string]cty.Value{ "id": cty.StringVal("yes"), })} p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { @@ -119,7 +119,7 @@ func TestLocal_refreshValidate(t *testing.T) { p := TestLocalProvider(t, b, "test", refreshFixtureSchema()) testStateFile(t, b.StatePath, testRefreshState()) p.ReadResourceFn = nil - p.ReadResourceResponse = providers.ReadResourceResponse{NewState: cty.ObjectVal(map[string]cty.Value{ + p.ReadResourceResponse = &providers.ReadResourceResponse{NewState: cty.ObjectVal(map[string]cty.Value{ "id": cty.StringVal("yes"), })} @@ -165,7 +165,7 @@ func TestLocal_refreshValidateProviderConfigured(t *testing.T) { p := TestLocalProvider(t, b, "test", schema) testStateFile(t, b.StatePath, testRefreshState()) p.ReadResourceFn = nil - p.ReadResourceResponse = providers.ReadResourceResponse{NewState: cty.ObjectVal(map[string]cty.Value{ + p.ReadResourceResponse = &providers.ReadResourceResponse{NewState: cty.ObjectVal(map[string]cty.Value{ "id": cty.StringVal("yes"), })} diff --git a/backend/local/testing.go b/backend/local/testing.go index 0e6d426f1..e5dc47b7c 100644 --- a/backend/local/testing.go +++ b/backend/local/testing.go @@ -72,7 +72,21 @@ func TestLocalProvider(t *testing.T, b *Local, name string, schema *terraform.Pr if schema == nil { schema = &terraform.ProviderSchema{} // default schema is empty } - p.GetSchemaReturn = schema + p.GetSchemaResponse = &providers.GetSchemaResponse{ + Provider: providers.Schema{Block: schema.Provider}, + ProviderMeta: providers.Schema{Block: schema.ProviderMeta}, + ResourceTypes: map[string]providers.Schema{}, + DataSources: map[string]providers.Schema{}, + } + for name, res := range schema.ResourceTypes { + p.GetSchemaResponse.ResourceTypes[name] = providers.Schema{ + Block: res, + Version: int64(schema.ResourceTypeSchemaVersions[name]), + } + } + for name, dat := range schema.DataSources { + p.GetSchemaResponse.DataSources[name] = providers.Schema{Block: dat} + } p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { rSchema, _ := schema.SchemaForResourceType(addrs.ManagedResourceMode, req.TypeName) diff --git a/backend/remote/testing.go b/backend/remote/testing.go index 9f152b5d1..07ea95358 100644 --- a/backend/remote/testing.go +++ b/backend/remote/testing.go @@ -175,7 +175,7 @@ func testLocalBackend(t *testing.T, remote *Remote) backend.Enhanced { }, }, }) - p.ApplyResourceChangeResponse = providers.ApplyResourceChangeResponse{NewState: cty.ObjectVal(map[string]cty.Value{ + p.ApplyResourceChangeResponse = &providers.ApplyResourceChangeResponse{NewState: cty.ObjectVal(map[string]cty.Value{ "id": cty.StringVal("yes"), })} diff --git a/command/apply_destroy_test.go b/command/apply_destroy_test.go index 6acffdf75..cbe14ae4e 100644 --- a/command/apply_destroy_test.go +++ b/command/apply_destroy_test.go @@ -14,7 +14,6 @@ import ( "github.com/hashicorp/terraform/providers" "github.com/hashicorp/terraform/states" "github.com/hashicorp/terraform/states/statefile" - "github.com/hashicorp/terraform/terraform" ) func TestApply_destroy(t *testing.T) { @@ -38,12 +37,14 @@ func TestApply_destroy(t *testing.T) { statePath := testStateFile(t, originalState) p := testProvider() - p.GetSchemaReturn = &terraform.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}, - "ami": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Computed: true}, + "ami": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -225,17 +226,21 @@ func TestApply_destroyTargeted(t *testing.T) { statePath := testStateFile(t, originalState) p := testProvider() - p.GetSchemaReturn = &terraform.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}, + }, }, }, "test_load_balancer": { - Attributes: map[string]*configschema.Attribute{ - "id": {Type: cty.String, Computed: true}, - "instances": {Type: cty.List(cty.String), Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Computed: true}, + "instances": {Type: cty.List(cty.String), Optional: true}, + }, }, }, }, diff --git a/command/apply_test.go b/command/apply_test.go index cf2935eaf..407be0afd 100644 --- a/command/apply_test.go +++ b/command/apply_test.go @@ -177,9 +177,9 @@ func TestApply_parallelism(t *testing.T) { for i := 0; i < 10; i++ { name := fmt.Sprintf("test%d", i) provider := &terraform.MockProvider{} - provider.GetSchemaReturn = &terraform.ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ - name + "_instance": {}, + provider.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ + name + "_instance": {Block: &configschema.Block{}}, }, } provider.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { @@ -359,13 +359,15 @@ func TestApply_error(t *testing.T) { resp.PlannedState = cty.ObjectVal(s) return } - p.GetSchemaReturn = &terraform.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, Optional: true, Computed: true}, - "ami": {Type: cty.String, Optional: true}, - "error": {Type: cty.Bool, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true, Computed: true}, + "ami": {Type: cty.String, Optional: true}, + "error": {Type: cty.Bool, Optional: true}, + }, }, }, }, @@ -903,11 +905,13 @@ func TestApply_shutdown(t *testing.T) { return } - p.GetSchemaReturn = &terraform.ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "test_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}, + }, }, }, }, @@ -959,12 +963,12 @@ func TestApply_state(t *testing.T) { statePath := testStateFile(t, originalState) p := applyFixtureProvider() - p.PlanResourceChangeResponse = providers.PlanResourceChangeResponse{ + p.PlanResourceChangeResponse = &providers.PlanResourceChangeResponse{ PlannedState: cty.ObjectVal(map[string]cty.Value{ "ami": cty.StringVal("bar"), }), } - p.ApplyResourceChangeResponse = providers.ApplyResourceChangeResponse{ + p.ApplyResourceChangeResponse = &providers.ApplyResourceChangeResponse{ NewState: cty.ObjectVal(map[string]cty.Value{ "ami": cty.StringVal("bar"), }), @@ -1089,11 +1093,13 @@ func TestApply_vars(t *testing.T) { } actual := "" - p.GetSchemaReturn = &terraform.ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "test_instance": { - Attributes: map[string]*configschema.Attribute{ - "value": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "value": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -1143,11 +1149,13 @@ func TestApply_varFile(t *testing.T) { } actual := "" - p.GetSchemaReturn = &terraform.ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "test_instance": { - Attributes: map[string]*configschema.Attribute{ - "value": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "value": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -1207,11 +1215,13 @@ func TestApply_varFileDefault(t *testing.T) { } actual := "" - p.GetSchemaReturn = &terraform.ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "test_instance": { - Attributes: map[string]*configschema.Attribute{ - "value": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "value": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -1270,11 +1280,13 @@ func TestApply_varFileDefaultJSON(t *testing.T) { } actual := "" - p.GetSchemaReturn = &terraform.ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "test_instance": { - Attributes: map[string]*configschema.Attribute{ - "value": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "value": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -1327,7 +1339,7 @@ func TestApply_backup(t *testing.T) { backupPath := testTempFile(t) p := applyFixtureProvider() - p.PlanResourceChangeResponse = providers.PlanResourceChangeResponse{ + p.PlanResourceChangeResponse = &providers.PlanResourceChangeResponse{ PlannedState: cty.ObjectVal(map[string]cty.Value{ "ami": cty.StringVal("bar"), }), @@ -1381,7 +1393,7 @@ func TestApply_disableBackup(t *testing.T) { statePath := testStateFile(t, originalState) p := applyFixtureProvider() - p.PlanResourceChangeResponse = providers.PlanResourceChangeResponse{ + p.PlanResourceChangeResponse = &providers.PlanResourceChangeResponse{ PlannedState: cty.ObjectVal(map[string]cty.Value{ "ami": cty.StringVal("bar"), }), @@ -1538,13 +1550,15 @@ output = test // applyFixtureSchema returns a schema suitable for processing the // configuration in testdata/apply . This schema should be // assigned to a mock provider named "test". -func applyFixtureSchema() *terraform.ProviderSchema { - return &terraform.ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ +func applyFixtureSchema() *providers.GetSchemaResponse { + return &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "test_instance": { - Attributes: map[string]*configschema.Attribute{ - "id": {Type: cty.String, Optional: true, Computed: true}, - "ami": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true, Computed: true}, + "ami": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -1553,12 +1567,12 @@ func applyFixtureSchema() *terraform.ProviderSchema { // applyFixtureProvider returns a mock provider that is configured for basic // operation with the configuration in testdata/apply. This mock has -// GetSchemaReturn, PlanResourceChangeFn, and ApplyResourceChangeFn populated, +// GetSchemaResponse, PlanResourceChangeFn, and ApplyResourceChangeFn populated, // with the plan/apply steps just passing through the data determined by // Terraform Core. func applyFixtureProvider() *terraform.MockProvider { p := testProvider() - p.GetSchemaReturn = applyFixtureSchema() + p.GetSchemaResponse = applyFixtureSchema() p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { return providers.PlanResourceChangeResponse{ PlannedState: req.ProposedNewState, diff --git a/command/console_test.go b/command/console_test.go index 921e664db..b4fa2915c 100644 --- a/command/console_test.go +++ b/command/console_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/hashicorp/terraform/configs/configschema" - "github.com/hashicorp/terraform/terraform" + "github.com/hashicorp/terraform/providers" "github.com/mitchellh/cli" "github.com/zclconf/go-cty/cty" ) @@ -62,16 +62,17 @@ func TestConsole_tfvars(t *testing.T) { } p := testProvider() - p.GetSchemaReturn = &terraform.ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "test_instance": { - Attributes: map[string]*configschema.Attribute{ - "value": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "value": {Type: cty.String, Optional: true}, + }, }, }, }, } - ui := cli.NewMockUi() c := &ConsoleCommand{ Meta: Meta{ @@ -110,11 +111,13 @@ func TestConsole_unsetRequiredVars(t *testing.T) { defer testFixCwd(t, tmp, cwd) p := testProvider() - p.GetSchemaReturn = &terraform.ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "test_instance": { - Attributes: map[string]*configschema.Attribute{ - "value": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "value": {Type: cty.String, Optional: true}, + }, }, }, }, diff --git a/command/format/state_test.go b/command/format/state_test.go index 5d83200bc..103b4bc2d 100644 --- a/command/format/state_test.go +++ b/command/format/state_test.go @@ -92,43 +92,49 @@ func testProvider() *terraform.MockProvider { return providers.ReadResourceResponse{NewState: req.PriorState} } - p.GetSchemaReturn = testProviderSchema() + p.GetSchemaResponse = testProviderSchema() return p } -func testProviderSchema() *terraform.ProviderSchema { - return &terraform.ProviderSchema{ - Provider: &configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "region": {Type: cty.String, Optional: true}, +func testProviderSchema() *providers.GetSchemaResponse { + return &providers.GetSchemaResponse{ + Provider: providers.Schema{ + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "region": {Type: cty.String, Optional: true}, + }, }, }, - ResourceTypes: map[string]*configschema.Block{ + ResourceTypes: map[string]providers.Schema{ "test_resource": { - Attributes: map[string]*configschema.Attribute{ - "id": {Type: cty.String, Computed: true}, - "foo": {Type: cty.String, Optional: true}, - "woozles": {Type: cty.String, Optional: true}, - }, - BlockTypes: map[string]*configschema.NestedBlock{ - "nested": { - Nesting: configschema.NestingList, - Block: configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "compute": {Type: cty.String, Optional: true}, - "value": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Computed: true}, + "foo": {Type: cty.String, Optional: true}, + "woozles": {Type: cty.String, Optional: true}, + }, + BlockTypes: map[string]*configschema.NestedBlock{ + "nested": { + Nesting: configschema.NestingList, + Block: configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "compute": {Type: cty.String, Optional: true}, + "value": {Type: cty.String, Optional: true}, + }, }, }, }, }, }, }, - DataSources: map[string]*configschema.Block{ + DataSources: map[string]providers.Schema{ "test_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}, + }, }, }, }, @@ -139,7 +145,7 @@ func testSchemas() *terraform.Schemas { provider := testProvider() return &terraform.Schemas{ Providers: map[addrs.Provider]*terraform.ProviderSchema{ - addrs.NewDefaultProvider("test"): provider.GetSchemaReturn, + addrs.NewDefaultProvider("test"): provider.ProviderSchema(), }, } } diff --git a/command/import_test.go b/command/import_test.go index e90b0cbe1..354b20536 100644 --- a/command/import_test.go +++ b/command/import_test.go @@ -14,7 +14,6 @@ import ( "github.com/hashicorp/terraform/configs/configschema" "github.com/hashicorp/terraform/internal/copy" "github.com/hashicorp/terraform/providers" - "github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/tfdiags" ) @@ -33,7 +32,7 @@ func TestImport(t *testing.T) { } p.ImportResourceStateFn = nil - p.ImportResourceStateResponse = providers.ImportResourceStateResponse{ + p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{ ImportedResources: []providers.ImportedResource{ { TypeName: "test_instance", @@ -43,11 +42,13 @@ func TestImport(t *testing.T) { }, }, } - p.GetSchemaReturn = &terraform.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, Optional: true, Computed: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true, Computed: true}, + }, }, }, }, @@ -84,7 +85,7 @@ func TestImport_providerConfig(t *testing.T) { } p.ImportResourceStateFn = nil - p.ImportResourceStateResponse = providers.ImportResourceStateResponse{ + p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{ ImportedResources: []providers.ImportedResource{ { TypeName: "test_instance", @@ -94,16 +95,20 @@ func TestImport_providerConfig(t *testing.T) { }, }, } - p.GetSchemaReturn = &terraform.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{ "test_instance": { - Attributes: map[string]*configschema.Attribute{ - "id": {Type: cty.String, Optional: true, Computed: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true, Computed: true}, + }, }, }, }, @@ -191,7 +196,7 @@ func TestImport_remoteState(t *testing.T) { } p.ImportResourceStateFn = nil - p.ImportResourceStateResponse = providers.ImportResourceStateResponse{ + p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{ ImportedResources: []providers.ImportedResource{ { TypeName: "test_instance", @@ -201,16 +206,20 @@ func TestImport_remoteState(t *testing.T) { }, }, } - p.GetSchemaReturn = &terraform.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{ "test_instance": { - Attributes: map[string]*configschema.Attribute{ - "id": {Type: cty.String, Optional: true, Computed: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true, Computed: true}, + }, }, }, }, @@ -338,7 +347,7 @@ func TestImport_providerConfigWithVar(t *testing.T) { } p.ImportResourceStateFn = nil - p.ImportResourceStateResponse = providers.ImportResourceStateResponse{ + p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{ ImportedResources: []providers.ImportedResource{ { TypeName: "test_instance", @@ -348,16 +357,20 @@ func TestImport_providerConfigWithVar(t *testing.T) { }, }, } - p.GetSchemaReturn = &terraform.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{ "test_instance": { - Attributes: map[string]*configschema.Attribute{ - "id": {Type: cty.String, Optional: true, Computed: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true, Computed: true}, + }, }, }, }, @@ -412,7 +425,7 @@ func TestImport_providerConfigWithDataSource(t *testing.T) { } p.ImportResourceStateFn = nil - p.ImportResourceStateResponse = providers.ImportResourceStateResponse{ + p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{ ImportedResources: []providers.ImportedResource{ { TypeName: "test_instance", @@ -422,23 +435,29 @@ func TestImport_providerConfigWithDataSource(t *testing.T) { }, }, } - p.GetSchemaReturn = &terraform.ProviderSchema{ - Provider: &configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "foo": {Type: cty.String, Optional: true}, - }, - }, - ResourceTypes: map[string]*configschema.Block{ - "test_instance": { + p.GetSchemaResponse = &providers.GetSchemaResponse{ + Provider: providers.Schema{ + Block: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ - "id": {Type: cty.String, Optional: true, Computed: true}, + "foo": {Type: cty.String, Optional: true}, }, }, }, - DataSources: map[string]*configschema.Block{ + ResourceTypes: map[string]providers.Schema{ + "test_instance": { + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true, Computed: true}, + }, + }, + }, + }, + DataSources: map[string]providers.Schema{ "test_data": { - Attributes: map[string]*configschema.Attribute{ - "id": {Type: cty.String, Optional: true, Computed: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "foo": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -469,7 +488,7 @@ func TestImport_providerConfigWithVarDefault(t *testing.T) { } p.ImportResourceStateFn = nil - p.ImportResourceStateResponse = providers.ImportResourceStateResponse{ + p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{ ImportedResources: []providers.ImportedResource{ { TypeName: "test_instance", @@ -479,16 +498,20 @@ func TestImport_providerConfigWithVarDefault(t *testing.T) { }, }, } - p.GetSchemaReturn = &terraform.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{ "test_instance": { - Attributes: map[string]*configschema.Attribute{ - "id": {Type: cty.String, Optional: true, Computed: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true, Computed: true}, + }, }, }, }, @@ -542,7 +565,7 @@ func TestImport_providerConfigWithVarFile(t *testing.T) { } p.ImportResourceStateFn = nil - p.ImportResourceStateResponse = providers.ImportResourceStateResponse{ + p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{ ImportedResources: []providers.ImportedResource{ { TypeName: "test_instance", @@ -552,16 +575,20 @@ func TestImport_providerConfigWithVarFile(t *testing.T) { }, }, } - p.GetSchemaReturn = &terraform.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{ "test_instance": { - Attributes: map[string]*configschema.Attribute{ - "id": {Type: cty.String, Optional: true, Computed: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true, Computed: true}, + }, }, }, }, @@ -616,7 +643,7 @@ func TestImport_allowMissingResourceConfig(t *testing.T) { } p.ImportResourceStateFn = nil - p.ImportResourceStateResponse = providers.ImportResourceStateResponse{ + p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{ ImportedResources: []providers.ImportedResource{ { TypeName: "test_instance", @@ -626,11 +653,13 @@ func TestImport_allowMissingResourceConfig(t *testing.T) { }, }, } - p.GetSchemaReturn = &terraform.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, Optional: true, Computed: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true, Computed: true}, + }, }, }, }, @@ -753,11 +782,13 @@ func TestImportModuleVarFile(t *testing.T) { statePath := testTempFile(t) p := testProvider() - p.GetSchemaReturn = &terraform.ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "test_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}, + }, }, }, }, @@ -823,11 +854,13 @@ func TestImportModuleInputVariableEvaluation(t *testing.T) { statePath := testTempFile(t) p := testProvider() - p.GetSchemaReturn = &terraform.ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "test_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}, + }, }, }, }, diff --git a/command/plan_test.go b/command/plan_test.go index 8f19aa19a..ba03b16e6 100644 --- a/command/plan_test.go +++ b/command/plan_test.go @@ -172,7 +172,7 @@ func TestPlan_noState(t *testing.T) { // Verify that the provider was called with the existing state actual := p.PlanResourceChangeRequest.PriorState - expected := cty.NullVal(p.GetSchemaReturn.ResourceTypes["test_instance"].ImpliedType()) + expected := cty.NullVal(p.GetSchemaResponse.ResourceTypes["test_instance"].Block.ImpliedType()) if !expected.RawEquals(actual) { t.Fatalf("wrong prior state\ngot: %#v\nwant: %#v", actual, expected) } @@ -194,7 +194,7 @@ func TestPlan_outPath(t *testing.T) { }, } - p.PlanResourceChangeResponse = providers.PlanResourceChangeResponse{ + p.PlanResourceChangeResponse = &providers.PlanResourceChangeResponse{ PlannedState: cty.NullVal(cty.EmptyObject), } @@ -292,17 +292,19 @@ func TestPlan_outBackend(t *testing.T) { outPath := "foo" p := testProvider() - p.GetSchemaReturn = &terraform.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, - }, - "ami": { - Type: cty.String, - Optional: true, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": { + Type: cty.String, + Computed: true, + }, + "ami": { + Type: cty.String, + Optional: true, + }, }, }, }, @@ -476,11 +478,13 @@ func TestPlan_validate(t *testing.T) { defer testChdir(t, td)() p := testProvider() - p.GetSchemaReturn = &terraform.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, Optional: true, Computed: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true, Computed: true}, + }, }, }, }, @@ -589,25 +593,29 @@ func TestPlan_providerArgumentUnset(t *testing.T) { p := planFixtureProvider() // override the planFixtureProvider schema to include a required provider argument - p.GetSchemaReturn = &terraform.ProviderSchema{ - Provider: &configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "region": {Type: cty.String, Required: true}, + p.GetSchemaResponse = &providers.GetSchemaResponse{ + Provider: providers.Schema{ + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "region": {Type: cty.String, Required: true}, + }, }, }, - ResourceTypes: map[string]*configschema.Block{ + ResourceTypes: map[string]providers.Schema{ "test_instance": { - Attributes: map[string]*configschema.Attribute{ - "id": {Type: cty.String, Optional: true, Computed: true}, - "ami": {Type: cty.String, Optional: true, Computed: true}, - }, - BlockTypes: map[string]*configschema.NestedBlock{ - "network_interface": { - Nesting: configschema.NestingList, - Block: configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "device_index": {Type: cty.String, Optional: true}, - "description": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true, Computed: true}, + "ami": {Type: cty.String, Optional: true, Computed: true}, + }, + BlockTypes: map[string]*configschema.NestedBlock{ + "network_interface": { + Nesting: configschema.NestingList, + Block: configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "device_index": {Type: cty.String, Optional: true}, + "description": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -827,11 +835,13 @@ func TestPlan_shutdown(t *testing.T) { return } - p.GetSchemaReturn = &terraform.ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "test_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}, + }, }, }, }, @@ -883,21 +893,23 @@ func TestPlan_init_required(t *testing.T) { // planFixtureSchema returns a schema suitable for processing the // configuration in testdata/plan . This schema should be // assigned to a mock provider named "test". -func planFixtureSchema() *terraform.ProviderSchema { - return &terraform.ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ +func planFixtureSchema() *providers.GetSchemaResponse { + return &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "test_instance": { - Attributes: map[string]*configschema.Attribute{ - "id": {Type: cty.String, Optional: true, Computed: true}, - "ami": {Type: cty.String, Optional: true}, - }, - BlockTypes: map[string]*configschema.NestedBlock{ - "network_interface": { - Nesting: configschema.NestingList, - Block: configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "device_index": {Type: cty.String, Optional: true}, - "description": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true, Computed: true}, + "ami": {Type: cty.String, Optional: true}, + }, + BlockTypes: map[string]*configschema.NestedBlock{ + "network_interface": { + Nesting: configschema.NestingList, + Block: configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "device_index": {Type: cty.String, Optional: true}, + "description": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -909,11 +921,11 @@ func planFixtureSchema() *terraform.ProviderSchema { // planFixtureProvider returns a mock provider that is configured for basic // operation with the configuration in testdata/plan. This mock has -// GetSchemaReturn and PlanResourceChangeFn populated, with the plan +// GetSchemaResponse and PlanResourceChangeFn populated, with the plan // step just passing through the new object proposed by Terraform Core. func planFixtureProvider() *terraform.MockProvider { p := testProvider() - p.GetSchemaReturn = planFixtureSchema() + p.GetSchemaResponse = planFixtureSchema() p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { return providers.PlanResourceChangeResponse{ PlannedState: req.ProposedNewState, @@ -925,13 +937,15 @@ func planFixtureProvider() *terraform.MockProvider { // planVarsFixtureSchema returns a schema suitable for processing the // configuration in testdata/plan-vars . This schema should be // assigned to a mock provider named "test". -func planVarsFixtureSchema() *terraform.ProviderSchema { - return &terraform.ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ +func planVarsFixtureSchema() *providers.GetSchemaResponse { + return &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "test_instance": { - Attributes: map[string]*configschema.Attribute{ - "id": {Type: cty.String, Optional: true, Computed: true}, - "value": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true, Computed: true}, + "value": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -940,11 +954,11 @@ func planVarsFixtureSchema() *terraform.ProviderSchema { // planVarsFixtureProvider returns a mock provider that is configured for basic // operation with the configuration in testdata/plan-vars. This mock has -// GetSchemaReturn and PlanResourceChangeFn populated, with the plan +// GetSchemaResponse and PlanResourceChangeFn populated, with the plan // step just passing through the new object proposed by Terraform Core. func planVarsFixtureProvider() *terraform.MockProvider { p := testProvider() - p.GetSchemaReturn = planVarsFixtureSchema() + p.GetSchemaResponse = planVarsFixtureSchema() p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { return providers.PlanResourceChangeResponse{ PlannedState: req.ProposedNewState, diff --git a/command/refresh_test.go b/command/refresh_test.go index 4f17a4a33..d3d9cd6b1 100644 --- a/command/refresh_test.go +++ b/command/refresh_test.go @@ -22,7 +22,6 @@ import ( "github.com/hashicorp/terraform/states" "github.com/hashicorp/terraform/states/statefile" "github.com/hashicorp/terraform/states/statemgr" - "github.com/hashicorp/terraform/terraform" ) var equateEmpty = cmpopts.EquateEmpty() @@ -40,9 +39,9 @@ func TestRefresh(t *testing.T) { }, } - p.GetSchemaReturn = refreshFixtureSchema() + p.GetSchemaResponse = refreshFixtureSchema() p.ReadResourceFn = nil - p.ReadResourceResponse = providers.ReadResourceResponse{ + p.ReadResourceResponse = &providers.ReadResourceResponse{ NewState: cty.ObjectVal(map[string]cty.Value{ "id": cty.StringVal("yes"), }), @@ -95,7 +94,7 @@ func TestRefresh_empty(t *testing.T) { } p.ReadResourceFn = nil - p.ReadResourceResponse = providers.ReadResourceResponse{ + p.ReadResourceResponse = &providers.ReadResourceResponse{ NewState: cty.ObjectVal(map[string]cty.Value{ "id": cty.StringVal("yes"), }), @@ -132,9 +131,9 @@ func TestRefresh_lockedState(t *testing.T) { }, } - p.GetSchemaReturn = refreshFixtureSchema() + p.GetSchemaResponse = refreshFixtureSchema() p.ReadResourceFn = nil - p.ReadResourceResponse = providers.ReadResourceResponse{ + p.ReadResourceResponse = &providers.ReadResourceResponse{ NewState: cty.ObjectVal(map[string]cty.Value{ "id": cty.StringVal("yes"), }), @@ -177,9 +176,9 @@ func TestRefresh_cwd(t *testing.T) { }, } - p.GetSchemaReturn = refreshFixtureSchema() + p.GetSchemaResponse = refreshFixtureSchema() p.ReadResourceFn = nil - p.ReadResourceResponse = providers.ReadResourceResponse{ + p.ReadResourceResponse = &providers.ReadResourceResponse{ NewState: cty.ObjectVal(map[string]cty.Value{ "id": cty.StringVal("yes"), }), @@ -249,9 +248,9 @@ func TestRefresh_defaultState(t *testing.T) { }, } - p.GetSchemaReturn = refreshFixtureSchema() + p.GetSchemaResponse = refreshFixtureSchema() p.ReadResourceFn = nil - p.ReadResourceResponse = providers.ReadResourceResponse{ + p.ReadResourceResponse = &providers.ReadResourceResponse{ NewState: cty.ObjectVal(map[string]cty.Value{ "id": cty.StringVal("yes"), }), @@ -312,9 +311,9 @@ func TestRefresh_outPath(t *testing.T) { }, } - p.GetSchemaReturn = refreshFixtureSchema() + p.GetSchemaResponse = refreshFixtureSchema() p.ReadResourceFn = nil - p.ReadResourceResponse = providers.ReadResourceResponse{ + p.ReadResourceResponse = &providers.ReadResourceResponse{ NewState: cty.ObjectVal(map[string]cty.Value{ "id": cty.StringVal("yes"), }), @@ -365,7 +364,7 @@ func TestRefresh_var(t *testing.T) { Ui: ui, }, } - p.GetSchemaReturn = refreshVarFixtureSchema() + p.GetSchemaResponse = refreshVarFixtureSchema() args := []string{ "-var", "foo=bar", @@ -396,7 +395,7 @@ func TestRefresh_varFile(t *testing.T) { Ui: ui, }, } - p.GetSchemaReturn = refreshVarFixtureSchema() + p.GetSchemaResponse = refreshVarFixtureSchema() varFilePath := testTempFile(t) if err := ioutil.WriteFile(varFilePath, []byte(refreshVarFile), 0644); err != nil { @@ -432,7 +431,7 @@ func TestRefresh_varFileDefault(t *testing.T) { Ui: ui, }, } - p.GetSchemaReturn = refreshVarFixtureSchema() + p.GetSchemaResponse = refreshVarFixtureSchema() varFileDir := testTempDir(t) varFilePath := filepath.Join(varFileDir, "terraform.tfvars") @@ -483,12 +482,14 @@ func TestRefresh_varsUnset(t *testing.T) { Ui: ui, }, } - p.GetSchemaReturn = &terraform.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, Optional: true, Computed: true}, - "ami": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true, Computed: true}, + "ami": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -540,9 +541,9 @@ func TestRefresh_backup(t *testing.T) { }, } - p.GetSchemaReturn = refreshFixtureSchema() + p.GetSchemaResponse = refreshFixtureSchema() p.ReadResourceFn = nil - p.ReadResourceResponse = providers.ReadResourceResponse{ + p.ReadResourceResponse = &providers.ReadResourceResponse{ NewState: cty.ObjectVal(map[string]cty.Value{ "id": cty.StringVal("changed"), }), @@ -604,9 +605,9 @@ func TestRefresh_disableBackup(t *testing.T) { }, } - p.GetSchemaReturn = refreshFixtureSchema() + p.GetSchemaResponse = refreshFixtureSchema() p.ReadResourceFn = nil - p.ReadResourceResponse = providers.ReadResourceResponse{ + p.ReadResourceResponse = &providers.ReadResourceResponse{ NewState: cty.ObjectVal(map[string]cty.Value{ "id": cty.StringVal("yes"), }), @@ -663,12 +664,14 @@ func TestRefresh_displaysOutputs(t *testing.T) { Ui: ui, }, } - p.GetSchemaReturn = &terraform.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, Optional: true, Computed: true}, - "ami": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true, Computed: true}, + "ami": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -692,13 +695,15 @@ func TestRefresh_displaysOutputs(t *testing.T) { // configuration in testdata/refresh . This schema should be // assigned to a mock provider named "test". -func refreshFixtureSchema() *terraform.ProviderSchema { - return &terraform.ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ +func refreshFixtureSchema() *providers.GetSchemaResponse { + return &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "test_instance": { - Attributes: map[string]*configschema.Attribute{ - "id": {Type: cty.String, Optional: true, Computed: true}, - "ami": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true, Computed: true}, + "ami": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -708,17 +713,21 @@ func refreshFixtureSchema() *terraform.ProviderSchema { // refreshVarFixtureSchema returns a schema suitable for processing the // configuration in testdata/refresh-var . This schema should be // assigned to a mock provider named "test". -func refreshVarFixtureSchema() *terraform.ProviderSchema { - return &terraform.ProviderSchema{ - Provider: &configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "value": {Type: cty.String, Optional: true}, +func refreshVarFixtureSchema() *providers.GetSchemaResponse { + return &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{ "test_instance": { - Attributes: map[string]*configschema.Attribute{ - "id": {Type: cty.String, Optional: true, Computed: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true, Computed: true}, + }, }, }, }, diff --git a/command/show_test.go b/command/show_test.go index 93f300d47..aec6e22ec 100644 --- a/command/show_test.go +++ b/command/show_test.go @@ -408,18 +408,22 @@ func TestShow_json_output_state(t *testing.T) { // showFixtureSchema returns a schema suitable for processing the configuration // in testdata/show. This schema should be assigned to a mock provider // named "test". -func showFixtureSchema() *terraform.ProviderSchema { - return &terraform.ProviderSchema{ - Provider: &configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "region": {Type: cty.String, Optional: true}, +func showFixtureSchema() *providers.GetSchemaResponse { + return &providers.GetSchemaResponse{ + Provider: providers.Schema{ + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "region": {Type: cty.String, Optional: true}, + }, }, }, - ResourceTypes: map[string]*configschema.Block{ + ResourceTypes: map[string]providers.Schema{ "test_instance": { - Attributes: map[string]*configschema.Attribute{ - "id": {Type: cty.String, Optional: true, Computed: true}, - "ami": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true, Computed: true}, + "ami": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -428,12 +432,12 @@ func showFixtureSchema() *terraform.ProviderSchema { // showFixtureProvider returns a mock provider that is configured for basic // operation with the configuration in testdata/show. This mock has -// GetSchemaReturn, PlanResourceChangeFn, and ApplyResourceChangeFn populated, +// GetSchemaResponse, PlanResourceChangeFn, and ApplyResourceChangeFn populated, // with the plan/apply steps just passing through the data determined by // Terraform Core. func showFixtureProvider() *terraform.MockProvider { p := testProvider() - p.GetSchemaReturn = showFixtureSchema() + p.GetSchemaResponse = showFixtureSchema() p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { idVal := req.ProposedNewState.GetAttr("id") amiVal := req.ProposedNewState.GetAttr("ami") diff --git a/command/state_show_test.go b/command/state_show_test.go index 0f649cb78..ad70cd5e7 100644 --- a/command/state_show_test.go +++ b/command/state_show_test.go @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform/configs/configschema" "github.com/hashicorp/terraform/providers" "github.com/hashicorp/terraform/states" - "github.com/hashicorp/terraform/terraform" "github.com/mitchellh/cli" "github.com/zclconf/go-cty/cty" ) @@ -34,13 +33,15 @@ func TestStateShow(t *testing.T) { statePath := testStateFile(t, state) p := testProvider() - p.GetSchemaReturn = &terraform.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, Optional: true, Computed: true}, - "foo": {Type: cty.String, Optional: true}, - "bar": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true, Computed: true}, + "foo": {Type: cty.String, Optional: true}, + "bar": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -107,13 +108,15 @@ func TestStateShow_multi(t *testing.T) { statePath := testStateFile(t, state) p := testProvider() - p.GetSchemaReturn = &terraform.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, Optional: true, Computed: true}, - "foo": {Type: cty.String, Optional: true}, - "bar": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true, Computed: true}, + "foo": {Type: cty.String, Optional: true}, + "bar": {Type: cty.String, Optional: true}, + }, }, }, }, @@ -213,13 +216,15 @@ func TestStateShow_configured_provider(t *testing.T) { statePath := testStateFile(t, state) p := testProvider() - p.GetSchemaReturn = &terraform.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, Optional: true, Computed: true}, - "foo": {Type: cty.String, Optional: true}, - "bar": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Optional: true, Computed: true}, + "foo": {Type: cty.String, Optional: true}, + "bar": {Type: cty.String, Optional: true}, + }, }, }, }, diff --git a/command/validate_test.go b/command/validate_test.go index 114a1a861..65515900b 100644 --- a/command/validate_test.go +++ b/command/validate_test.go @@ -13,26 +13,28 @@ import ( "github.com/zclconf/go-cty/cty" "github.com/hashicorp/terraform/configs/configschema" - "github.com/hashicorp/terraform/terraform" + "github.com/hashicorp/terraform/providers" ) func setupTest(fixturepath string, args ...string) (*cli.MockUi, int) { ui := new(cli.MockUi) p := testProvider() - p.GetSchemaReturn = &terraform.ProviderSchema{ - ResourceTypes: map[string]*configschema.Block{ + p.GetSchemaResponse = &providers.GetSchemaResponse{ + ResourceTypes: map[string]providers.Schema{ "test_instance": { - Attributes: map[string]*configschema.Attribute{ - "ami": {Type: cty.String, Optional: true}, - }, - BlockTypes: map[string]*configschema.NestedBlock{ - "network_interface": { - Nesting: configschema.NestingList, - Block: configschema.Block{ - Attributes: map[string]*configschema.Attribute{ - "device_index": {Type: cty.String, Optional: true}, - "description": {Type: cty.String, Optional: true}, - "name": {Type: cty.String, Optional: true}, + Block: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "ami": {Type: cty.String, Optional: true}, + }, + BlockTypes: map[string]*configschema.NestedBlock{ + "network_interface": { + Nesting: configschema.NestingList, + Block: configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "device_index": {Type: cty.String, Optional: true}, + "description": {Type: cty.String, Optional: true}, + "name": {Type: cty.String, Optional: true}, + }, }, }, }, diff --git a/repl/session_test.go b/repl/session_test.go index 4e721375c..50c5065ed 100644 --- a/repl/session_test.go +++ b/repl/session_test.go @@ -184,11 +184,13 @@ func testSession(t *testing.T, test testSessionTest) { t.Helper() p := &terraform.MockProvider{} - p.GetSchemaReturn = &terraform.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}, + }, }, }, },