mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
use ResourceInstanceReplaceByTriggers
Set ResourceInstanceReplaceByTriggers in the change.
This commit is contained in:
parent
e4c4dcbd14
commit
e2fc9a19f5
@ -3025,6 +3025,9 @@ resource "test_object" "b" {
|
|||||||
if c.Action != plans.DeleteThenCreate {
|
if c.Action != plans.DeleteThenCreate {
|
||||||
t.Fatalf("unexpected %s change for %s\n", c.Action, c.Addr)
|
t.Fatalf("unexpected %s change for %s\n", c.Action, c.Addr)
|
||||||
}
|
}
|
||||||
|
if c.ActionReason != plans.ResourceInstanceReplaceByTriggers {
|
||||||
|
t.Fatalf("incorrect reason for change: %s\n", c.ActionReason)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
t.Fatal("unexpected change", c.Addr, c.Action)
|
t.Fatal("unexpected change", c.Addr, c.Action)
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,10 @@ type NodePlannableResourceInstance struct {
|
|||||||
// it might contain addresses that have nothing to do with the resource
|
// it might contain addresses that have nothing to do with the resource
|
||||||
// that this node represents, which the node itself must therefore ignore.
|
// that this node represents, which the node itself must therefore ignore.
|
||||||
forceReplace []addrs.AbsResourceInstance
|
forceReplace []addrs.AbsResourceInstance
|
||||||
|
|
||||||
|
// replaceTriggeredBy stores references from replace_triggered_by which
|
||||||
|
// triggered this instance to be replaced.
|
||||||
|
replaceTriggeredBy []*addrs.Reference
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -219,6 +223,13 @@ func (n *NodePlannableResourceInstance) managedResourceExecute(ctx EvalContext)
|
|||||||
return diags
|
return diags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: here we udpate the change to reflect the reason for
|
||||||
|
// replacement, but we still overload forceReplace to get the correct
|
||||||
|
// change planned.
|
||||||
|
if len(n.replaceTriggeredBy) > 0 {
|
||||||
|
change.ActionReason = plans.ResourceInstanceReplaceByTriggers
|
||||||
|
}
|
||||||
|
|
||||||
diags = diags.Append(n.checkPreventDestroy(change))
|
diags = diags.Append(n.checkPreventDestroy(change))
|
||||||
if diags.HasErrors() {
|
if diags.HasErrors() {
|
||||||
return diags
|
return diags
|
||||||
@ -325,21 +336,27 @@ func (n *NodePlannableResourceInstance) replaceTriggered(ctx EvalContext, repDat
|
|||||||
var diags tfdiags.Diagnostics
|
var diags tfdiags.Diagnostics
|
||||||
|
|
||||||
for _, expr := range n.Config.TriggersReplacement {
|
for _, expr := range n.Config.TriggersReplacement {
|
||||||
_, replace, evalDiags := ctx.EvaluateReplaceTriggeredBy(expr, repData)
|
ref, replace, evalDiags := ctx.EvaluateReplaceTriggeredBy(expr, repData)
|
||||||
diags = diags.Append(evalDiags)
|
diags = diags.Append(evalDiags)
|
||||||
if diags.HasErrors() {
|
if diags.HasErrors() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if replace {
|
if replace {
|
||||||
// FIXME: forceReplace accomplishes the same goal, however we will
|
// FIXME: forceReplace accomplishes the same goal, however we may
|
||||||
// want a new way to signal why this resource was replaced in the
|
// want to communicate more information about which resource
|
||||||
// plan.
|
// Rather than further complicating the plan method with more
|
||||||
|
// options, we can refactor both of these featured later.
|
||||||
|
n.forceReplace = append(n.forceReplace, n.Addr)
|
||||||
|
//
|
||||||
|
// triggered the replacement in the plan.
|
||||||
// EvalauteReplaceTriggeredBy returns a reference to store
|
// EvalauteReplaceTriggeredBy returns a reference to store
|
||||||
// somewhere for this purpose too.
|
// somewhere for this purpose too.
|
||||||
n.forceReplace = append(n.forceReplace, n.Addr)
|
log.Printf("[DEBUG] ReplaceTriggeredBy forcing replacement of %s due to change in %s", n.Addr, ref.DisplayString())
|
||||||
}
|
|
||||||
|
|
||||||
|
n.replaceTriggeredBy = append(n.replaceTriggeredBy, ref)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return diags
|
return diags
|
||||||
|
Loading…
Reference in New Issue
Block a user