failing test for interpolated count from plan

An interpolated count value that is determined during plan, is lost
during plan serialization, causing apply to fail when the interpolation
string can't be evaluated.
This commit is contained in:
James Bardin 2018-03-09 18:38:41 -05:00
parent bb8f859113
commit f3d1fb3aff
2 changed files with 79 additions and 1 deletions

View File

@ -9472,5 +9472,72 @@ func TestContext2Apply_providersFromState(t *testing.T) {
})
}
}
func TestContext2Apply_plannedInterpolatedCount(t *testing.T) {
m := testModule(t, "apply-interpolated-count")
p := testProvider("aws")
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
providerResolver := ResourceProviderResolverFixed(
map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
)
s := &State{
Modules: []*ModuleState{
&ModuleState{
Path: rootModulePath,
Resources: map[string]*ResourceState{
"aws_instance.test": {
Type: "aws_instance",
Primary: &InstanceState{
ID: "foo",
},
Provider: "provider.aws",
},
},
},
},
}
ctx := testContext2(t, &ContextOpts{
Module: m,
ProviderResolver: providerResolver,
State: s,
})
plan, err := ctx.Plan()
if err != nil {
t.Fatalf("plan failed: %s", err)
}
// We'll marshal and unmarshal the plan here, to ensure that we have
// a clean new context as would be created if we separately ran
// terraform plan -out=tfplan && terraform apply tfplan
var planBuf bytes.Buffer
err = WritePlan(plan, &planBuf)
if err != nil {
t.Fatalf("failed to write plan: %s", err)
}
plan, err = ReadPlan(&planBuf)
if err != nil {
t.Fatalf("failed to read plan: %s", err)
}
ctx, err = plan.Context(&ContextOpts{
ProviderResolver: providerResolver,
})
if err != nil {
t.Fatalf("failed to create context for plan: %s", err)
}
// Applying the plan should now succeed
_, err = ctx.Apply()
if err != nil {
t.Fatalf("apply failed: %s", err)
}
}

View File

@ -0,0 +1,11 @@
variable "instance_count" {
default = 1
}
resource "aws_instance" "test" {
count = "${var.instance_count}"
}
resource "aws_instance" "dependent" {
count = "${aws_instance.test.count}"
}