mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
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) {
|
func TestContext2Apply_badDiff(t *testing.T) {
|
||||||
m := testModule(t, "apply-good")
|
m := testModule(t, "apply-good")
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
|
@ -1,5 +1,38 @@
|
|||||||
package terraform
|
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
|
// EvalDiff is an EvalNode implementation that does a refresh for
|
||||||
// a resource.
|
// a resource.
|
||||||
type EvalDiff struct {
|
type EvalDiff struct {
|
||||||
@ -84,11 +117,15 @@ func (n *EvalDiff) Eval(
|
|||||||
|
|
||||||
// Update our output
|
// Update our output
|
||||||
*n.Output = diff
|
*n.Output = diff
|
||||||
*n.OutputState = state
|
|
||||||
|
|
||||||
// Merge our state so that the state is updated with our plan
|
// Update the state if we care
|
||||||
if !diff.Empty() && n.OutputState != nil {
|
if n.OutputState != nil {
|
||||||
*n.OutputState = state.MergeDiff(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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return state, nil
|
return state, nil
|
||||||
|
@ -98,7 +98,7 @@ func (n *graphNodeExpandedResource) ProvidedBy() []string {
|
|||||||
|
|
||||||
// GraphNodeEvalable impl.
|
// GraphNodeEvalable impl.
|
||||||
func (n *graphNodeExpandedResource) EvalTree() EvalNode {
|
func (n *graphNodeExpandedResource) EvalTree() EvalNode {
|
||||||
var diff *InstanceDiff
|
var diff, diff2 *InstanceDiff
|
||||||
var state *InstanceState
|
var state *InstanceState
|
||||||
|
|
||||||
// Build the resource. If we aren't part of a multi-resource, then
|
// 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},
|
Ops: []walkOperation{walkApply},
|
||||||
Node: &EvalSequence{
|
Node: &EvalSequence{
|
||||||
Nodes: []EvalNode{
|
Nodes: []EvalNode{
|
||||||
&EvalGetProvider{
|
// Redo the diff so we can compare outputs
|
||||||
Name: n.ProvidedBy()[0],
|
&EvalDiff{
|
||||||
Output: &provider,
|
Info: info,
|
||||||
|
Config: interpolateNode,
|
||||||
|
Provider: &EvalGetProvider{Name: n.ProvidedBy()[0]},
|
||||||
|
State: &EvalReadState{Name: n.stateId()},
|
||||||
|
Output: &diff2,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Get the saved diff
|
||||||
&EvalReadDiff{
|
&EvalReadDiff{
|
||||||
Name: n.stateId(),
|
Name: n.stateId(),
|
||||||
Diff: &diff,
|
Diff: &diff,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Compare the diffs
|
||||||
|
&EvalCompareDiff{
|
||||||
|
Info: info,
|
||||||
|
One: &diff,
|
||||||
|
Two: &diff2,
|
||||||
|
},
|
||||||
|
|
||||||
|
&EvalGetProvider{
|
||||||
|
Name: n.ProvidedBy()[0],
|
||||||
|
Output: &provider,
|
||||||
|
},
|
||||||
&EvalReadState{
|
&EvalReadState{
|
||||||
Name: n.stateId(),
|
Name: n.stateId(),
|
||||||
Output: &state,
|
Output: &state,
|
||||||
|
Loading…
Reference in New Issue
Block a user