From 33cad6d2073170752b1834e1f7ef4c59ff62180b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 13 Feb 2015 16:05:44 -0800 Subject: [PATCH] terraform: fix create before destroy edge case with partial state --- terraform/context_test.go | 8 ++++---- terraform/eval_state.go | 2 ++ terraform/transform_resource.go | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/terraform/context_test.go b/terraform/context_test.go index e880bb499..ccd304eb9 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -3424,8 +3424,7 @@ func TestContext2Apply_provisionerFail_createBeforeDestroy(t *testing.T) { } } -/* -func TestContextApply_error_createBeforeDestroy(t *testing.T) { +func TestContext2Apply_error_createBeforeDestroy(t *testing.T) { m := testModule(t, "apply-error-create-before") p := testProvider("aws") state := &State{ @@ -3446,7 +3445,7 @@ func TestContextApply_error_createBeforeDestroy(t *testing.T) { }, }, } - ctx := testContext(t, &ContextOpts{ + ctx := testContext2(t, &ContextOpts{ Module: m, Providers: map[string]ResourceProviderFactory{ "aws": testProviderFuncFixed(p), @@ -3470,10 +3469,11 @@ func TestContextApply_error_createBeforeDestroy(t *testing.T) { actual := strings.TrimSpace(state.String()) expected := strings.TrimSpace(testTerraformApplyErrorCreateBeforeDestroyStr) if actual != expected { - t.Fatalf("bad: \n%s\n\n\n%s", actual, expected) + t.Fatalf("bad: \n%s\n\nExpected:\n\n%s", actual, expected) } } +/* func TestContextApply_errorDestroy_createBeforeDestroy(t *testing.T) { m := testModule(t, "apply-error-create-before") p := testProvider("aws") diff --git a/terraform/eval_state.go b/terraform/eval_state.go index 93225e2f9..cf315dade 100644 --- a/terraform/eval_state.go +++ b/terraform/eval_state.go @@ -103,6 +103,8 @@ func (n *EvalWriteState) Eval( rs.Type = n.ResourceType rs.Dependencies = n.Dependencies + println(fmt.Sprintf("%#v", rs)) + println(fmt.Sprintf("%#v", *n.State)) if n.Tainted != nil && *n.Tainted { if n.TaintedIndex != -1 { rs.Tainted[n.TaintedIndex] = *n.State diff --git a/terraform/transform_resource.go b/terraform/transform_resource.go index 940a53fa1..dfa06b913 100644 --- a/terraform/transform_resource.go +++ b/terraform/transform_resource.go @@ -315,8 +315,9 @@ func (n *graphNodeExpandedResource) EvalTree() EvalNode { }, &EvalIf{ If: func(ctx EvalContext) (bool, error) { - return n.Resource.Lifecycle.CreateBeforeDestroy && - tainted, nil + failure := tainted || err != nil + tainted = n.Resource.Lifecycle.CreateBeforeDestroy + return n.Resource.Lifecycle.CreateBeforeDestroy && failure, nil }, Node: &EvalUndeposeState{ Name: n.stateId(),