Merge pull request #1069 from hashicorp/b-tainted-double-destroy
core: band-aid fix for tainted double destroy
This commit is contained in:
commit
06d1a242d2
|
@ -8,7 +8,9 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestContext2Plan(t *testing.T) {
|
func TestContext2Plan(t *testing.T) {
|
||||||
|
@ -4646,7 +4648,22 @@ func TestContext2Apply_outputMultiIndex(t *testing.T) {
|
||||||
func TestContext2Apply_taint(t *testing.T) {
|
func TestContext2Apply_taint(t *testing.T) {
|
||||||
m := testModule(t, "apply-taint")
|
m := testModule(t, "apply-taint")
|
||||||
p := testProvider("aws")
|
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
|
p.DiffFn = testDiffFn
|
||||||
s := &State{
|
s := &State{
|
||||||
Modules: []*ModuleState{
|
Modules: []*ModuleState{
|
||||||
|
@ -4691,6 +4708,10 @@ func TestContext2Apply_taint(t *testing.T) {
|
||||||
if actual != expected {
|
if actual != expected {
|
||||||
t.Fatalf("bad:\n%s", actual)
|
t.Fatalf("bad:\n%s", actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if destroyCount != 1 {
|
||||||
|
t.Fatalf("Expected 1 destroy, got %d", destroyCount)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContext2Apply_unknownAttribute(t *testing.T) {
|
func TestContext2Apply_unknownAttribute(t *testing.T) {
|
||||||
|
|
|
@ -293,6 +293,7 @@ func (n *GraphNodeConfigResource) DynamicExpand(ctx EvalContext) (*Graph, error)
|
||||||
View: n.Resource.Id(),
|
View: n.Resource.Id(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if n.Resource.Lifecycle.CreateBeforeDestroy {
|
||||||
// If we're only destroying tainted resources, then we only
|
// If we're only destroying tainted resources, then we only
|
||||||
// want to find tainted resources and destroy them here.
|
// want to find tainted resources and destroy them here.
|
||||||
steps = append(steps, &TaintedTransformer{
|
steps = append(steps, &TaintedTransformer{
|
||||||
|
@ -301,6 +302,7 @@ func (n *GraphNodeConfigResource) DynamicExpand(ctx EvalContext) (*Graph, error)
|
||||||
Deposed: n.Resource.Lifecycle.CreateBeforeDestroy,
|
Deposed: n.Resource.Lifecycle.CreateBeforeDestroy,
|
||||||
DeposedInclude: true,
|
DeposedInclude: true,
|
||||||
})
|
})
|
||||||
|
}
|
||||||
case DestroyTainted:
|
case DestroyTainted:
|
||||||
// If we're only destroying tainted resources, then we only
|
// If we're only destroying tainted resources, then we only
|
||||||
// want to find tainted resources and destroy them here.
|
// want to find tainted resources and destroy them here.
|
||||||
|
|
Loading…
Reference in New Issue