diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 477beb3ae..382664688 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -4771,6 +4771,61 @@ func TestContext2Apply_provisionerDestroyRef(t *testing.T) { } } +// Test that a destroy provisioner referencing an invalid key errors. +func TestContext2Apply_provisionerDestroyRefInvalid(t *testing.T) { + m := testModule(t, "apply-provisioner-destroy-ref") + p := testProvider("aws") + pr := testProvisioner() + p.ApplyFn = testApplyFn + p.DiffFn = testDiffFn + pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error { + return nil + } + + state := &State{ + Modules: []*ModuleState{ + &ModuleState{ + Path: rootModulePath, + Resources: map[string]*ResourceState{ + "aws_instance.bar": &ResourceState{ + Type: "aws_instance", + Primary: &InstanceState{ + ID: "bar", + }, + }, + + "aws_instance.foo": &ResourceState{ + Type: "aws_instance", + Primary: &InstanceState{ + ID: "bar", + }, + }, + }, + }, + }, + } + + ctx := testContext2(t, &ContextOpts{ + Module: m, + State: state, + Destroy: true, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + Provisioners: map[string]ResourceProvisionerFactory{ + "shell": testProvisionerFuncFixed(pr), + }, + }) + + if _, err := ctx.Plan(); err != nil { + t.Fatalf("err: %s", err) + } + + if _, err := ctx.Apply(); err == nil { + t.Fatal("expected error") + } +} + func TestContext2Apply_provisionerResourceRef(t *testing.T) { m := testModule(t, "apply-provisioner-resource-ref") p := testProvider("aws") diff --git a/terraform/interpolate.go b/terraform/interpolate.go index 4cbfab78e..a59af6e83 100644 --- a/terraform/interpolate.go +++ b/terraform/interpolate.go @@ -498,7 +498,7 @@ MISSING: // // For an input walk, computed values are okay to return because we're only // looking for missing variables to prompt the user for. - if i.Operation == walkRefresh || i.Operation == walkPlanDestroy || i.Operation == walkDestroy || i.Operation == walkInput { + if i.Operation == walkRefresh || i.Operation == walkPlanDestroy || i.Operation == walkInput { return &unknownVariable, nil }