execgraph: opManagedFinalPlan can use resource type from prior state

Previously we had a gap here where we only knew the resource type to use
when there was a "desired state" object to get it from, which isn't true
when we're planning to destroy an undesired object.

The new extended model for resource instance object state gives us direct
access to the resource type name, so we can now handle that properly.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
This commit is contained in:
Martin Atkins
2025-12-03 16:14:13 -08:00
parent a484919556
commit c89cd97505

View File

@@ -71,14 +71,14 @@ func (c *compiler) compileOpManagedFinalPlan(operands *compilerOperands) nodeExe
var resourceTypeName string var resourceTypeName string
if desired != nil { if desired != nil {
resourceTypeName = desired.Addr.Resource.Resource.Type resourceTypeName = desired.Addr.Resource.Resource.Type
} else if prior != nil {
resourceTypeName = prior.ResourceType
} else { } else {
// FIXME: We don't haave anywhere to get the resource type name from // Should not get here: there's no reason to be applying changes
// if the resource instance is not desired. This is one of the // for a resource instance that has neither a desired state nor
// annoyances of using our existing states.ResourceInstanceObject // a prior state.
// model, since it was designed to be used by callers that also have diags = diags.Append(fmt.Errorf("attempting to apply final plan for resource instance that has neither desired nor prior state (this is a bug in OpenTofu)"))
// access to the rest of the state data structure that would've return nil, false, diags
// indicated which resource instance the object belongs to.
resourceTypeName = "<FIXME: no resource type available!>"
} }
req := providers.PlanResourceChangeRequest{ req := providers.PlanResourceChangeRequest{