terraform: apply for orphans

This commit is contained in:
Mitchell Hashimoto 2015-02-12 20:03:44 -08:00
parent abc68a89a8
commit 691db58478
3 changed files with 52 additions and 3 deletions

View File

@ -2948,8 +2948,7 @@ func TestContext2Apply_compute(t *testing.T) {
}
}
/*
func TestContextApply_countDecrease(t *testing.T) {
func TestContext2Apply_countDecrease(t *testing.T) {
m := testModule(t, "apply-count-dec")
p := testProvider("aws")
p.DiffFn = testDiffFn
@ -2992,7 +2991,7 @@ func TestContextApply_countDecrease(t *testing.T) {
},
},
}
ctx := testContext(t, &ContextOpts{
ctx := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
@ -3016,6 +3015,7 @@ func TestContextApply_countDecrease(t *testing.T) {
}
}
/*
func TestContextApply_countDecreaseToOne(t *testing.T) {
m := testModule(t, "apply-count-dec-one")
p := testProvider("aws")

View File

@ -2,6 +2,7 @@ package terraform
import (
"fmt"
"log"
)
// EvalCompareDiff is an EvalNode implementation that compares two diffs
@ -20,7 +21,20 @@ func (n *EvalCompareDiff) Eval(
ctx EvalContext, args []interface{}) (interface{}, error) {
one, two := *n.One, *n.Two
// If either are nil, let them be empty
if one == nil {
one = new(InstanceDiff)
one.init()
}
if two == nil {
two = new(InstanceDiff)
two.init()
}
if !one.Same(two) {
log.Printf("[ERROR] %s: diff's didn't match", n.Info.Id)
log.Printf("[ERROR] %s: diff one: %#v", n.Info.Id, one)
log.Printf("[ERROR] %s: diff two: %#v", n.Info.Id, two)
return nil, fmt.Errorf(
"%s: diffs didn't match during apply. This is a bug with "+
"Terraform and should be reported.", n.Info.Id)

View File

@ -223,6 +223,41 @@ func (n *graphNodeOrphanResource) EvalTree() EvalNode {
},
})
// Apply
var provider ResourceProvider
seq.Nodes = append(seq.Nodes, &EvalOpFilter{
Ops: []walkOperation{walkApply},
Node: &EvalSequence{
Nodes: []EvalNode{
&EvalReadDiff{
Name: n.ResourceName,
Diff: &diff,
},
&EvalGetProvider{
Name: n.ProvidedBy()[0],
Output: &provider,
},
&EvalReadState{
Name: n.ResourceName,
Output: &state,
},
&EvalApply{
Info: info,
State: &state,
Diff: &diff,
Provider: &provider,
Output: &state,
},
&EvalWriteState{
Name: n.ResourceName,
ResourceType: n.ResourceType,
Dependencies: n.DependentOn(),
State: &state,
},
},
},
})
return seq
}