Merge pull request #27485 from hashicorp/jbardin/mock-provider
Update the MockProvider to use correct types and allow default behaviors
This commit is contained in:
commit
7e880299c0
|
@ -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"),
|
||||
})}
|
||||
|
|
|
@ -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"),
|
||||
})}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"),
|
||||
})}
|
||||
|
||||
|
|
|
@ -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},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package configschema
|
||||
|
||||
import (
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
)
|
||||
|
||||
// AttributeByPath looks up the Attribute schema which corresponds to the given
|
||||
// cty.Path. A nil value is returned if the given path does not correspond to a
|
||||
// specific attribute.
|
||||
// TODO: this will need to be updated for nested attributes
|
||||
func (b *Block) AttributeByPath(path cty.Path) *Attribute {
|
||||
block := b
|
||||
for _, step := range path {
|
||||
switch step := step.(type) {
|
||||
case cty.GetAttrStep:
|
||||
if attr := block.Attributes[step.Name]; attr != nil {
|
||||
return attr
|
||||
}
|
||||
|
||||
if nestedBlock := block.BlockTypes[step.Name]; nestedBlock != nil {
|
||||
block = &nestedBlock.Block
|
||||
continue
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
package configschema
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
)
|
||||
|
||||
func TestAttributeByPath(t *testing.T) {
|
||||
schema := &Block{
|
||||
Attributes: map[string]*Attribute{
|
||||
"a1": {Description: "a1"},
|
||||
"a2": {Description: "a2"},
|
||||
},
|
||||
BlockTypes: map[string]*NestedBlock{
|
||||
"b1": {
|
||||
Nesting: NestingList,
|
||||
Block: Block{
|
||||
Attributes: map[string]*Attribute{
|
||||
"a3": {Description: "a3"},
|
||||
"a4": {Description: "a4"},
|
||||
},
|
||||
BlockTypes: map[string]*NestedBlock{
|
||||
"b2": {
|
||||
Nesting: NestingMap,
|
||||
Block: Block{
|
||||
Attributes: map[string]*Attribute{
|
||||
"a5": {Description: "a5"},
|
||||
"a6": {Description: "a6"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"b3": {
|
||||
Nesting: NestingMap,
|
||||
Block: Block{
|
||||
Attributes: map[string]*Attribute{
|
||||
"a7": {Description: "a7"},
|
||||
"a8": {Description: "a8"},
|
||||
},
|
||||
BlockTypes: map[string]*NestedBlock{
|
||||
"b4": {
|
||||
Nesting: NestingSet,
|
||||
Block: Block{
|
||||
Attributes: map[string]*Attribute{
|
||||
"a9": {Description: "a9"},
|
||||
"a10": {Description: "a10"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
path cty.Path
|
||||
attrDescription string
|
||||
exists bool
|
||||
}{
|
||||
{
|
||||
cty.GetAttrPath("a2"),
|
||||
"a2",
|
||||
true,
|
||||
},
|
||||
{
|
||||
cty.GetAttrPath("b1"),
|
||||
"block",
|
||||
false,
|
||||
},
|
||||
{
|
||||
cty.GetAttrPath("b1").IndexInt(1).GetAttr("a3"),
|
||||
"a3",
|
||||
true,
|
||||
},
|
||||
{
|
||||
cty.GetAttrPath("b1").IndexInt(1).GetAttr("b2").IndexString("foo").GetAttr("a7"),
|
||||
"missing",
|
||||
false,
|
||||
},
|
||||
{
|
||||
cty.GetAttrPath("b1").IndexInt(1).GetAttr("b2").IndexString("foo").GetAttr("a6"),
|
||||
"a6",
|
||||
true,
|
||||
},
|
||||
{
|
||||
cty.GetAttrPath("b3").IndexString("foo").GetAttr("b2").IndexString("foo").GetAttr("a7"),
|
||||
"missing_block",
|
||||
false,
|
||||
},
|
||||
{
|
||||
cty.GetAttrPath("b3").IndexString("foo").GetAttr("a7"),
|
||||
"a7",
|
||||
true,
|
||||
},
|
||||
{
|
||||
// Index steps don't apply to the schema, so the set Index value doesn't matter.
|
||||
cty.GetAttrPath("b3").IndexString("foo").GetAttr("b4").Index(cty.EmptyObjectVal).GetAttr("a9"),
|
||||
"a9",
|
||||
true,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.attrDescription, func(t *testing.T) {
|
||||
attr := schema.AttributeByPath(tc.path)
|
||||
if !tc.exists && attr == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if attr == nil {
|
||||
t.Fatalf("missing attribute from path %#v\n", tc.path)
|
||||
}
|
||||
|
||||
if attr.Description != tc.attrDescription {
|
||||
t.Fatalf("expected Attribute for %q, got %#v\n", tc.attrDescription, attr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -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},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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 {
|
||||
|
@ -1418,7 +1418,7 @@ func TestContext2Apply_dataBasic(t *testing.T) {
|
|||
p := testProvider("null")
|
||||
p.ApplyResourceChangeFn = testApplyFn
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.ReadDataSourceResponse = providers.ReadDataSourceResponse{
|
||||
p.ReadDataSourceResponse = &providers.ReadDataSourceResponse{
|
||||
State: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("yo"),
|
||||
"foo": cty.NullVal(cty.String),
|
||||
|
@ -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": {
|
||||
|
@ -10402,17 +10402,16 @@ func TestContext2Apply_ProviderMeta_refresh_set(t *testing.T) {
|
|||
},
|
||||
}
|
||||
rrcPMs := map[string]cty.Value{}
|
||||
p.ReadResourceFn = func(req providers.ReadResourceRequest) providers.ReadResourceResponse {
|
||||
p.ReadResourceFn = func(req providers.ReadResourceRequest) (resp providers.ReadResourceResponse) {
|
||||
rrcPMs[req.TypeName] = req.ProviderMeta
|
||||
newState, err := p.GetSchemaReturn.ResourceTypes[req.TypeName].CoerceValue(p.ReadResourceResponse.NewState)
|
||||
newState, err := p.GetSchemaResponse.ResourceTypes[req.TypeName].Block.CoerceValue(req.PriorState)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
resp := p.ReadResourceResponse
|
||||
resp.NewState = newState
|
||||
return resp
|
||||
}
|
||||
p.GetSchemaReturn = schema
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
|
@ -10474,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": {
|
||||
|
@ -10483,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{
|
||||
|
@ -10499,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{
|
||||
|
@ -10543,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": {
|
||||
|
@ -10552,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{
|
||||
|
@ -10575,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{
|
||||
|
@ -10621,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": {
|
||||
|
@ -10630,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{
|
||||
|
@ -10717,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": {
|
||||
|
@ -10726,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{
|
||||
|
@ -10792,7 +10791,7 @@ func TestContext2Apply_ProviderMeta_refreshdata_setNoSchema(t *testing.T) {
|
|||
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
p.ReadDataSourceResponse = providers.ReadDataSourceResponse{
|
||||
p.ReadDataSourceResponse = &providers.ReadDataSourceResponse{
|
||||
State: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("yo"),
|
||||
"foo": cty.StringVal("bar"),
|
||||
|
@ -10832,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": {
|
||||
|
@ -10841,14 +10840,14 @@ 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{
|
||||
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
p.ReadDataSourceResponse = providers.ReadDataSourceResponse{
|
||||
p.ReadDataSourceResponse = &providers.ReadDataSourceResponse{
|
||||
State: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("yo"),
|
||||
"foo": cty.StringVal("bar"),
|
||||
|
@ -11467,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) {
|
||||
|
@ -11492,12 +11491,12 @@ 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
|
||||
|
||||
nullP.ReadDataSourceResponse = providers.ReadDataSourceResponse{
|
||||
nullP.ReadDataSourceResponse = &providers.ReadDataSourceResponse{
|
||||
State: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("ID"),
|
||||
"output": cty.StringVal("valid"),
|
||||
|
@ -11881,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": {
|
||||
|
@ -11909,7 +11908,7 @@ resource "test_resource" "foo" {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
p.ApplyResourceChangeFn = testApplyFn
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
|
||||
|
@ -12385,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{
|
||||
|
@ -12393,7 +12392,7 @@ resource "test_instance" "a" {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
|
|
|
@ -22,7 +22,7 @@ func TestContextImport_basic(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -63,7 +63,7 @@ func TestContextImport_countIndex(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -125,7 +125,7 @@ func TestContextImport_collision(t *testing.T) {
|
|||
}),
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -164,7 +164,7 @@ func TestContextImport_missingType(t *testing.T) {
|
|||
p := testProvider("aws")
|
||||
m := testModule(t, "import-provider")
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
State: cty.ObjectVal(map[string]cty.Value{
|
||||
|
@ -205,7 +205,7 @@ func TestContextImport_missingType(t *testing.T) {
|
|||
func TestContextImport_moduleProvider(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -269,7 +269,7 @@ func TestContextImport_providerModule(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -341,7 +341,7 @@ func TestContextImport_providerConfig(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -396,7 +396,7 @@ func TestContextImport_providerConfigResources(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -435,7 +435,7 @@ func TestContextImport_refresh(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -448,7 +448,7 @@ func TestContextImport_refresh(t *testing.T) {
|
|||
|
||||
p.ReadResourceFn = nil
|
||||
|
||||
p.ReadResourceResponse = providers.ReadResourceResponse{
|
||||
p.ReadResourceResponse = &providers.ReadResourceResponse{
|
||||
NewState: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("foo"),
|
||||
"foo": cty.StringVal("bar"),
|
||||
|
@ -486,7 +486,7 @@ func TestContextImport_refreshNil(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -534,7 +534,7 @@ func TestContextImport_module(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -576,7 +576,7 @@ func TestContextImport_moduleDepth2(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -618,7 +618,7 @@ func TestContextImport_moduleDiff(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -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,9 +672,9 @@ func TestContextImport_multiState(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -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,9 +741,9 @@ func TestContextImport_multiStateSame(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
@ -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,9 +842,9 @@ resource "test_resource" "unused" {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "test_resource",
|
||||
|
@ -854,7 +854,7 @@ resource "test_resource" "unused" {
|
|||
},
|
||||
},
|
||||
}
|
||||
p.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "test_resource",
|
||||
|
|
|
@ -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,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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 {
|
||||
|
@ -49,7 +49,7 @@ func TestContext2Refresh(t *testing.T) {
|
|||
}
|
||||
|
||||
p.ReadResourceFn = nil
|
||||
p.ReadResourceResponse = providers.ReadResourceResponse{
|
||||
p.ReadResourceResponse = &providers.ReadResourceResponse{
|
||||
NewState: readState,
|
||||
}
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
|
@ -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")
|
||||
|
@ -514,8 +514,8 @@ func TestContext2Refresh_delete(t *testing.T) {
|
|||
})
|
||||
|
||||
p.ReadResourceFn = nil
|
||||
p.ReadResourceResponse = providers.ReadResourceResponse{
|
||||
NewState: cty.NullVal(p.GetSchemaReturn.ResourceTypes["aws_instance"].ImpliedType()),
|
||||
p.ReadResourceResponse = &providers.ReadResourceResponse{
|
||||
NewState: cty.NullVal(p.GetSchemaResponse.ResourceTypes["aws_instance"].Block.ImpliedType()),
|
||||
}
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
|
||||
|
@ -542,7 +542,7 @@ func TestContext2Refresh_ignoreUncreated(t *testing.T) {
|
|||
})
|
||||
|
||||
p.ReadResourceFn = nil
|
||||
p.ReadResourceResponse = providers.ReadResourceResponse{
|
||||
p.ReadResourceResponse = &providers.ReadResourceResponse{
|
||||
NewState: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("foo"),
|
||||
}),
|
||||
|
@ -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,
|
||||
|
@ -700,7 +700,7 @@ func TestContext2Refresh_noState(t *testing.T) {
|
|||
})
|
||||
|
||||
p.ReadResourceFn = nil
|
||||
p.ReadResourceResponse = providers.ReadResourceResponse{
|
||||
p.ReadResourceResponse = &providers.ReadResourceResponse{
|
||||
NewState: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("foo"),
|
||||
}),
|
||||
|
@ -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()),
|
||||
p.ReadResourceResponse = &providers.ReadResourceResponse{
|
||||
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{
|
||||
|
@ -841,7 +841,7 @@ func TestContext2Refresh_stateBasic(t *testing.T) {
|
|||
|
||||
p.ReadResourceFn = nil
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.ReadResourceResponse = providers.ReadResourceResponse{
|
||||
p.ReadResourceResponse = &providers.ReadResourceResponse{
|
||||
NewState: readStateVal,
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
@ -1142,7 +1142,7 @@ func TestContext2Refresh_vars(t *testing.T) {
|
|||
|
||||
p.ReadResourceFn = nil
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.ReadResourceResponse = providers.ReadResourceResponse{
|
||||
p.ReadResourceResponse = &providers.ReadResourceResponse{
|
||||
NewState: readStateVal,
|
||||
}
|
||||
|
||||
|
@ -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,8 +1332,8 @@ func TestContext2Refresh_schemaUpgradeFlatmap(t *testing.T) {
|
|||
ResourceTypeSchemaVersions: map[string]uint64{
|
||||
"test_thing": 5,
|
||||
},
|
||||
}
|
||||
p.UpgradeResourceStateResponse = providers.UpgradeResourceStateResponse{
|
||||
})
|
||||
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,8 +1419,8 @@ func TestContext2Refresh_schemaUpgradeJSON(t *testing.T) {
|
|||
ResourceTypeSchemaVersions: map[string]uint64{
|
||||
"test_thing": 5,
|
||||
},
|
||||
}
|
||||
p.UpgradeResourceStateResponse = providers.UpgradeResourceStateResponse{
|
||||
})
|
||||
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,9 +1543,9 @@ func TestContext2Refresh_dataResourceDependsOn(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.ReadDataSourceResponse = providers.ReadDataSourceResponse{
|
||||
p.ReadDataSourceResponse = &providers.ReadDataSourceResponse{
|
||||
State: cty.ObjectVal(map[string]cty.Value{
|
||||
"compute": cty.StringVal("value"),
|
||||
}),
|
||||
|
|
|
@ -401,11 +401,7 @@ func testDiffFn(req providers.PlanResourceChangeRequest) (resp providers.PlanRes
|
|||
|
||||
func testProvider(prefix string) *MockProvider {
|
||||
p := new(MockProvider)
|
||||
p.ReadResourceFn = func(req providers.ReadResourceRequest) providers.ReadResourceResponse {
|
||||
return providers.ReadResourceResponse{NewState: req.PriorState}
|
||||
}
|
||||
|
||||
p.GetSchemaReturn = testProviderSchema(prefix)
|
||||
p.GetSchemaResponse = testProviderSchema(prefix)
|
||||
|
||||
return p
|
||||
}
|
||||
|
@ -465,8 +461,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 +704,7 @@ func testProviderSchema(name string) *ProviderSchema {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
// contextForPlanViaFile is a helper that creates a temporary plan file, then
|
||||
|
|
|
@ -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{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -398,7 +419,7 @@ func TestContext2Validate_moduleBadResource(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ValidateResourceTypeConfigResponse = providers.ValidateResourceTypeConfigResponse{
|
||||
p.ValidateResourceTypeConfigResponse = &providers.ValidateResourceTypeConfigResponse{
|
||||
Diagnostics: tfdiags.Diagnostics{}.Append(fmt.Errorf("bad")),
|
||||
}
|
||||
|
||||
|
@ -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{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -582,7 +619,7 @@ func TestContext2Validate_providerConfig_bad(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.PrepareProviderConfigResponse = providers.PrepareProviderConfigResponse{
|
||||
p.PrepareProviderConfigResponse = &providers.PrepareProviderConfigResponse{
|
||||
Diagnostics: tfdiags.Diagnostics{}.Append(fmt.Errorf("bad")),
|
||||
}
|
||||
|
||||
|
@ -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{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -618,7 +659,7 @@ func TestContext2Validate_providerConfig_skippedEmpty(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.PrepareProviderConfigResponse = providers.PrepareProviderConfigResponse{
|
||||
p.PrepareProviderConfigResponse = &providers.PrepareProviderConfigResponse{
|
||||
Diagnostics: tfdiags.Diagnostics{}.Append(fmt.Errorf("should not be called")),
|
||||
}
|
||||
|
||||
|
@ -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},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -714,7 +765,7 @@ func TestContext2Validate_provisionerConfig_bad(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.PrepareProviderConfigResponse = providers.PrepareProviderConfigResponse{
|
||||
p.PrepareProviderConfigResponse = &providers.PrepareProviderConfigResponse{
|
||||
Diagnostics: tfdiags.Diagnostics{}.Append(fmt.Errorf("bad")),
|
||||
}
|
||||
|
||||
|
@ -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{
|
||||
|
@ -878,7 +939,7 @@ func TestContext2Validate_resourceConfig_bad(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
p.ValidateResourceTypeConfigResponse = providers.ValidateResourceTypeConfigResponse{
|
||||
p.ValidateResourceTypeConfigResponse = &providers.ValidateResourceTypeConfigResponse{
|
||||
Diagnostics: tfdiags.Diagnostics{}.Append(fmt.Errorf("bad")),
|
||||
}
|
||||
|
||||
|
@ -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,17 +1939,19 @@ 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},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
p.ValidateResourceTypeConfigResponse = providers.ValidateResourceTypeConfigResponse{
|
||||
p.ValidateResourceTypeConfigResponse = &providers.ValidateResourceTypeConfigResponse{
|
||||
Diagnostics: tfdiags.Diagnostics(nil).Append(tfdiags.SimpleWarning("don't frobble")),
|
||||
}
|
||||
|
||||
|
|
|
@ -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(),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -26,7 +26,7 @@ func TestNodePlanDeposedResourceInstanceObject_Execute(t *testing.T) {
|
|||
)
|
||||
|
||||
p := testProvider("test")
|
||||
p.UpgradeResourceStateResponse = providers.UpgradeResourceStateResponse{
|
||||
p.UpgradeResourceStateResponse = &providers.UpgradeResourceStateResponse{
|
||||
UpgradedState: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("bar"),
|
||||
}),
|
||||
|
@ -85,28 +85,32 @@ func TestNodeDestroyDeposedResourceInstanceObject_Execute(t *testing.T) {
|
|||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
|
||||
schema := &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"id": {
|
||||
Type: cty.String,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
p := testProvider("test")
|
||||
p.UpgradeResourceStateResponse = providers.UpgradeResourceStateResponse{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
|
||||
|
||||
p.UpgradeResourceStateResponse = &providers.UpgradeResourceStateResponse{
|
||||
UpgradedState: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("bar"),
|
||||
}),
|
||||
}
|
||||
ctx := &MockEvalContext{
|
||||
StateState: state.SyncWrapper(),
|
||||
ProviderProvider: p,
|
||||
ProviderSchemaSchema: &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"id": {
|
||||
Type: cty.String,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
ChangesChanges: plans.NewChanges().SyncWrapper(),
|
||||
StateState: state.SyncWrapper(),
|
||||
ProviderProvider: p,
|
||||
ProviderSchemaSchema: schema,
|
||||
ChangesChanges: plans.NewChanges().SyncWrapper(),
|
||||
}
|
||||
|
||||
node := NodeDestroyDeposedResourceInstanceObject{
|
||||
|
@ -143,7 +147,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{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
package terraform
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
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"
|
||||
)
|
||||
|
@ -22,34 +23,34 @@ 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
|
||||
PrepareProviderConfigResponse *providers.PrepareProviderConfigResponse
|
||||
PrepareProviderConfigRequest providers.PrepareProviderConfigRequest
|
||||
PrepareProviderConfigFn func(providers.PrepareProviderConfigRequest) providers.PrepareProviderConfigResponse
|
||||
|
||||
ValidateResourceTypeConfigCalled bool
|
||||
ValidateResourceTypeConfigTypeName string
|
||||
ValidateResourceTypeConfigResponse providers.ValidateResourceTypeConfigResponse
|
||||
ValidateResourceTypeConfigResponse *providers.ValidateResourceTypeConfigResponse
|
||||
ValidateResourceTypeConfigRequest providers.ValidateResourceTypeConfigRequest
|
||||
ValidateResourceTypeConfigFn func(providers.ValidateResourceTypeConfigRequest) providers.ValidateResourceTypeConfigResponse
|
||||
|
||||
ValidateDataSourceConfigCalled bool
|
||||
ValidateDataSourceConfigTypeName string
|
||||
ValidateDataSourceConfigResponse providers.ValidateDataSourceConfigResponse
|
||||
ValidateDataSourceConfigResponse *providers.ValidateDataSourceConfigResponse
|
||||
ValidateDataSourceConfigRequest providers.ValidateDataSourceConfigRequest
|
||||
ValidateDataSourceConfigFn func(providers.ValidateDataSourceConfigRequest) providers.ValidateDataSourceConfigResponse
|
||||
|
||||
UpgradeResourceStateCalled bool
|
||||
UpgradeResourceStateTypeName string
|
||||
UpgradeResourceStateResponse providers.UpgradeResourceStateResponse
|
||||
UpgradeResourceStateResponse *providers.UpgradeResourceStateResponse
|
||||
UpgradeResourceStateRequest providers.UpgradeResourceStateRequest
|
||||
UpgradeResourceStateFn func(providers.UpgradeResourceStateRequest) providers.UpgradeResourceStateResponse
|
||||
|
||||
ConfigureCalled bool
|
||||
ConfigureResponse providers.ConfigureResponse
|
||||
ConfigureResponse *providers.ConfigureResponse
|
||||
ConfigureRequest providers.ConfigureRequest
|
||||
ConfigureFn func(providers.ConfigureRequest) providers.ConfigureResponse
|
||||
|
||||
|
@ -58,27 +59,27 @@ type MockProvider struct {
|
|||
StopResponse error
|
||||
|
||||
ReadResourceCalled bool
|
||||
ReadResourceResponse providers.ReadResourceResponse
|
||||
ReadResourceResponse *providers.ReadResourceResponse
|
||||
ReadResourceRequest providers.ReadResourceRequest
|
||||
ReadResourceFn func(providers.ReadResourceRequest) providers.ReadResourceResponse
|
||||
|
||||
PlanResourceChangeCalled bool
|
||||
PlanResourceChangeResponse providers.PlanResourceChangeResponse
|
||||
PlanResourceChangeResponse *providers.PlanResourceChangeResponse
|
||||
PlanResourceChangeRequest providers.PlanResourceChangeRequest
|
||||
PlanResourceChangeFn func(providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse
|
||||
|
||||
ApplyResourceChangeCalled bool
|
||||
ApplyResourceChangeResponse providers.ApplyResourceChangeResponse
|
||||
ApplyResourceChangeResponse *providers.ApplyResourceChangeResponse
|
||||
ApplyResourceChangeRequest providers.ApplyResourceChangeRequest
|
||||
ApplyResourceChangeFn func(providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse
|
||||
|
||||
ImportResourceStateCalled bool
|
||||
ImportResourceStateResponse providers.ImportResourceStateResponse
|
||||
ImportResourceStateResponse *providers.ImportResourceStateResponse
|
||||
ImportResourceStateRequest providers.ImportResourceStateRequest
|
||||
ImportResourceStateFn func(providers.ImportResourceStateRequest) providers.ImportResourceStateResponse
|
||||
|
||||
ReadDataSourceCalled bool
|
||||
ReadDataSourceResponse providers.ReadDataSourceResponse
|
||||
ReadDataSourceResponse *providers.ReadDataSourceResponse
|
||||
ReadDataSourceRequest providers.ReadDataSourceRequest
|
||||
ReadDataSourceFn func(providers.ReadDataSourceRequest) providers.ReadDataSourceResponse
|
||||
|
||||
|
@ -97,50 +98,43 @@ 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)
|
||||
// ProviderSchema is a helper to convert from the internal GetSchemaResponse to
|
||||
// a ProviderSchema.
|
||||
func (p *MockProvider) ProviderSchema() *ProviderSchema {
|
||||
resp := p.getSchema()
|
||||
|
||||
schema := &ProviderSchema{
|
||||
Provider: resp.Provider.Block,
|
||||
ProviderMeta: resp.ProviderMeta.Block,
|
||||
ResourceTypes: map[string]*configschema.Block{},
|
||||
DataSources: map[string]*configschema.Block{},
|
||||
ResourceTypeSchemaVersions: map[string]uint64{},
|
||||
}
|
||||
return resSchema
|
||||
|
||||
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) getDatasourceSchema(name string) providers.Schema {
|
||||
schema := p.getSchema()
|
||||
dataSchema, ok := schema.DataSources[name]
|
||||
if !ok {
|
||||
panic("unknown data source " + name)
|
||||
}
|
||||
return dataSchema
|
||||
}
|
||||
|
||||
func (p *MockProvider) PrepareProviderConfig(r providers.PrepareProviderConfigRequest) providers.PrepareProviderConfigResponse {
|
||||
func (p *MockProvider) PrepareProviderConfig(r providers.PrepareProviderConfigRequest) (resp providers.PrepareProviderConfigResponse) {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
|
||||
|
@ -149,8 +143,13 @@ func (p *MockProvider) PrepareProviderConfig(r providers.PrepareProviderConfigRe
|
|||
if p.PrepareProviderConfigFn != nil {
|
||||
return p.PrepareProviderConfigFn(r)
|
||||
}
|
||||
p.PrepareProviderConfigResponse.PreparedConfig = r.Config
|
||||
return p.PrepareProviderConfigResponse
|
||||
|
||||
if p.PrepareProviderConfigResponse != nil {
|
||||
return *p.PrepareProviderConfigResponse
|
||||
}
|
||||
|
||||
resp.PreparedConfig = r.Config
|
||||
return resp
|
||||
}
|
||||
|
||||
func (p *MockProvider) ValidateResourceTypeConfig(r providers.ValidateResourceTypeConfigRequest) (resp providers.ValidateResourceTypeConfigResponse) {
|
||||
|
@ -162,7 +161,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)
|
||||
|
@ -173,7 +177,11 @@ func (p *MockProvider) ValidateResourceTypeConfig(r providers.ValidateResourceTy
|
|||
return p.ValidateResourceTypeConfigFn(r)
|
||||
}
|
||||
|
||||
return p.ValidateResourceTypeConfigResponse
|
||||
if p.ValidateResourceTypeConfigResponse != nil {
|
||||
return *p.ValidateResourceTypeConfigResponse
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
func (p *MockProvider) ValidateDataSourceConfig(r providers.ValidateDataSourceConfigRequest) (resp providers.ValidateDataSourceConfigResponse) {
|
||||
|
@ -184,7 +192,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)
|
||||
|
@ -195,15 +207,23 @@ func (p *MockProvider) ValidateDataSourceConfig(r providers.ValidateDataSourceCo
|
|||
return p.ValidateDataSourceConfigFn(r)
|
||||
}
|
||||
|
||||
return p.ValidateDataSourceConfigResponse
|
||||
if p.ValidateDataSourceConfigResponse != nil {
|
||||
return *p.ValidateDataSourceConfigResponse
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
func (p *MockProvider) UpgradeResourceState(r providers.UpgradeResourceStateRequest) providers.UpgradeResourceStateResponse {
|
||||
func (p *MockProvider) UpgradeResourceState(r providers.UpgradeResourceStateRequest) (resp providers.UpgradeResourceStateResponse) {
|
||||
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
|
||||
|
@ -213,31 +233,32 @@ func (p *MockProvider) UpgradeResourceState(r providers.UpgradeResourceStateRequ
|
|||
return p.UpgradeResourceStateFn(r)
|
||||
}
|
||||
|
||||
resp := p.UpgradeResourceStateResponse
|
||||
|
||||
if resp.UpgradedState == cty.NilVal {
|
||||
switch {
|
||||
case r.RawStateFlatmap != nil:
|
||||
v, err := hcl2shim.HCL2ValueFromFlatmap(r.RawStateFlatmap, schemaType)
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
return resp
|
||||
}
|
||||
resp.UpgradedState = v
|
||||
case len(r.RawStateJSON) > 0:
|
||||
v, err := ctyjson.Unmarshal(r.RawStateJSON, schemaType)
|
||||
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
return resp
|
||||
}
|
||||
resp.UpgradedState = v
|
||||
}
|
||||
if p.UpgradeResourceStateResponse != nil {
|
||||
return *p.UpgradeResourceStateResponse
|
||||
}
|
||||
|
||||
switch {
|
||||
case r.RawStateFlatmap != nil:
|
||||
v, err := hcl2shim.HCL2ValueFromFlatmap(r.RawStateFlatmap, schemaType)
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
return resp
|
||||
}
|
||||
resp.UpgradedState = v
|
||||
case len(r.RawStateJSON) > 0:
|
||||
v, err := ctyjson.Unmarshal(r.RawStateJSON, schemaType)
|
||||
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
return resp
|
||||
}
|
||||
resp.UpgradedState = v
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
func (p *MockProvider) Configure(r providers.ConfigureRequest) providers.ConfigureResponse {
|
||||
func (p *MockProvider) Configure(r providers.ConfigureRequest) (resp providers.ConfigureResponse) {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
|
||||
|
@ -248,7 +269,11 @@ func (p *MockProvider) Configure(r providers.ConfigureRequest) providers.Configu
|
|||
return p.ConfigureFn(r)
|
||||
}
|
||||
|
||||
return p.ConfigureResponse
|
||||
if p.ConfigureResponse != nil {
|
||||
return *p.ConfigureResponse
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
func (p *MockProvider) Stop() error {
|
||||
|
@ -265,7 +290,7 @@ func (p *MockProvider) Stop() error {
|
|||
return p.StopResponse
|
||||
}
|
||||
|
||||
func (p *MockProvider) ReadResource(r providers.ReadResourceRequest) providers.ReadResourceResponse {
|
||||
func (p *MockProvider) ReadResource(r providers.ReadResourceRequest) (resp providers.ReadResourceResponse) {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
|
||||
|
@ -276,24 +301,32 @@ func (p *MockProvider) ReadResource(r providers.ReadResourceRequest) providers.R
|
|||
return p.ReadResourceFn(r)
|
||||
}
|
||||
|
||||
resp := p.ReadResourceResponse
|
||||
if resp.NewState != cty.NilVal {
|
||||
// make sure the NewState fits the schema
|
||||
// This isn't always the case for the existing tests
|
||||
newState, err := p.GetSchemaReturn.ResourceTypes[r.TypeName].CoerceValue(resp.NewState)
|
||||
if p.ReadResourceResponse != nil {
|
||||
resp = *p.ReadResourceResponse
|
||||
|
||||
// Make sure the NewState conforms to the schema.
|
||||
// This isn't always the case for the existing tests.
|
||||
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 {
|
||||
panic(err)
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
}
|
||||
resp.NewState = newState
|
||||
return resp
|
||||
}
|
||||
|
||||
// just return the same state we received
|
||||
// otherwise just return the same state we received
|
||||
resp.NewState = r.PriorState
|
||||
resp.Private = r.Private
|
||||
return resp
|
||||
}
|
||||
|
||||
func (p *MockProvider) PlanResourceChange(r providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse {
|
||||
func (p *MockProvider) PlanResourceChange(r providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
|
||||
|
@ -304,10 +337,64 @@ func (p *MockProvider) PlanResourceChange(r providers.PlanResourceChangeRequest)
|
|||
return p.PlanResourceChangeFn(r)
|
||||
}
|
||||
|
||||
return p.PlanResourceChangeResponse
|
||||
if p.PlanResourceChangeResponse != nil {
|
||||
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
|
||||
}
|
||||
|
||||
// The default plan behavior is to accept the proposed value, and mark all
|
||||
// nil computed attributes as unknown.
|
||||
val, err := cty.Transform(r.ProposedNewState, func(path cty.Path, v cty.Value) (cty.Value, error) {
|
||||
// We're only concerned with known null values, which can be computed
|
||||
// by the provider.
|
||||
if !v.IsKnown() {
|
||||
return v, nil
|
||||
}
|
||||
|
||||
attrSchema := schema.Block.AttributeByPath(path)
|
||||
if attrSchema == nil {
|
||||
// this is an intermediate path which does not represent an attribute
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// get the current configuration value, to detect when a
|
||||
// computed+optional attributes has become unset
|
||||
configVal, err := path.Apply(r.Config)
|
||||
if err != nil {
|
||||
return v, err
|
||||
}
|
||||
|
||||
switch {
|
||||
case attrSchema.Computed && !attrSchema.Optional && v.IsNull():
|
||||
// this is the easy path, this value is not yet set, and _must_ be computed
|
||||
return cty.UnknownVal(v.Type()), nil
|
||||
|
||||
case attrSchema.Computed && attrSchema.Optional && !v.IsNull() && configVal.IsNull():
|
||||
// If an optional+computed value has gone from set to unset, it
|
||||
// becomes computed. (this was not possible to do with legacy
|
||||
// providers)
|
||||
return cty.UnknownVal(v.Type()), nil
|
||||
}
|
||||
|
||||
return v, nil
|
||||
})
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
return resp
|
||||
}
|
||||
|
||||
resp.PlannedPrivate = r.PriorPrivate
|
||||
resp.PlannedState = val
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
func (p *MockProvider) ApplyResourceChange(r providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse {
|
||||
func (p *MockProvider) ApplyResourceChange(r providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) {
|
||||
p.Lock()
|
||||
p.ApplyResourceChangeCalled = true
|
||||
p.ApplyResourceChangeRequest = r
|
||||
|
@ -317,7 +404,56 @@ func (p *MockProvider) ApplyResourceChange(r providers.ApplyResourceChangeReques
|
|||
return p.ApplyResourceChangeFn(r)
|
||||
}
|
||||
|
||||
return p.ApplyResourceChangeResponse
|
||||
if p.ApplyResourceChangeResponse != nil {
|
||||
return *p.ApplyResourceChangeResponse
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// if the value is nil, we return that directly to correspond to a delete
|
||||
if r.PlannedState.IsNull() {
|
||||
resp.NewState = cty.NullVal(schema.Block.ImpliedType())
|
||||
return resp
|
||||
}
|
||||
|
||||
val, err := schema.Block.CoerceValue(r.PlannedState)
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
return resp
|
||||
}
|
||||
|
||||
// the default behavior will be to create the minimal valid apply value by
|
||||
// setting unknowns (which correspond to computed attributes) to a zero
|
||||
// value.
|
||||
val, _ = cty.Transform(val, func(path cty.Path, v cty.Value) (cty.Value, error) {
|
||||
if !v.IsKnown() {
|
||||
ty := v.Type()
|
||||
switch {
|
||||
case ty == cty.String:
|
||||
return cty.StringVal(""), nil
|
||||
case ty == cty.Number:
|
||||
return cty.NumberIntVal(0), nil
|
||||
case ty == cty.Bool:
|
||||
return cty.False, nil
|
||||
case ty.IsMapType():
|
||||
return cty.MapValEmpty(ty.ElementType()), nil
|
||||
case ty.IsListType():
|
||||
return cty.ListValEmpty(ty.ElementType()), nil
|
||||
default:
|
||||
return cty.NullVal(ty), nil
|
||||
}
|
||||
}
|
||||
return v, nil
|
||||
})
|
||||
|
||||
resp.NewState = val
|
||||
resp.Private = r.PlannedPrivate
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
func (p *MockProvider) ImportResourceState(r providers.ImportResourceStateRequest) (resp providers.ImportResourceStateResponse) {
|
||||
|
@ -330,28 +466,31 @@ func (p *MockProvider) ImportResourceState(r providers.ImportResourceStateReques
|
|||
return p.ImportResourceStateFn(r)
|
||||
}
|
||||
|
||||
// fixup the cty value to match the schema
|
||||
for i, res := range p.ImportResourceStateResponse.ImportedResources {
|
||||
schema := p.GetSchemaReturn.ResourceTypes[res.TypeName]
|
||||
if schema == nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(errors.New("no schema found for " + res.TypeName))
|
||||
return resp
|
||||
}
|
||||
if p.ImportResourceStateResponse != nil {
|
||||
resp = *p.ImportResourceStateResponse
|
||||
// fixup the cty value to match the schema
|
||||
for i, res := range resp.ImportedResources {
|
||||
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)
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
return resp
|
||||
}
|
||||
var err error
|
||||
res.State, err = schema.Block.CoerceValue(res.State)
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
return resp
|
||||
}
|
||||
|
||||
p.ImportResourceStateResponse.ImportedResources[i] = res
|
||||
resp.ImportedResources[i] = res
|
||||
}
|
||||
}
|
||||
|
||||
return p.ImportResourceStateResponse
|
||||
return resp
|
||||
}
|
||||
|
||||
func (p *MockProvider) ReadDataSource(r providers.ReadDataSourceRequest) providers.ReadDataSourceResponse {
|
||||
func (p *MockProvider) ReadDataSource(r providers.ReadDataSourceRequest) (resp providers.ReadDataSourceResponse) {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
|
||||
|
@ -362,7 +501,11 @@ func (p *MockProvider) ReadDataSource(r providers.ReadDataSourceRequest) provide
|
|||
return p.ReadDataSourceFn(r)
|
||||
}
|
||||
|
||||
return p.ReadDataSourceResponse
|
||||
if p.ReadDataSourceResponse != nil {
|
||||
resp = *p.ReadDataSourceResponse
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
func (p *MockProvider) Close() error {
|
||||
|
|
|
@ -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()},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
func TestGraphNodeImportStateExecute(t *testing.T) {
|
||||
state := states.NewState()
|
||||
provider := testProvider("aws")
|
||||
provider.ImportResourceStateResponse = providers.ImportResourceStateResponse{
|
||||
provider.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
{
|
||||
TypeName: "aws_instance",
|
||||
|
|
Loading…
Reference in New Issue