core: Add mock schemas to the refresh context tests
There are still some other issues with some of these tests right now, but all the ones that need to have schema should now have it. It seems that there is a bug with the evaluation of child module input variables where they can't find their schema even when a mock is provided. Will attack this in a subsequent commit.
This commit is contained in:
parent
8b6ef7c8d3
commit
ea727d9918
|
@ -8,7 +8,10 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/zclconf/go-cty/cty"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/addrs"
|
"github.com/hashicorp/terraform/addrs"
|
||||||
|
"github.com/hashicorp/terraform/config/configschema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestContext2Refresh(t *testing.T) {
|
func TestContext2Refresh(t *testing.T) {
|
||||||
|
@ -82,6 +85,34 @@ func TestContext2Refresh_dataComputedModuleVar(t *testing.T) {
|
||||||
ID: "foo",
|
ID: "foo",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.GetSchemaReturn = &ProviderSchema{
|
||||||
|
Provider: &configschema.Block{},
|
||||||
|
ResourceTypes: map[string]*configschema.Block{
|
||||||
|
"aws_instance": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"foo": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
DataSources: map[string]*configschema.Block{
|
||||||
|
"aws_data_source": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
s, err := ctx.Refresh()
|
s, err := ctx.Refresh()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
|
@ -95,6 +126,40 @@ module.child:
|
||||||
|
|
||||||
func TestContext2Refresh_targeted(t *testing.T) {
|
func TestContext2Refresh_targeted(t *testing.T) {
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
|
p.GetSchemaReturn = &ProviderSchema{
|
||||||
|
Provider: &configschema.Block{},
|
||||||
|
ResourceTypes: map[string]*configschema.Block{
|
||||||
|
"aws_elb": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"instances": {
|
||||||
|
Type: cty.Set(cty.String),
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"aws_instance": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"vpc_id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"aws_vpc": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
m := testModule(t, "refresh-targeted")
|
m := testModule(t, "refresh-targeted")
|
||||||
ctx := testContext2(t, &ContextOpts{
|
ctx := testContext2(t, &ContextOpts{
|
||||||
Config: m,
|
Config: m,
|
||||||
|
@ -142,6 +207,40 @@ func TestContext2Refresh_targeted(t *testing.T) {
|
||||||
|
|
||||||
func TestContext2Refresh_targetedCount(t *testing.T) {
|
func TestContext2Refresh_targetedCount(t *testing.T) {
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
|
p.GetSchemaReturn = &ProviderSchema{
|
||||||
|
Provider: &configschema.Block{},
|
||||||
|
ResourceTypes: map[string]*configschema.Block{
|
||||||
|
"aws_elb": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"instances": {
|
||||||
|
Type: cty.Set(cty.String),
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"aws_instance": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"vpc_id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"aws_vpc": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
m := testModule(t, "refresh-targeted-count")
|
m := testModule(t, "refresh-targeted-count")
|
||||||
ctx := testContext2(t, &ContextOpts{
|
ctx := testContext2(t, &ContextOpts{
|
||||||
Config: m,
|
Config: m,
|
||||||
|
@ -199,6 +298,40 @@ func TestContext2Refresh_targetedCount(t *testing.T) {
|
||||||
|
|
||||||
func TestContext2Refresh_targetedCountIndex(t *testing.T) {
|
func TestContext2Refresh_targetedCountIndex(t *testing.T) {
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
|
p.GetSchemaReturn = &ProviderSchema{
|
||||||
|
Provider: &configschema.Block{},
|
||||||
|
ResourceTypes: map[string]*configschema.Block{
|
||||||
|
"aws_elb": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"instances": {
|
||||||
|
Type: cty.Set(cty.String),
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"aws_instance": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"vpc_id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"aws_vpc": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
m := testModule(t, "refresh-targeted-count")
|
m := testModule(t, "refresh-targeted-count")
|
||||||
ctx := testContext2(t, &ContextOpts{
|
ctx := testContext2(t, &ContextOpts{
|
||||||
Config: m,
|
Config: m,
|
||||||
|
@ -248,6 +381,24 @@ func TestContext2Refresh_targetedCountIndex(t *testing.T) {
|
||||||
|
|
||||||
func TestContext2Refresh_moduleComputedVar(t *testing.T) {
|
func TestContext2Refresh_moduleComputedVar(t *testing.T) {
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
|
p.GetSchemaReturn = &ProviderSchema{
|
||||||
|
Provider: &configschema.Block{},
|
||||||
|
ResourceTypes: map[string]*configschema.Block{
|
||||||
|
"aws_instance": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"value": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
m := testModule(t, "refresh-module-computed-var")
|
m := testModule(t, "refresh-module-computed-var")
|
||||||
ctx := testContext2(t, &ContextOpts{
|
ctx := testContext2(t, &ContextOpts{
|
||||||
Config: m,
|
Config: m,
|
||||||
|
@ -439,6 +590,24 @@ func TestContext2Refresh_moduleInputComputedOutput(t *testing.T) {
|
||||||
m := testModule(t, "refresh-module-input-computed-output")
|
m := testModule(t, "refresh-module-input-computed-output")
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
p.DiffFn = testDiffFn
|
p.DiffFn = testDiffFn
|
||||||
|
p.GetSchemaReturn = &ProviderSchema{
|
||||||
|
Provider: &configschema.Block{},
|
||||||
|
ResourceTypes: map[string]*configschema.Block{
|
||||||
|
"aws_instance": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"foo": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"compute": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
ctx := testContext2(t, &ContextOpts{
|
ctx := testContext2(t, &ContextOpts{
|
||||||
Config: m,
|
Config: m,
|
||||||
ProviderResolver: ResourceProviderResolverFixed(
|
ProviderResolver: ResourceProviderResolverFixed(
|
||||||
|
@ -496,6 +665,20 @@ func TestContext2Refresh_noState(t *testing.T) {
|
||||||
|
|
||||||
func TestContext2Refresh_output(t *testing.T) {
|
func TestContext2Refresh_output(t *testing.T) {
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
|
p.GetSchemaReturn = &ProviderSchema{
|
||||||
|
Provider: &configschema.Block{},
|
||||||
|
ResourceTypes: map[string]*configschema.Block{
|
||||||
|
"aws_instance": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"foo": {
|
||||||
|
Type: cty.String,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
m := testModule(t, "refresh-output")
|
m := testModule(t, "refresh-output")
|
||||||
ctx := testContext2(t, &ContextOpts{
|
ctx := testContext2(t, &ContextOpts{
|
||||||
Config: m,
|
Config: m,
|
||||||
|
@ -579,6 +762,20 @@ func TestContext2Refresh_outputPartial(t *testing.T) {
|
||||||
p.RefreshFn = nil
|
p.RefreshFn = nil
|
||||||
p.RefreshReturn = nil
|
p.RefreshReturn = nil
|
||||||
|
|
||||||
|
p.GetSchemaReturn = &ProviderSchema{
|
||||||
|
Provider: &configschema.Block{},
|
||||||
|
ResourceTypes: map[string]*configschema.Block{
|
||||||
|
"aws_instance": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"foo": {
|
||||||
|
Type: cty.String,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
s, err := ctx.Refresh()
|
s, err := ctx.Refresh()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
|
@ -702,6 +899,20 @@ func TestContext2Refresh_dataState(t *testing.T) {
|
||||||
State: state,
|
State: state,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
p.GetSchemaReturn = &ProviderSchema{
|
||||||
|
Provider: &configschema.Block{},
|
||||||
|
DataSources: map[string]*configschema.Block{
|
||||||
|
"null_data_source": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"inputs": {
|
||||||
|
Type: cty.Map(cty.String),
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
p.ReadDataDiffFn = nil
|
p.ReadDataDiffFn = nil
|
||||||
p.ReadDataDiffReturn = &InstanceDiff{
|
p.ReadDataDiffReturn = &InstanceDiff{
|
||||||
Attributes: map[string]*ResourceAttrDiff{
|
Attributes: map[string]*ResourceAttrDiff{
|
||||||
|
@ -752,6 +963,24 @@ func TestContext2Refresh_dataState(t *testing.T) {
|
||||||
|
|
||||||
func TestContext2Refresh_dataStateRefData(t *testing.T) {
|
func TestContext2Refresh_dataStateRefData(t *testing.T) {
|
||||||
p := testProvider("null")
|
p := testProvider("null")
|
||||||
|
p.GetSchemaReturn = &ProviderSchema{
|
||||||
|
Provider: &configschema.Block{},
|
||||||
|
DataSources: map[string]*configschema.Block{
|
||||||
|
"null_data_source": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"foo": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"bar": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
m := testModule(t, "refresh-data-ref-data")
|
m := testModule(t, "refresh-data-ref-data")
|
||||||
state := &State{
|
state := &State{
|
||||||
Modules: []*ModuleState{
|
Modules: []*ModuleState{
|
||||||
|
@ -883,6 +1112,24 @@ func TestContext2Refresh_unknownProvider(t *testing.T) {
|
||||||
|
|
||||||
func TestContext2Refresh_vars(t *testing.T) {
|
func TestContext2Refresh_vars(t *testing.T) {
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
|
p.GetSchemaReturn = &ProviderSchema{
|
||||||
|
Provider: &configschema.Block{},
|
||||||
|
ResourceTypes: map[string]*configschema.Block{
|
||||||
|
"aws_instance": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"ami": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
Type: cty.String,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
m := testModule(t, "refresh-vars")
|
m := testModule(t, "refresh-vars")
|
||||||
ctx := testContext2(t, &ContextOpts{
|
ctx := testContext2(t, &ContextOpts{
|
||||||
Config: m,
|
Config: m,
|
||||||
|
@ -952,6 +1199,12 @@ func TestContext2Refresh_orphanModule(t *testing.T) {
|
||||||
order = append(order, is.ID)
|
order = append(order, is.ID)
|
||||||
return is, nil
|
return is, nil
|
||||||
}
|
}
|
||||||
|
p.GetSchemaReturn = &ProviderSchema{
|
||||||
|
Provider: &configschema.Block{},
|
||||||
|
ResourceTypes: map[string]*configschema.Block{
|
||||||
|
"aws_instance": {},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
state := &State{
|
state := &State{
|
||||||
Modules: []*ModuleState{
|
Modules: []*ModuleState{
|
||||||
|
@ -1046,6 +1299,24 @@ func TestContext2Refresh_orphanModule(t *testing.T) {
|
||||||
|
|
||||||
func TestContext2Validate(t *testing.T) {
|
func TestContext2Validate(t *testing.T) {
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
|
p.GetSchemaReturn = &ProviderSchema{
|
||||||
|
Provider: &configschema.Block{},
|
||||||
|
ResourceTypes: map[string]*configschema.Block{
|
||||||
|
"aws_instance": {
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"foo": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
"num": {
|
||||||
|
Type: cty.String,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
m := testModule(t, "validate-good")
|
m := testModule(t, "validate-good")
|
||||||
c := testContext2(t, &ContextOpts{
|
c := testContext2(t, &ContextOpts{
|
||||||
Config: m,
|
Config: m,
|
||||||
|
@ -1072,6 +1343,12 @@ func TestContext2Refresh_noDiffHookOnScaleOut(t *testing.T) {
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
m := testModule(t, "refresh-resource-scale-inout")
|
m := testModule(t, "refresh-resource-scale-inout")
|
||||||
p.RefreshFn = nil
|
p.RefreshFn = nil
|
||||||
|
p.GetSchemaReturn = &ProviderSchema{
|
||||||
|
Provider: &configschema.Block{},
|
||||||
|
ResourceTypes: map[string]*configschema.Block{
|
||||||
|
"aws_instance": {},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
state := &State{
|
state := &State{
|
||||||
Modules: []*ModuleState{
|
Modules: []*ModuleState{
|
||||||
|
@ -1125,9 +1402,14 @@ func TestContext2Refresh_noDiffHookOnScaleOut(t *testing.T) {
|
||||||
func TestContext2Refresh_updateProviderInState(t *testing.T) {
|
func TestContext2Refresh_updateProviderInState(t *testing.T) {
|
||||||
m := testModule(t, "update-resource-provider")
|
m := testModule(t, "update-resource-provider")
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
|
|
||||||
p.DiffFn = testDiffFn
|
p.DiffFn = testDiffFn
|
||||||
p.ApplyFn = testApplyFn
|
p.ApplyFn = testApplyFn
|
||||||
|
p.GetSchemaReturn = &ProviderSchema{
|
||||||
|
Provider: &configschema.Block{},
|
||||||
|
ResourceTypes: map[string]*configschema.Block{
|
||||||
|
"aws_instance": {},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
s := &State{
|
s := &State{
|
||||||
Modules: []*ModuleState{
|
Modules: []*ModuleState{
|
||||||
|
@ -1161,9 +1443,9 @@ aws_instance.bar:
|
||||||
ID = foo
|
ID = foo
|
||||||
provider = provider.aws.foo`)
|
provider = provider.aws.foo`)
|
||||||
|
|
||||||
state, err := ctx.Refresh()
|
state, diags := ctx.Refresh()
|
||||||
if err != nil {
|
if diags.HasErrors() {
|
||||||
t.Fatal(err)
|
t.Fatal(diags.Err())
|
||||||
}
|
}
|
||||||
|
|
||||||
actual := state.String()
|
actual := state.String()
|
||||||
|
|
|
@ -3,6 +3,6 @@ resource "aws_instance" "A" {
|
||||||
}
|
}
|
||||||
|
|
||||||
module "child" {
|
module "child" {
|
||||||
source = "child"
|
source = "./child"
|
||||||
key = "${aws_instance.A.id}"
|
key = "${aws_instance.A.id}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
variable "input" {}
|
variable "input" {
|
||||||
|
type = list(string)
|
||||||
|
}
|
||||||
|
|
||||||
resource "aws_instance" "foo" {
|
resource "aws_instance" "foo" {
|
||||||
foo = "${var.input}"
|
foo = "${var.input}"
|
||||||
|
|
Loading…
Reference in New Issue