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
if desired != nil {
resourceTypeName = desired.Addr.Resource.Resource.Type
} else if prior != nil {
resourceTypeName = prior.ResourceType
} else {
// FIXME: We don't haave anywhere to get the resource type name from
// if the resource instance is not desired. This is one of the
// annoyances of using our existing states.ResourceInstanceObject
// model, since it was designed to be used by callers that also have
// access to the rest of the state data structure that would've
// indicated which resource instance the object belongs to.
resourceTypeName = "<FIXME: no resource type available!>"
// Should not get here: there's no reason to be applying changes
// for a resource instance that has neither a desired state nor
// a prior state.
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)"))
return nil, false, diags
}
req := providers.PlanResourceChangeRequest{