mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
terraform: apply for orphans
This commit is contained in:
parent
abc68a89a8
commit
691db58478
@ -2948,8 +2948,7 @@ func TestContext2Apply_compute(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
func TestContext2Apply_countDecrease(t *testing.T) {
|
||||||
func TestContextApply_countDecrease(t *testing.T) {
|
|
||||||
m := testModule(t, "apply-count-dec")
|
m := testModule(t, "apply-count-dec")
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
p.DiffFn = testDiffFn
|
p.DiffFn = testDiffFn
|
||||||
@ -2992,7 +2991,7 @@ func TestContextApply_countDecrease(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctx := testContext(t, &ContextOpts{
|
ctx := testContext2(t, &ContextOpts{
|
||||||
Module: m,
|
Module: m,
|
||||||
Providers: map[string]ResourceProviderFactory{
|
Providers: map[string]ResourceProviderFactory{
|
||||||
"aws": testProviderFuncFixed(p),
|
"aws": testProviderFuncFixed(p),
|
||||||
@ -3016,6 +3015,7 @@ func TestContextApply_countDecrease(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
func TestContextApply_countDecreaseToOne(t *testing.T) {
|
func TestContextApply_countDecreaseToOne(t *testing.T) {
|
||||||
m := testModule(t, "apply-count-dec-one")
|
m := testModule(t, "apply-count-dec-one")
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
|
@ -2,6 +2,7 @@ package terraform
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EvalCompareDiff is an EvalNode implementation that compares two diffs
|
// EvalCompareDiff is an EvalNode implementation that compares two diffs
|
||||||
@ -20,7 +21,20 @@ func (n *EvalCompareDiff) Eval(
|
|||||||
ctx EvalContext, args []interface{}) (interface{}, error) {
|
ctx EvalContext, args []interface{}) (interface{}, error) {
|
||||||
one, two := *n.One, *n.Two
|
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) {
|
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(
|
return nil, fmt.Errorf(
|
||||||
"%s: diffs didn't match during apply. This is a bug with "+
|
"%s: diffs didn't match during apply. This is a bug with "+
|
||||||
"Terraform and should be reported.", n.Info.Id)
|
"Terraform and should be reported.", n.Info.Id)
|
||||||
|
@ -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
|
return seq
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user