From 119d5a09cfdbbb337ffea2b5b7c27de4e3797a8c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 13 Feb 2015 14:03:17 -0800 Subject: [PATCH] terraform: fix some diff comparison --- terraform/context_test.go | 7 +++---- terraform/eval_diff.go | 12 ++++++++++++ terraform/transform_resource.go | 3 ++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/terraform/context_test.go b/terraform/context_test.go index 8ad8eb5d6..6c308cf0c 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -2735,7 +2735,6 @@ func TestContext2Apply_emptyModule(t *testing.T) { } } -/* func TestContext2Apply_createBeforeDestroy(t *testing.T) { m := testModule(t, "apply-good-create-before") p := testProvider("aws") @@ -2789,7 +2788,6 @@ func TestContext2Apply_createBeforeDestroy(t *testing.T) { t.Fatalf("bad: \n%s", actual) } } -*/ func TestContext2Apply_minimal(t *testing.T) { m := testModule(t, "apply-minimal") @@ -3372,7 +3370,7 @@ func TestContext2Apply_provisionerFail(t *testing.T) { } /* -func TestContextApply_provisionerFail_createBeforeDestroy(t *testing.T) { +func TestContext2Apply_provisionerFail_createBeforeDestroy(t *testing.T) { m := testModule(t, "apply-provisioner-fail-create-before") p := testProvider("aws") pr := testProvisioner() @@ -3400,7 +3398,7 @@ func TestContextApply_provisionerFail_createBeforeDestroy(t *testing.T) { }, }, } - ctx := testContext(t, &ContextOpts{ + ctx := testContext2(t, &ContextOpts{ Module: m, Providers: map[string]ResourceProviderFactory{ "aws": testProviderFuncFixed(p), @@ -3427,6 +3425,7 @@ func TestContextApply_provisionerFail_createBeforeDestroy(t *testing.T) { } } +/* func TestContextApply_error_createBeforeDestroy(t *testing.T) { m := testModule(t, "apply-error-create-before") p := testProvider("aws") diff --git a/terraform/eval_diff.go b/terraform/eval_diff.go index 4fab4c2d8..0bf3baa73 100644 --- a/terraform/eval_diff.go +++ b/terraform/eval_diff.go @@ -30,6 +30,18 @@ func (n *EvalCompareDiff) Eval( two = new(InstanceDiff) two.init() } + oneId := one.Attributes["id"] + twoId := two.Attributes["id"] + delete(one.Attributes, "id") + delete(two.Attributes, "id") + defer func() { + if oneId != nil { + one.Attributes["id"] = oneId + } + if twoId != nil { + two.Attributes["id"] = twoId + } + }() if !one.Same(two) { log.Printf("[ERROR] %s: diff's didn't match", n.Info.Id) diff --git a/terraform/transform_resource.go b/terraform/transform_resource.go index ea5090295..1a183b9dc 100644 --- a/terraform/transform_resource.go +++ b/terraform/transform_resource.go @@ -241,10 +241,11 @@ func (n *graphNodeExpandedResource) EvalTree() EvalNode { return true, EvalEarlyExitError{} } - if diffApply.Destroy { + if diffApply.Destroy && len(diffApply.Attributes) == 0 { return true, EvalEarlyExitError{} } + diffApply.Destroy = false return true, nil }, Node: EvalNoop{},