Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore errors interpolating RawCount during apply #17548

Merged
merged 2 commits into from
Mar 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions terraform/context_apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
10 changes: 8 additions & 2 deletions terraform/node_resource_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ func (n *NodeApplyableResource) evalTreeDataResource(
// Here we are just populating the interpolated value in-place
// inside this RawConfig object, like we would in
// NodeAbstractCountResource.
&EvalInterpolate{Config: n.Config.RawCount},
&EvalInterpolate{
Config: n.Config.RawCount,
ContinueOnErr: true,
},

// We need to re-interpolate the config here, rather than
// just using the diff's values directly, because we've
Expand Down Expand Up @@ -271,7 +274,10 @@ func (n *NodeApplyableResource) evalTreeManagedResource(
// Here we are just populating the interpolated value in-place
// inside this RawConfig object, like we would in
// NodeAbstractCountResource.
&EvalInterpolate{Config: n.Config.RawCount},
&EvalInterpolate{
Config: n.Config.RawCount,
ContinueOnErr: true,
},

&EvalInterpolate{
Config: n.Config.RawConfig.Copy(),
Expand Down
11 changes: 11 additions & 0 deletions terraform/test-fixtures/apply-interpolated-count/main.tf
Original file line number Diff line number Diff line change
@@ -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}"
}