change mock provider to use GetSchemaResponse
This ensures that test providers are using the same types as actual providers.
This commit is contained in:
parent
5fe848b642
commit
7dd570ef6c
|
@ -94,7 +94,7 @@ func TestContext2Apply_unstable(t *testing.T) {
|
|||
Type: "test_resource",
|
||||
Name: "foo",
|
||||
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance)
|
||||
schema := p.GetSchemaReturn.ResourceTypes["test_resource"] // automatically available in mock
|
||||
schema := p.GetSchemaResponse.ResourceTypes["test_resource"].Block
|
||||
rds := plan.Changes.ResourceInstance(addr)
|
||||
rd, err := rds.Decode(schema.ImpliedType())
|
||||
if err != nil {
|
||||
|
@ -1600,7 +1600,7 @@ func TestContext2Apply_destroyCrossProviders(t *testing.T) {
|
|||
p_aws := testProvider("aws")
|
||||
p_aws.ApplyResourceChangeFn = testApplyFn
|
||||
p_aws.PlanResourceChangeFn = testDiffFn
|
||||
p_aws.GetSchemaReturn = &ProviderSchema{
|
||||
p_aws.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -1623,7 +1623,7 @@ func TestContext2Apply_destroyCrossProviders(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
providers := map[addrs.Provider]providers.Factory{
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p_aws),
|
||||
|
@ -1939,7 +1939,7 @@ func TestContext2Apply_compute(t *testing.T) {
|
|||
p := testProvider("aws")
|
||||
p.ApplyResourceChangeFn = testApplyFn
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -1974,7 +1974,7 @@ func TestContext2Apply_compute(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
|
@ -2438,7 +2438,7 @@ func TestContext2Apply_moduleDestroyOrder(t *testing.T) {
|
|||
return resp
|
||||
}
|
||||
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -2448,7 +2448,7 @@ func TestContext2Apply_moduleDestroyOrder(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
state := states.NewState()
|
||||
child := state.EnsureModule(addrs.RootModuleInstance.Child("child", addrs.NoKey))
|
||||
|
@ -2559,7 +2559,7 @@ func TestContext2Apply_orphanResource(t *testing.T) {
|
|||
p := testProvider("test")
|
||||
p.ApplyResourceChangeFn = testApplyFn
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test_thing": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -2568,7 +2568,7 @@ func TestContext2Apply_orphanResource(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
// Step 1: create the resources and instances
|
||||
m := testModule(t, "apply-orphan-resource")
|
||||
|
@ -3172,7 +3172,7 @@ func TestContext2Apply_multiProviderDestroy(t *testing.T) {
|
|||
p := testProvider("aws")
|
||||
p.ApplyResourceChangeFn = testApplyFn
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
Provider: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"addr": {Type: cty.String, Optional: true},
|
||||
|
@ -3186,12 +3186,12 @@ func TestContext2Apply_multiProviderDestroy(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
p2 := testProvider("vault")
|
||||
p2.ApplyResourceChangeFn = testApplyFn
|
||||
p2.PlanResourceChangeFn = testDiffFn
|
||||
p2.GetSchemaReturn = &ProviderSchema{
|
||||
p2.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"vault_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -3199,7 +3199,7 @@ func TestContext2Apply_multiProviderDestroy(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
var state *states.State
|
||||
|
||||
|
@ -3293,7 +3293,7 @@ func TestContext2Apply_multiProviderDestroyChild(t *testing.T) {
|
|||
p := testProvider("aws")
|
||||
p.ApplyResourceChangeFn = testApplyFn
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
Provider: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"value": {Type: cty.String, Optional: true},
|
||||
|
@ -3307,12 +3307,12 @@ func TestContext2Apply_multiProviderDestroyChild(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
p2 := testProvider("vault")
|
||||
p2.ApplyResourceChangeFn = testApplyFn
|
||||
p2.PlanResourceChangeFn = testDiffFn
|
||||
p2.GetSchemaReturn = &ProviderSchema{
|
||||
p2.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
Provider: &configschema.Block{},
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"vault_instance": {
|
||||
|
@ -3321,7 +3321,7 @@ func TestContext2Apply_multiProviderDestroyChild(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
var state *states.State
|
||||
|
||||
|
@ -3530,7 +3530,7 @@ func TestContext2Apply_multiVarComprehensive(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test_thing": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -3552,7 +3552,7 @@ func TestContext2Apply_multiVarComprehensive(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
// First, apply with a count of 3
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
|
@ -3880,7 +3880,7 @@ func TestContext2Apply_multiVarMissingState(t *testing.T) {
|
|||
p := testProvider("test")
|
||||
p.ApplyResourceChangeFn = testApplyFn
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test_thing": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -3889,7 +3889,7 @@ func TestContext2Apply_multiVarMissingState(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
// First, apply with a count of 3
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
|
@ -4447,7 +4447,7 @@ func TestContext2Apply_multiDepose_createBeforeDestroy(t *testing.T) {
|
|||
m := testModule(t, "apply-multi-depose-create-before-destroy")
|
||||
p := testProvider("aws")
|
||||
ps := map[addrs.Provider]providers.Factory{addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p)}
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -4456,7 +4456,7 @@ func TestContext2Apply_multiDepose_createBeforeDestroy(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
|
@ -6328,7 +6328,7 @@ func TestContext2Apply_errorDestroy(t *testing.T) {
|
|||
m := testModule(t, "empty")
|
||||
p := testProvider("test")
|
||||
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test_thing": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -6336,7 +6336,7 @@ func TestContext2Apply_errorDestroy(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse {
|
||||
// Should actually be called for this test, because Terraform Core
|
||||
// constructs the plan for a destroy operation itself.
|
||||
|
@ -6401,7 +6401,7 @@ func TestContext2Apply_errorCreateInvalidNew(t *testing.T) {
|
|||
m := testModule(t, "apply-error")
|
||||
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -6410,7 +6410,7 @@ func TestContext2Apply_errorCreateInvalidNew(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse {
|
||||
return providers.PlanResourceChangeResponse{
|
||||
PlannedState: req.ProposedNewState,
|
||||
|
@ -6465,7 +6465,7 @@ func TestContext2Apply_errorUpdateNullNew(t *testing.T) {
|
|||
m := testModule(t, "apply-error")
|
||||
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -6474,7 +6474,7 @@ func TestContext2Apply_errorUpdateNullNew(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse {
|
||||
return providers.PlanResourceChangeResponse{
|
||||
PlannedState: req.ProposedNewState,
|
||||
|
@ -7713,7 +7713,7 @@ func TestContext2Apply_unknownAttribute(t *testing.T) {
|
|||
return resp
|
||||
}
|
||||
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -7724,7 +7724,7 @@ func TestContext2Apply_unknownAttribute(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
|
@ -8074,7 +8074,7 @@ func TestContext2Apply_issue7824(t *testing.T) {
|
|||
p := testProvider("template")
|
||||
p.ApplyResourceChangeFn = testApplyFn
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"template_file": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -8083,7 +8083,7 @@ func TestContext2Apply_issue7824(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
m, snap := testModuleWithSnapshot(t, "issue-7824")
|
||||
|
||||
|
@ -8130,7 +8130,7 @@ func TestContext2Apply_issue5254(t *testing.T) {
|
|||
p := testProvider("template")
|
||||
p.ApplyResourceChangeFn = testApplyFn
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"template_file": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -8141,7 +8141,7 @@ func TestContext2Apply_issue5254(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
// Apply cleanly step 0
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
|
@ -8297,7 +8297,7 @@ func TestContext2Apply_ignoreChangesCreate(t *testing.T) {
|
|||
p.ApplyResourceChangeFn = testApplyFn
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
|
||||
instanceSchema := p.GetSchemaReturn.ResourceTypes["aws_instance"]
|
||||
instanceSchema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block
|
||||
instanceSchema.Attributes["required_field"] = &configschema.Attribute{
|
||||
Type: cty.String,
|
||||
Required: true,
|
||||
|
@ -8441,7 +8441,7 @@ func TestContext2Apply_ignoreChangesWildcard(t *testing.T) {
|
|||
p.ApplyResourceChangeFn = testApplyFn
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
|
||||
instanceSchema := p.GetSchemaReturn.ResourceTypes["aws_instance"]
|
||||
instanceSchema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block
|
||||
instanceSchema.Attributes["required_field"] = &configschema.Attribute{
|
||||
Type: cty.String,
|
||||
Required: true,
|
||||
|
@ -9248,7 +9248,7 @@ func TestContext2Apply_scaleInMultivarRef(t *testing.T) {
|
|||
func TestContext2Apply_inconsistentWithPlan(t *testing.T) {
|
||||
m := testModule(t, "apply-inconsistent-with-plan")
|
||||
p := testProvider("test")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -9256,7 +9256,7 @@ func TestContext2Apply_inconsistentWithPlan(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse {
|
||||
return providers.PlanResourceChangeResponse{
|
||||
PlannedState: cty.ObjectVal(map[string]cty.Value{
|
||||
|
@ -9301,7 +9301,7 @@ func TestContext2Apply_inconsistentWithPlan(t *testing.T) {
|
|||
func TestContext2Apply_issue19908(t *testing.T) {
|
||||
m := testModule(t, "apply-issue19908")
|
||||
p := testProvider("test")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -9309,7 +9309,7 @@ func TestContext2Apply_issue19908(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse {
|
||||
return providers.PlanResourceChangeResponse{
|
||||
PlannedState: req.ProposedNewState,
|
||||
|
@ -9382,7 +9382,7 @@ func TestContext2Apply_issue19908(t *testing.T) {
|
|||
|
||||
func TestContext2Apply_invalidIndexRef(t *testing.T) {
|
||||
p := testProvider("test")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -9390,7 +9390,7 @@ func TestContext2Apply_invalidIndexRef(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
|
||||
m := testModule(t, "apply-invalid-index")
|
||||
|
@ -9440,11 +9440,11 @@ func TestContext2Apply_moduleReplaceCycle(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": instanceSchema,
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
state := states.NewState()
|
||||
modA := state.EnsureModule(addrs.RootModuleInstance.Child("a", addrs.NoKey))
|
||||
|
@ -9715,7 +9715,7 @@ func TestContext2Apply_taintedDestroyFailure(t *testing.T) {
|
|||
|
||||
return testApplyFn(req)
|
||||
}
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -9730,7 +9730,7 @@ func TestContext2Apply_taintedDestroyFailure(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
|
@ -10037,7 +10037,7 @@ func TestContext2Apply_ProviderMeta_apply_set(t *testing.T) {
|
|||
m := testModule(t, "provider-meta-set")
|
||||
p := testProvider("test")
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
schema := p.GetSchemaReturn
|
||||
schema := p.ProviderSchema()
|
||||
schema.ProviderMeta = &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"baz": {
|
||||
|
@ -10064,7 +10064,7 @@ func TestContext2Apply_ProviderMeta_apply_set(t *testing.T) {
|
|||
NewState: cty.ObjectVal(s),
|
||||
}
|
||||
}
|
||||
p.GetSchemaReturn = schema
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
|
@ -10120,7 +10120,7 @@ func TestContext2Apply_ProviderMeta_apply_unset(t *testing.T) {
|
|||
m := testModule(t, "provider-meta-unset")
|
||||
p := testProvider("test")
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
schema := p.GetSchemaReturn
|
||||
schema := p.ProviderSchema()
|
||||
schema.ProviderMeta = &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"baz": {
|
||||
|
@ -10145,7 +10145,7 @@ func TestContext2Apply_ProviderMeta_apply_unset(t *testing.T) {
|
|||
NewState: cty.ObjectVal(s),
|
||||
}
|
||||
}
|
||||
p.GetSchemaReturn = schema
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
|
@ -10180,7 +10180,7 @@ func TestContext2Apply_ProviderMeta_plan_set(t *testing.T) {
|
|||
m := testModule(t, "provider-meta-set")
|
||||
p := testProvider("test")
|
||||
p.ApplyResourceChangeFn = testApplyFn
|
||||
schema := p.GetSchemaReturn
|
||||
schema := p.ProviderSchema()
|
||||
schema.ProviderMeta = &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"baz": {
|
||||
|
@ -10196,7 +10196,7 @@ func TestContext2Apply_ProviderMeta_plan_set(t *testing.T) {
|
|||
PlannedState: req.ProposedNewState,
|
||||
}
|
||||
}
|
||||
p.GetSchemaReturn = schema
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
|
@ -10249,7 +10249,7 @@ func TestContext2Apply_ProviderMeta_plan_unset(t *testing.T) {
|
|||
m := testModule(t, "provider-meta-unset")
|
||||
p := testProvider("test")
|
||||
p.ApplyResourceChangeFn = testApplyFn
|
||||
schema := p.GetSchemaReturn
|
||||
schema := p.ProviderSchema()
|
||||
schema.ProviderMeta = &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"baz": {
|
||||
|
@ -10265,7 +10265,7 @@ func TestContext2Apply_ProviderMeta_plan_unset(t *testing.T) {
|
|||
PlannedState: req.ProposedNewState,
|
||||
}
|
||||
}
|
||||
p.GetSchemaReturn = schema
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
|
@ -10338,7 +10338,7 @@ func TestContext2Apply_ProviderMeta_plan_setInvalid(t *testing.T) {
|
|||
p := testProvider("test")
|
||||
p.ApplyResourceChangeFn = testApplyFn
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
schema := p.GetSchemaReturn
|
||||
schema := p.ProviderSchema()
|
||||
schema.ProviderMeta = &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"quux": {
|
||||
|
@ -10347,7 +10347,7 @@ func TestContext2Apply_ProviderMeta_plan_setInvalid(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
p.GetSchemaReturn = schema
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
|
@ -10392,7 +10392,7 @@ func TestContext2Apply_ProviderMeta_refresh_set(t *testing.T) {
|
|||
p := testProvider("test")
|
||||
p.ApplyResourceChangeFn = testApplyFn
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
schema := p.GetSchemaReturn
|
||||
schema := p.ProviderSchema()
|
||||
schema.ProviderMeta = &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"baz": {
|
||||
|
@ -10404,14 +10404,14 @@ func TestContext2Apply_ProviderMeta_refresh_set(t *testing.T) {
|
|||
rrcPMs := map[string]cty.Value{}
|
||||
p.ReadResourceFn = func(req providers.ReadResourceRequest) (resp providers.ReadResourceResponse) {
|
||||
rrcPMs[req.TypeName] = req.ProviderMeta
|
||||
newState, err := p.GetSchemaReturn.ResourceTypes[req.TypeName].CoerceValue(req.PriorState)
|
||||
newState, err := p.GetSchemaResponse.ResourceTypes[req.TypeName].Block.CoerceValue(req.PriorState)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
resp.NewState = newState
|
||||
return resp
|
||||
}
|
||||
p.GetSchemaReturn = schema
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
|
@ -10473,7 +10473,7 @@ func TestContext2Apply_ProviderMeta_refresh_setNoSchema(t *testing.T) {
|
|||
p.PlanResourceChangeFn = testDiffFn
|
||||
|
||||
// we need a schema for plan/apply so they don't error
|
||||
schema := p.GetSchemaReturn
|
||||
schema := p.ProviderSchema()
|
||||
schema.ProviderMeta = &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"baz": {
|
||||
|
@ -10482,7 +10482,7 @@ func TestContext2Apply_ProviderMeta_refresh_setNoSchema(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
p.GetSchemaReturn = schema
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
|
@ -10498,7 +10498,7 @@ func TestContext2Apply_ProviderMeta_refresh_setNoSchema(t *testing.T) {
|
|||
|
||||
// drop the schema before refresh, to test that it errors
|
||||
schema.ProviderMeta = nil
|
||||
p.GetSchemaReturn = schema
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
|
||||
ctx = testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
|
@ -10542,7 +10542,7 @@ func TestContext2Apply_ProviderMeta_refresh_setInvalid(t *testing.T) {
|
|||
p.PlanResourceChangeFn = testDiffFn
|
||||
|
||||
// we need a matching schema for plan/apply so they don't error
|
||||
schema := p.GetSchemaReturn
|
||||
schema := p.ProviderSchema()
|
||||
schema.ProviderMeta = &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"baz": {
|
||||
|
@ -10551,7 +10551,7 @@ func TestContext2Apply_ProviderMeta_refresh_setInvalid(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
p.GetSchemaReturn = schema
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
|
@ -10574,7 +10574,7 @@ func TestContext2Apply_ProviderMeta_refresh_setInvalid(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
p.GetSchemaReturn = schema
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
|
||||
ctx = testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
|
@ -10620,7 +10620,7 @@ func TestContext2Apply_ProviderMeta_refreshdata_set(t *testing.T) {
|
|||
p := testProvider("test")
|
||||
p.ApplyResourceChangeFn = testApplyFn
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
schema := p.GetSchemaReturn
|
||||
schema := p.ProviderSchema()
|
||||
schema.ProviderMeta = &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"baz": {
|
||||
|
@ -10629,7 +10629,7 @@ func TestContext2Apply_ProviderMeta_refreshdata_set(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
p.GetSchemaReturn = schema
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
|
@ -10716,7 +10716,7 @@ func TestContext2Apply_ProviderMeta_refreshdata_unset(t *testing.T) {
|
|||
p := testProvider("test")
|
||||
p.ApplyResourceChangeFn = testApplyFn
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
schema := p.GetSchemaReturn
|
||||
schema := p.ProviderSchema()
|
||||
schema.ProviderMeta = &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"baz": {
|
||||
|
@ -10725,7 +10725,7 @@ func TestContext2Apply_ProviderMeta_refreshdata_unset(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
p.GetSchemaReturn = schema
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
|
@ -10831,7 +10831,7 @@ func TestContext2Apply_ProviderMeta_refreshdata_setInvalid(t *testing.T) {
|
|||
p := testProvider("test")
|
||||
p.ApplyResourceChangeFn = testApplyFn
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
schema := p.GetSchemaReturn
|
||||
schema := p.ProviderSchema()
|
||||
schema.ProviderMeta = &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"quux": {
|
||||
|
@ -10840,7 +10840,7 @@ func TestContext2Apply_ProviderMeta_refreshdata_setInvalid(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
p.GetSchemaReturn = schema
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(schema)
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
|
@ -11466,7 +11466,7 @@ output "output" {
|
|||
testP.ReadResourceFn = func(req providers.ReadResourceRequest) providers.ReadResourceResponse {
|
||||
return providers.ReadResourceResponse{NewState: req.PriorState}
|
||||
}
|
||||
testP.GetSchemaReturn = schemaFn("test")
|
||||
testP.GetSchemaResponse = getSchemaResponseFromProviderSchema(schemaFn("test"))
|
||||
|
||||
providerConfig := ""
|
||||
testP.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) {
|
||||
|
@ -11491,7 +11491,7 @@ output "output" {
|
|||
nullP.ReadResourceFn = func(req providers.ReadResourceRequest) providers.ReadResourceResponse {
|
||||
return providers.ReadResourceResponse{NewState: req.PriorState}
|
||||
}
|
||||
nullP.GetSchemaReturn = schemaFn("null")
|
||||
nullP.GetSchemaResponse = getSchemaResponseFromProviderSchema(schemaFn("null"))
|
||||
|
||||
nullP.ApplyResourceChangeFn = testApplyFn
|
||||
nullP.PlanResourceChangeFn = testDiffFn
|
||||
|
@ -11880,7 +11880,7 @@ resource "test_resource" "foo" {
|
|||
p.ReadResourceFn = func(req providers.ReadResourceRequest) providers.ReadResourceResponse {
|
||||
return providers.ReadResourceResponse{NewState: req.PriorState}
|
||||
}
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
Provider: &configschema.Block{},
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test_resource": {
|
||||
|
@ -11908,7 +11908,7 @@ resource "test_resource" "foo" {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
p.ApplyResourceChangeFn = testApplyFn
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
|
||||
|
@ -12384,7 +12384,7 @@ resource "test_instance" "a" {
|
|||
return resp
|
||||
}
|
||||
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -12392,7 +12392,7 @@ resource "test_instance" "a" {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
|
|
|
@ -654,7 +654,7 @@ func TestContextImport_multiState(t *testing.T) {
|
|||
p := testProvider("aws")
|
||||
m := testModule(t, "import-provider")
|
||||
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
Provider: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
|
@ -672,7 +672,7 @@ func TestContextImport_multiState(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
|
@ -723,7 +723,7 @@ func TestContextImport_multiStateSame(t *testing.T) {
|
|||
p := testProvider("aws")
|
||||
m := testModule(t, "import-provider")
|
||||
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
Provider: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
|
@ -741,7 +741,7 @@ func TestContextImport_multiStateSame(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
|
@ -829,7 +829,7 @@ resource "test_resource" "unused" {
|
|||
`,
|
||||
})
|
||||
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
Provider: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
|
@ -842,7 +842,7 @@ resource "test_resource" "unused" {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
|
||||
ImportedResources: []providers.ImportedResource{
|
||||
|
|
|
@ -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 {
|
||||
|
@ -105,7 +105,7 @@ func TestContext2Refresh_dynamicAttr(t *testing.T) {
|
|||
})
|
||||
|
||||
p := testProvider("test")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -113,7 +113,7 @@ func TestContext2Refresh_dynamicAttr(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
p.ReadResourceFn = func(req providers.ReadResourceRequest) providers.ReadResourceResponse {
|
||||
return providers.ReadResourceResponse{
|
||||
NewState: readStateVal,
|
||||
|
@ -132,7 +132,7 @@ func TestContext2Refresh_dynamicAttr(t *testing.T) {
|
|||
State: startingState,
|
||||
})
|
||||
|
||||
schema := p.GetSchemaReturn.ResourceTypes["test_instance"]
|
||||
schema := p.GetSchemaResponse.ResourceTypes["test_instance"].Block
|
||||
ty := schema.ImpliedType()
|
||||
|
||||
s, diags := ctx.Refresh()
|
||||
|
@ -169,7 +169,7 @@ func TestContext2Refresh_dataComputedModuleVar(t *testing.T) {
|
|||
return resp
|
||||
}
|
||||
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
Provider: &configschema.Block{},
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {
|
||||
|
@ -199,7 +199,7 @@ func TestContext2Refresh_dataComputedModuleVar(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
|
@ -220,7 +220,7 @@ func TestContext2Refresh_dataComputedModuleVar(t *testing.T) {
|
|||
|
||||
func TestContext2Refresh_targeted(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
Provider: &configschema.Block{},
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_elb": {
|
||||
|
@ -252,7 +252,7 @@ func TestContext2Refresh_targeted(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
|
@ -297,7 +297,7 @@ func TestContext2Refresh_targeted(t *testing.T) {
|
|||
|
||||
func TestContext2Refresh_targetedCount(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
Provider: &configschema.Block{},
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_elb": {
|
||||
|
@ -329,7 +329,7 @@ func TestContext2Refresh_targetedCount(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
|
@ -384,7 +384,7 @@ func TestContext2Refresh_targetedCount(t *testing.T) {
|
|||
|
||||
func TestContext2Refresh_targetedCountIndex(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
Provider: &configschema.Block{},
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_elb": {
|
||||
|
@ -416,7 +416,7 @@ func TestContext2Refresh_targetedCountIndex(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
|
@ -463,7 +463,7 @@ func TestContext2Refresh_targetedCountIndex(t *testing.T) {
|
|||
|
||||
func TestContext2Refresh_moduleComputedVar(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
Provider: &configschema.Block{},
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {
|
||||
|
@ -479,7 +479,7 @@ func TestContext2Refresh_moduleComputedVar(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
|
||||
m := testModule(t, "refresh-module-computed-var")
|
||||
|
@ -515,7 +515,7 @@ func TestContext2Refresh_delete(t *testing.T) {
|
|||
|
||||
p.ReadResourceFn = nil
|
||||
p.ReadResourceResponse = &providers.ReadResourceResponse{
|
||||
NewState: cty.NullVal(p.GetSchemaReturn.ResourceTypes["aws_instance"].ImpliedType()),
|
||||
NewState: cty.NullVal(p.GetSchemaResponse.ResourceTypes["aws_instance"].Block.ImpliedType()),
|
||||
}
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
|
||||
|
@ -641,7 +641,7 @@ func TestContext2Refresh_moduleInputComputedOutput(t *testing.T) {
|
|||
m := testModule(t, "refresh-module-input-computed-output")
|
||||
p := testProvider("aws")
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
Provider: &configschema.Block{},
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {
|
||||
|
@ -658,7 +658,7 @@ func TestContext2Refresh_moduleInputComputedOutput(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
|
@ -714,7 +714,7 @@ func TestContext2Refresh_noState(t *testing.T) {
|
|||
|
||||
func TestContext2Refresh_output(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
Provider: &configschema.Block{},
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {
|
||||
|
@ -731,7 +731,7 @@ func TestContext2Refresh_output(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
|
||||
m := testModule(t, "refresh-output")
|
||||
|
@ -770,7 +770,7 @@ func TestContext2Refresh_outputPartial(t *testing.T) {
|
|||
// we need to make DiffFn available to let that complete.
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
Provider: &configschema.Block{},
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {
|
||||
|
@ -782,11 +782,11 @@ func TestContext2Refresh_outputPartial(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
p.ReadResourceFn = nil
|
||||
p.ReadResourceResponse = &providers.ReadResourceResponse{
|
||||
NewState: cty.NullVal(p.GetSchemaReturn.ResourceTypes["aws_instance"].ImpliedType()),
|
||||
NewState: cty.NullVal(p.GetSchemaResponse.ResourceTypes["aws_instance"].Block.ImpliedType()),
|
||||
}
|
||||
|
||||
state := states.NewState()
|
||||
|
@ -829,7 +829,7 @@ func TestContext2Refresh_stateBasic(t *testing.T) {
|
|||
State: state,
|
||||
})
|
||||
|
||||
schema := p.GetSchemaReturn.ResourceTypes["aws_instance"]
|
||||
schema := p.GetSchemaResponse.ResourceTypes["aws_instance"].Block
|
||||
ty := schema.ImpliedType()
|
||||
|
||||
readStateVal, err := schema.CoerceValue(cty.ObjectVal(map[string]cty.Value{
|
||||
|
@ -875,7 +875,7 @@ func TestContext2Refresh_dataCount(t *testing.T) {
|
|||
resp.PlannedState = cty.ObjectVal(m)
|
||||
return resp
|
||||
}
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -887,7 +887,7 @@ func TestContext2Refresh_dataCount(t *testing.T) {
|
|||
DataSources: map[string]*configschema.Block{
|
||||
"test": {},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
p.ReadDataSourceFn = func(req providers.ReadDataSourceRequest) providers.ReadDataSourceResponse {
|
||||
return providers.ReadDataSourceResponse{
|
||||
|
@ -924,12 +924,12 @@ func TestContext2Refresh_dataState(t *testing.T) {
|
|||
}
|
||||
|
||||
p := testProvider("null")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
Provider: &configschema.Block{},
|
||||
DataSources: map[string]*configschema.Block{
|
||||
"null_data_source": schema,
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
|
@ -974,7 +974,7 @@ func TestContext2Refresh_dataState(t *testing.T) {
|
|||
|
||||
func TestContext2Refresh_dataStateRefData(t *testing.T) {
|
||||
p := testProvider("null")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
Provider: &configschema.Block{},
|
||||
DataSources: map[string]*configschema.Block{
|
||||
"null_data_source": {
|
||||
|
@ -994,7 +994,7 @@ func TestContext2Refresh_dataStateRefData(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
m := testModule(t, "refresh-data-ref-data")
|
||||
state := states.NewState()
|
||||
|
@ -1115,10 +1115,10 @@ func TestContext2Refresh_vars(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
Provider: &configschema.Block{},
|
||||
ResourceTypes: map[string]*configschema.Block{"aws_instance": schema},
|
||||
}
|
||||
})
|
||||
|
||||
m := testModule(t, "refresh-vars")
|
||||
state := states.NewState()
|
||||
|
@ -1248,7 +1248,7 @@ func TestContext2Refresh_orphanModule(t *testing.T) {
|
|||
|
||||
func TestContext2Validate(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
Provider: &configschema.Block{},
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {
|
||||
|
@ -1264,7 +1264,7 @@ func TestContext2Validate(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
|
||||
m := testModule(t, "validate-good")
|
||||
|
@ -1318,7 +1318,7 @@ aws_instance.bar:
|
|||
func TestContext2Refresh_schemaUpgradeFlatmap(t *testing.T) {
|
||||
m := testModule(t, "refresh-schema-upgrade")
|
||||
p := testProvider("test")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test_thing": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -1332,7 +1332,7 @@ func TestContext2Refresh_schemaUpgradeFlatmap(t *testing.T) {
|
|||
ResourceTypeSchemaVersions: map[string]uint64{
|
||||
"test_thing": 5,
|
||||
},
|
||||
}
|
||||
})
|
||||
p.UpgradeResourceStateResponse = &providers.UpgradeResourceStateResponse{
|
||||
UpgradedState: cty.ObjectVal(map[string]cty.Value{
|
||||
"name": cty.StringVal("foo"),
|
||||
|
@ -1405,7 +1405,7 @@ test_thing.bar:
|
|||
func TestContext2Refresh_schemaUpgradeJSON(t *testing.T) {
|
||||
m := testModule(t, "refresh-schema-upgrade")
|
||||
p := testProvider("test")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test_thing": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -1419,7 +1419,7 @@ func TestContext2Refresh_schemaUpgradeJSON(t *testing.T) {
|
|||
ResourceTypeSchemaVersions: map[string]uint64{
|
||||
"test_thing": 5,
|
||||
},
|
||||
}
|
||||
})
|
||||
p.UpgradeResourceStateResponse = &providers.UpgradeResourceStateResponse{
|
||||
UpgradedState: cty.ObjectVal(map[string]cty.Value{
|
||||
"name": cty.StringVal("foo"),
|
||||
|
@ -1527,7 +1527,7 @@ data "aws_data_source" "foo" {
|
|||
func TestContext2Refresh_dataResourceDependsOn(t *testing.T) {
|
||||
m := testModule(t, "plan-data-depends-on")
|
||||
p := testProvider("test")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test_resource": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -1543,7 +1543,7 @@ func TestContext2Refresh_dataResourceDependsOn(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.ReadDataSourceResponse = &providers.ReadDataSourceResponse{
|
||||
State: cty.ObjectVal(map[string]cty.Value{
|
||||
|
|
|
@ -405,7 +405,7 @@ func testProvider(prefix string) *MockProvider {
|
|||
return providers.ReadResourceResponse{NewState: req.PriorState}
|
||||
}
|
||||
|
||||
p.GetSchemaReturn = testProviderSchema(prefix)
|
||||
p.GetSchemaResponse = testProviderSchema(prefix)
|
||||
|
||||
return p
|
||||
}
|
||||
|
@ -465,8 +465,8 @@ func testCheckDeadlock(t *testing.T, f func()) {
|
|||
}
|
||||
}
|
||||
|
||||
func testProviderSchema(name string) *ProviderSchema {
|
||||
return &ProviderSchema{
|
||||
func testProviderSchema(name string) *providers.GetSchemaResponse {
|
||||
return getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
Provider: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"region": {
|
||||
|
@ -708,8 +708,7 @@ func testProviderSchema(name string) *ProviderSchema {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
// contextForPlanViaFile is a helper that creates a temporary plan file, then
|
||||
|
|
|
@ -18,13 +18,13 @@ import (
|
|||
|
||||
func TestContext2Validate_badCount(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
m := testModule(t, "validate-bad-count")
|
||||
c := testContext2(t, &ContextOpts{
|
||||
|
@ -42,13 +42,13 @@ func TestContext2Validate_badCount(t *testing.T) {
|
|||
|
||||
func TestContext2Validate_badResource_reference(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
m := testModule(t, "validate-bad-resource-count")
|
||||
c := testContext2(t, &ContextOpts{
|
||||
|
@ -66,7 +66,7 @@ func TestContext2Validate_badResource_reference(t *testing.T) {
|
|||
|
||||
func TestContext2Validate_badVar(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -75,7 +75,7 @@ func TestContext2Validate_badVar(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
m := testModule(t, "validate-bad-var")
|
||||
c := testContext2(t, &ContextOpts{
|
||||
|
@ -94,7 +94,7 @@ func TestContext2Validate_badVar(t *testing.T) {
|
|||
func TestContext2Validate_varMapOverrideOld(t *testing.T) {
|
||||
m := testModule(t, "validate-module-pc-vars")
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
p.GetSchemaResponse = getSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
Provider: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
|
@ -105,7 +105,7 @@ func TestContext2Validate_varMapOverrideOld(t *testing.T) {
|
|||
Attributes: map[string]*configschema.Attribute{},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
_, diags := NewContext(&ContextOpts{
|
||||
Config: m,
|
||||
|
@ -133,25 +133,31 @@ func TestContext2Validate_varNoDefaultExplicitType(t *testing.T) {
|
|||
|
||||
func TestContext2Validate_computedVar(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
Provider: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"value": {Type: cty.String, Optional: true},
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
Provider: providers.Schema{
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"value": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
pt := testProvider("test")
|
||||
pt.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
pt.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"test_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"id": {Type: cty.String, Computed: true},
|
||||
"value": {Type: cty.String, Optional: true},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"id": {Type: cty.String, Computed: true},
|
||||
"value": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -186,19 +192,23 @@ func TestContext2Validate_computedVar(t *testing.T) {
|
|||
|
||||
func TestContext2Validate_computedInFunction(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"attr": {Type: cty.Number, Optional: true},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"attr": {Type: cty.Number, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
DataSources: map[string]*configschema.Block{
|
||||
DataSources: map[string]providers.Schema{
|
||||
"aws_data_source": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"optional_attr": {Type: cty.String, Optional: true},
|
||||
"computed": {Type: cty.String, Computed: true},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"optional_attr": {Type: cty.String, Optional: true},
|
||||
"computed": {Type: cty.String, Computed: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -223,17 +233,21 @@ func TestContext2Validate_computedInFunction(t *testing.T) {
|
|||
// can be realized during a plan.
|
||||
func TestContext2Validate_countComputed(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{},
|
||||
},
|
||||
},
|
||||
},
|
||||
DataSources: map[string]*configschema.Block{
|
||||
DataSources: map[string]providers.Schema{
|
||||
"aws_data_source": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"compute": {Type: cty.String, Optional: true},
|
||||
"value": {Type: cty.String, Computed: true},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"compute": {Type: cty.String, Optional: true},
|
||||
"value": {Type: cty.String, Computed: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -255,14 +269,15 @@ func TestContext2Validate_countComputed(t *testing.T) {
|
|||
|
||||
func TestContext2Validate_countNegative(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
m := testModule(t, "validate-count-negative")
|
||||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
|
@ -279,16 +294,17 @@ func TestContext2Validate_countNegative(t *testing.T) {
|
|||
|
||||
func TestContext2Validate_countVariable(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
m := testModule(t, "apply-count-variable")
|
||||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
|
@ -306,16 +322,17 @@ func TestContext2Validate_countVariable(t *testing.T) {
|
|||
func TestContext2Validate_countVariableNoDefault(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "validate-count-variable")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
_, diags := NewContext(&ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
|
@ -330,16 +347,17 @@ func TestContext2Validate_countVariableNoDefault(t *testing.T) {
|
|||
|
||||
func TestContext2Validate_moduleBadOutput(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
m := testModule(t, "validate-bad-module-output")
|
||||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
|
@ -356,16 +374,17 @@ func TestContext2Validate_moduleBadOutput(t *testing.T) {
|
|||
|
||||
func TestContext2Validate_moduleGood(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
m := testModule(t, "validate-good-module")
|
||||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
|
@ -383,10 +402,12 @@ func TestContext2Validate_moduleGood(t *testing.T) {
|
|||
func TestContext2Validate_moduleBadResource(t *testing.T) {
|
||||
m := testModule(t, "validate-module-bad-rc")
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -411,11 +432,13 @@ func TestContext2Validate_moduleBadResource(t *testing.T) {
|
|||
func TestContext2Validate_moduleDepsShouldNotCycle(t *testing.T) {
|
||||
m := testModule(t, "validate-module-deps-cycle")
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"id": {Type: cty.String, Optional: true},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"id": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -437,19 +460,23 @@ func TestContext2Validate_moduleDepsShouldNotCycle(t *testing.T) {
|
|||
func TestContext2Validate_moduleProviderVar(t *testing.T) {
|
||||
m := testModule(t, "validate-module-pc-vars")
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
Provider: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
Provider: providers.Schema{
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
c := testContext2(t, &ContextOpts{
|
||||
|
@ -481,19 +508,23 @@ func TestContext2Validate_moduleProviderVar(t *testing.T) {
|
|||
func TestContext2Validate_moduleProviderInheritUnused(t *testing.T) {
|
||||
m := testModule(t, "validate-module-pc-inherit-unused")
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
Provider: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
Provider: providers.Schema{
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
c := testContext2(t, &ContextOpts{
|
||||
|
@ -518,12 +549,14 @@ func TestContext2Validate_moduleProviderInheritUnused(t *testing.T) {
|
|||
|
||||
func TestContext2Validate_orphans(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
"num": {Type: cty.String, Optional: true},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
"num": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -562,15 +595,19 @@ func TestContext2Validate_orphans(t *testing.T) {
|
|||
func TestContext2Validate_providerConfig_bad(t *testing.T) {
|
||||
m := testModule(t, "validate-bad-pc")
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
Provider: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
Provider: providers.Schema{
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -598,15 +635,19 @@ func TestContext2Validate_providerConfig_bad(t *testing.T) {
|
|||
func TestContext2Validate_providerConfig_skippedEmpty(t *testing.T) {
|
||||
m := testModule(t, "validate-skipped-pc-empty")
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
Provider: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
Provider: providers.Schema{
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -631,15 +672,19 @@ func TestContext2Validate_providerConfig_skippedEmpty(t *testing.T) {
|
|||
func TestContext2Validate_providerConfig_good(t *testing.T) {
|
||||
m := testModule(t, "validate-bad-pc")
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
Provider: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
Provider: providers.Schema{
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -663,15 +708,19 @@ func TestContext2Validate_requiredProviderConfig(t *testing.T) {
|
|||
m := testModule(t, "validate-required-provider-config")
|
||||
p := testProvider("aws")
|
||||
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
Provider: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"required_attribute": {Type: cty.String, Required: true},
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
Provider: providers.Schema{
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"required_attribute": {Type: cty.String, Required: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -692,11 +741,13 @@ func TestContext2Validate_requiredProviderConfig(t *testing.T) {
|
|||
func TestContext2Validate_provisionerConfig_bad(t *testing.T) {
|
||||
m := testModule(t, "validate-bad-prov-conf")
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -727,11 +778,13 @@ func TestContext2Validate_provisionerConfig_bad(t *testing.T) {
|
|||
func TestContext2Validate_badResourceConnection(t *testing.T) {
|
||||
m := testModule(t, "validate-bad-resource-connection")
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -759,11 +812,13 @@ func TestContext2Validate_badResourceConnection(t *testing.T) {
|
|||
func TestContext2Validate_badProvisionerConnection(t *testing.T) {
|
||||
m := testModule(t, "validate-bad-prov-connection")
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -791,19 +846,23 @@ func TestContext2Validate_badProvisionerConnection(t *testing.T) {
|
|||
func TestContext2Validate_provisionerConfig_good(t *testing.T) {
|
||||
m := testModule(t, "validate-bad-prov-conf")
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
Provider: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
Provider: providers.Schema{
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
pr := simpleMockProvisioner()
|
||||
|
@ -836,16 +895,17 @@ func TestContext2Validate_provisionerConfig_good(t *testing.T) {
|
|||
func TestContext2Validate_requiredVar(t *testing.T) {
|
||||
m := testModule(t, "validate-required-var")
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"ami": {Type: cty.String, Optional: true},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"ami": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
_, diags := NewContext(&ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
|
@ -861,16 +921,17 @@ func TestContext2Validate_requiredVar(t *testing.T) {
|
|||
func TestContext2Validate_resourceConfig_bad(t *testing.T) {
|
||||
m := testModule(t, "validate-bad-rc")
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
|
@ -891,16 +952,17 @@ func TestContext2Validate_resourceConfig_bad(t *testing.T) {
|
|||
func TestContext2Validate_resourceConfig_good(t *testing.T) {
|
||||
m := testModule(t, "validate-bad-rc")
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
|
@ -916,12 +978,14 @@ func TestContext2Validate_resourceConfig_good(t *testing.T) {
|
|||
|
||||
func TestContext2Validate_tainted(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
"num": {Type: cty.String, Optional: true},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
"num": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -962,12 +1026,14 @@ func TestContext2Validate_targetedDestroy(t *testing.T) {
|
|||
pr := simpleMockProvisioner()
|
||||
p.ApplyResourceChangeFn = testApplyFn
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
"num": {Type: cty.String, Optional: true},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
"num": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -1004,11 +1070,13 @@ func TestContext2Validate_targetedDestroy(t *testing.T) {
|
|||
func TestContext2Validate_varRefUnknown(t *testing.T) {
|
||||
m := testModule(t, "validate-variable-ref")
|
||||
p := testProvider("aws")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -1051,11 +1119,13 @@ func TestContext2Validate_interpolateVar(t *testing.T) {
|
|||
p := testProvider("null")
|
||||
p.ApplyResourceChangeFn = testApplyFn
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"template_file": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"template": {Type: cty.String, Optional: true},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"template": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -1084,11 +1154,13 @@ func TestContext2Validate_interpolateComputedModuleVarDef(t *testing.T) {
|
|||
p := testProvider("aws")
|
||||
p.ApplyResourceChangeFn = testApplyFn
|
||||
p.PlanResourceChangeFn = testDiffFn
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"attr": {Type: cty.String, Optional: true},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"attr": {Type: cty.String, Optional: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -1867,11 +1939,13 @@ resource "test_instance" "a" {
|
|||
})
|
||||
|
||||
p := testProvider("test")
|
||||
p.GetSchemaReturn = &ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
p.GetSchemaResponse = &providers.GetSchemaResponse{
|
||||
ResourceTypes: map[string]providers.Schema{
|
||||
"test_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"id": {Type: cty.String, Computed: true},
|
||||
Block: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"id": {Type: cty.String, Computed: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -143,7 +143,7 @@ func TestNodeDestroyDeposedResourceInstanceObject_WriteResourceInstanceState(t *
|
|||
},
|
||||
})
|
||||
ctx.ProviderProvider = mockProvider
|
||||
ctx.ProviderSchemaSchema = mockProvider.GetSchemaReturn
|
||||
ctx.ProviderSchemaSchema = mockProvider.ProviderSchema()
|
||||
|
||||
obj := &states.ResourceInstanceObject{
|
||||
Value: cty.ObjectVal(map[string]cty.Value{
|
||||
|
|
|
@ -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,12 +1,13 @@
|
|||
package terraform
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
ctyjson "github.com/zclconf/go-cty/cty/json"
|
||||
"github.com/zclconf/go-cty/cty/msgpack"
|
||||
|
||||
"github.com/hashicorp/terraform/configs/configschema"
|
||||
"github.com/hashicorp/terraform/configs/hcl2shim"
|
||||
"github.com/hashicorp/terraform/providers"
|
||||
)
|
||||
|
@ -21,8 +22,8 @@ type MockProvider struct {
|
|||
// Anything you want, in case you need to store extra data with the mock.
|
||||
Meta interface{}
|
||||
|
||||
GetSchemaCalled bool
|
||||
GetSchemaReturn *ProviderSchema // This is using ProviderSchema directly rather than providers.GetSchemaResponse for compatibility with old tests
|
||||
GetSchemaCalled bool
|
||||
GetSchemaResponse *providers.GetSchemaResponse
|
||||
|
||||
PrepareProviderConfigCalled bool
|
||||
PrepareProviderConfigResponse *providers.PrepareProviderConfigResponse
|
||||
|
@ -96,47 +97,40 @@ func (p *MockProvider) getSchema() providers.GetSchemaResponse {
|
|||
// This version of getSchema doesn't do any locking, so it's suitable to
|
||||
// call from other methods of this mock as long as they are already
|
||||
// holding the lock.
|
||||
if p.GetSchemaResponse != nil {
|
||||
return *p.GetSchemaResponse
|
||||
}
|
||||
|
||||
ret := providers.GetSchemaResponse{
|
||||
return providers.GetSchemaResponse{
|
||||
Provider: providers.Schema{},
|
||||
DataSources: map[string]providers.Schema{},
|
||||
ResourceTypes: map[string]providers.Schema{},
|
||||
}
|
||||
if p.GetSchemaReturn != nil {
|
||||
ret.Provider.Block = p.GetSchemaReturn.Provider
|
||||
ret.ProviderMeta.Block = p.GetSchemaReturn.ProviderMeta
|
||||
for n, s := range p.GetSchemaReturn.DataSources {
|
||||
ret.DataSources[n] = providers.Schema{
|
||||
Block: s,
|
||||
}
|
||||
}
|
||||
for n, s := range p.GetSchemaReturn.ResourceTypes {
|
||||
ret.ResourceTypes[n] = providers.Schema{
|
||||
Version: int64(p.GetSchemaReturn.ResourceTypeSchemaVersions[n]),
|
||||
Block: s,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (p *MockProvider) getResourceSchema(name string) providers.Schema {
|
||||
schema := p.getSchema()
|
||||
resSchema, ok := schema.ResourceTypes[name]
|
||||
if !ok {
|
||||
panic("unknown resource type " + name)
|
||||
}
|
||||
return resSchema
|
||||
}
|
||||
// ProviderSchema is a helper to convert from the internal GetSchemaResponse to
|
||||
// a ProviderSchema.
|
||||
func (p *MockProvider) ProviderSchema() *ProviderSchema {
|
||||
resp := p.getSchema()
|
||||
|
||||
func (p *MockProvider) getDatasourceSchema(name string) providers.Schema {
|
||||
schema := p.getSchema()
|
||||
dataSchema, ok := schema.DataSources[name]
|
||||
if !ok {
|
||||
panic("unknown data source " + name)
|
||||
schema := &ProviderSchema{
|
||||
Provider: resp.Provider.Block,
|
||||
ProviderMeta: resp.ProviderMeta.Block,
|
||||
ResourceTypes: map[string]*configschema.Block{},
|
||||
DataSources: map[string]*configschema.Block{},
|
||||
ResourceTypeSchemaVersions: map[string]uint64{},
|
||||
}
|
||||
return dataSchema
|
||||
|
||||
for resType, s := range resp.ResourceTypes {
|
||||
schema.ResourceTypes[resType] = s.Block
|
||||
schema.ResourceTypeSchemaVersions[resType] = uint64(s.Version)
|
||||
}
|
||||
|
||||
for dataSource, s := range resp.DataSources {
|
||||
schema.DataSources[dataSource] = s.Block
|
||||
}
|
||||
|
||||
return schema
|
||||
}
|
||||
|
||||
func (p *MockProvider) PrepareProviderConfig(r providers.PrepareProviderConfigRequest) (resp providers.PrepareProviderConfigResponse) {
|
||||
|
@ -166,7 +160,12 @@ func (p *MockProvider) ValidateResourceTypeConfig(r providers.ValidateResourceTy
|
|||
|
||||
// Marshall the value to replicate behavior by the GRPC protocol,
|
||||
// and return any relevant errors
|
||||
resourceSchema := p.getResourceSchema(r.TypeName)
|
||||
resourceSchema, ok := p.getSchema().ResourceTypes[r.TypeName]
|
||||
if !ok {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("no schema found for %q", r.TypeName))
|
||||
return resp
|
||||
}
|
||||
|
||||
_, err := msgpack.Marshal(r.Config, resourceSchema.Block.ImpliedType())
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
|
@ -192,7 +191,11 @@ func (p *MockProvider) ValidateDataSourceConfig(r providers.ValidateDataSourceCo
|
|||
p.ValidateDataSourceConfigRequest = r
|
||||
|
||||
// Marshall the value to replicate behavior by the GRPC protocol
|
||||
dataSchema := p.getDatasourceSchema(r.TypeName)
|
||||
dataSchema, ok := p.getSchema().DataSources[r.TypeName]
|
||||
if !ok {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("no schema found for %q", r.TypeName))
|
||||
return resp
|
||||
}
|
||||
_, err := msgpack.Marshal(r.Config, dataSchema.Block.ImpliedType())
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
|
@ -214,8 +217,12 @@ func (p *MockProvider) UpgradeResourceState(r providers.UpgradeResourceStateRequ
|
|||
p.Lock()
|
||||
defer p.Unlock()
|
||||
|
||||
schemas := p.getSchema()
|
||||
schema := schemas.ResourceTypes[r.TypeName]
|
||||
schema, ok := p.getSchema().ResourceTypes[r.TypeName]
|
||||
if !ok {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("no schema found for %q", r.TypeName))
|
||||
return resp
|
||||
}
|
||||
|
||||
schemaType := schema.Block.ImpliedType()
|
||||
|
||||
p.UpgradeResourceStateCalled = true
|
||||
|
@ -298,7 +305,13 @@ func (p *MockProvider) ReadResource(r providers.ReadResourceRequest) (resp provi
|
|||
|
||||
// Make sure the NewState conforms to the schema.
|
||||
// This isn't always the case for the existing tests.
|
||||
newState, err := p.GetSchemaReturn.ResourceTypes[r.TypeName].CoerceValue(resp.NewState)
|
||||
schema, ok := p.getSchema().ResourceTypes[r.TypeName]
|
||||
if !ok {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("no schema found for %q", r.TypeName))
|
||||
return resp
|
||||
}
|
||||
|
||||
newState, err := schema.Block.CoerceValue(resp.NewState)
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
}
|
||||
|
@ -326,6 +339,12 @@ func (p *MockProvider) PlanResourceChange(r providers.PlanResourceChangeRequest)
|
|||
return *p.PlanResourceChangeResponse
|
||||
}
|
||||
|
||||
schema, ok := p.getSchema().ResourceTypes[r.TypeName]
|
||||
if !ok {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("no schema found for %q", r.TypeName))
|
||||
return resp
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
|
@ -342,6 +361,7 @@ func (p *MockProvider) ApplyResourceChange(r providers.ApplyResourceChangeReques
|
|||
if p.ApplyResourceChangeResponse != nil {
|
||||
return *p.ApplyResourceChangeResponse
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
|
@ -359,14 +379,14 @@ func (p *MockProvider) ImportResourceState(r providers.ImportResourceStateReques
|
|||
resp = *p.ImportResourceStateResponse
|
||||
// fixup the cty value to match the schema
|
||||
for i, res := range resp.ImportedResources {
|
||||
schema := p.GetSchemaReturn.ResourceTypes[res.TypeName]
|
||||
if schema == nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(errors.New("no schema found for " + res.TypeName))
|
||||
schema, ok := p.getSchema().ResourceTypes[res.TypeName]
|
||||
if !ok {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("no schema found for %q", res.TypeName))
|
||||
return resp
|
||||
}
|
||||
|
||||
var err error
|
||||
res.State, err = schema.CoerceValue(res.State)
|
||||
res.State, err = schema.Block.CoerceValue(res.State)
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
return resp
|
||||
|
@ -393,6 +413,7 @@ func (p *MockProvider) ReadDataSource(r providers.ReadDataSourceRequest) (resp p
|
|||
if p.ReadDataSourceResponse != nil {
|
||||
resp = *p.ReadDataSourceResponse
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue