diff --git a/terraform/context_test.go b/terraform/context_test.go index 5ee9a8c71..ceb34688e 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -8,7 +8,9 @@ import ( "sort" "strings" "sync" + "sync/atomic" "testing" + "time" ) func TestContext2Plan(t *testing.T) { @@ -4646,7 +4648,22 @@ func TestContext2Apply_outputMultiIndex(t *testing.T) { func TestContext2Apply_taint(t *testing.T) { m := testModule(t, "apply-taint") p := testProvider("aws") - p.ApplyFn = testApplyFn + + // destroyCount tests against regression of + // https://github.com/hashicorp/terraform/issues/1056 + var destroyCount = int32(0) + var once sync.Once + simulateProviderDelay := func() { + time.Sleep(10 * time.Millisecond) + } + + p.ApplyFn = func(info *InstanceInfo, s *InstanceState, d *InstanceDiff) (*InstanceState, error) { + once.Do(simulateProviderDelay) + if d.Destroy { + atomic.AddInt32(&destroyCount, 1) + } + return testApplyFn(info, s, d) + } p.DiffFn = testDiffFn s := &State{ Modules: []*ModuleState{ @@ -4691,6 +4708,10 @@ func TestContext2Apply_taint(t *testing.T) { if actual != expected { t.Fatalf("bad:\n%s", actual) } + + if destroyCount != 1 { + t.Fatalf("Expected 1 destroy, got %d", destroyCount) + } } func TestContext2Apply_unknownAttribute(t *testing.T) { diff --git a/terraform/graph_config_node.go b/terraform/graph_config_node.go index 30a614146..baa862b2d 100644 --- a/terraform/graph_config_node.go +++ b/terraform/graph_config_node.go @@ -293,14 +293,16 @@ func (n *GraphNodeConfigResource) DynamicExpand(ctx EvalContext) (*Graph, error) View: n.Resource.Id(), }) - // If we're only destroying tainted resources, then we only - // want to find tainted resources and destroy them here. - steps = append(steps, &TaintedTransformer{ - State: state, - View: n.Resource.Id(), - Deposed: n.Resource.Lifecycle.CreateBeforeDestroy, - DeposedInclude: true, - }) + if n.Resource.Lifecycle.CreateBeforeDestroy { + // If we're only destroying tainted resources, then we only + // want to find tainted resources and destroy them here. + steps = append(steps, &TaintedTransformer{ + State: state, + View: n.Resource.Id(), + Deposed: n.Resource.Lifecycle.CreateBeforeDestroy, + DeposedInclude: true, + }) + } case DestroyTainted: // If we're only destroying tainted resources, then we only // want to find tainted resources and destroy them here.