terraform: fix create before destroy edge case with partial state

This commit is contained in:
Mitchell Hashimoto 2015-02-13 16:05:44 -08:00
parent f7f1f17b49
commit 33cad6d207
3 changed files with 9 additions and 6 deletions

View File

@ -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")

View File

@ -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

View File

@ -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(),