terraform: compare bad diffs for apply
This commit is contained in:
parent
d72ceb597d
commit
aea6b0a7e1
|
@ -2817,7 +2817,6 @@ func TestContext2Apply_minimal(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func TestContext2Apply_badDiff(t *testing.T) {
|
||||
m := testModule(t, "apply-good")
|
||||
p := testProvider("aws")
|
||||
|
|
|
@ -1,5 +1,38 @@
|
|||
package terraform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// EvalCompareDiff is an EvalNode implementation that compares two diffs
|
||||
// and errors if the diffs are not equal.
|
||||
type EvalCompareDiff struct {
|
||||
Info *InstanceInfo
|
||||
One, Two **InstanceDiff
|
||||
}
|
||||
|
||||
func (n *EvalCompareDiff) Args() ([]EvalNode, []EvalType) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// TODO: test
|
||||
func (n *EvalCompareDiff) Eval(
|
||||
ctx EvalContext, args []interface{}) (interface{}, error) {
|
||||
one, two := *n.One, *n.Two
|
||||
|
||||
if !one.Same(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)
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (n *EvalCompareDiff) Type() EvalType {
|
||||
return EvalTypeNull
|
||||
}
|
||||
|
||||
// EvalDiff is an EvalNode implementation that does a refresh for
|
||||
// a resource.
|
||||
type EvalDiff struct {
|
||||
|
@ -84,11 +117,15 @@ func (n *EvalDiff) Eval(
|
|||
|
||||
// Update our output
|
||||
*n.Output = diff
|
||||
*n.OutputState = state
|
||||
|
||||
// Merge our state so that the state is updated with our plan
|
||||
if !diff.Empty() && n.OutputState != nil {
|
||||
*n.OutputState = state.MergeDiff(diff)
|
||||
// Update the state if we care
|
||||
if n.OutputState != nil {
|
||||
*n.OutputState = state
|
||||
|
||||
// Merge our state so that the state is updated with our plan
|
||||
if !diff.Empty() && n.OutputState != nil {
|
||||
*n.OutputState = state.MergeDiff(diff)
|
||||
}
|
||||
}
|
||||
|
||||
return state, nil
|
||||
|
|
|
@ -98,7 +98,7 @@ func (n *graphNodeExpandedResource) ProvidedBy() []string {
|
|||
|
||||
// GraphNodeEvalable impl.
|
||||
func (n *graphNodeExpandedResource) EvalTree() EvalNode {
|
||||
var diff *InstanceDiff
|
||||
var diff, diff2 *InstanceDiff
|
||||
var state *InstanceState
|
||||
|
||||
// Build the resource. If we aren't part of a multi-resource, then
|
||||
|
@ -225,14 +225,32 @@ func (n *graphNodeExpandedResource) EvalTree() EvalNode {
|
|||
Ops: []walkOperation{walkApply},
|
||||
Node: &EvalSequence{
|
||||
Nodes: []EvalNode{
|
||||
&EvalGetProvider{
|
||||
Name: n.ProvidedBy()[0],
|
||||
Output: &provider,
|
||||
// Redo the diff so we can compare outputs
|
||||
&EvalDiff{
|
||||
Info: info,
|
||||
Config: interpolateNode,
|
||||
Provider: &EvalGetProvider{Name: n.ProvidedBy()[0]},
|
||||
State: &EvalReadState{Name: n.stateId()},
|
||||
Output: &diff2,
|
||||
},
|
||||
|
||||
// Get the saved diff
|
||||
&EvalReadDiff{
|
||||
Name: n.stateId(),
|
||||
Diff: &diff,
|
||||
},
|
||||
|
||||
// Compare the diffs
|
||||
&EvalCompareDiff{
|
||||
Info: info,
|
||||
One: &diff,
|
||||
Two: &diff2,
|
||||
},
|
||||
|
||||
&EvalGetProvider{
|
||||
Name: n.ProvidedBy()[0],
|
||||
Output: &provider,
|
||||
},
|
||||
&EvalReadState{
|
||||
Name: n.stateId(),
|
||||
Output: &state,
|
||||
|
|
Loading…
Reference in New Issue