From f6ab0bc5c499d82cdfbec367f22bc3d27b6f1c06 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 17 Feb 2017 14:32:32 -0800 Subject: [PATCH] terraform: interpolation failures on a destroy provisioner should error --- terraform/context_apply_test.go | 55 +++++++++++++++++++++++++++++++++ terraform/interpolate.go | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) 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 }