diff --git a/terraform/node_data_refresh.go b/terraform/node_data_refresh.go index ee50a2401..5de33c66a 100644 --- a/terraform/node_data_refresh.go +++ b/terraform/node_data_refresh.go @@ -147,7 +147,7 @@ func (n *NodeRefreshableDataResource) DynamicExpand(ctx EvalContext) (*Graph, er // directly as NodeDestroyableDataResource. &OrphanResourceCountTransformer{ Concrete: concreteResourceDestroyable, - Addr: n.ResourceAddr(), + Addr: n.Addr, InstanceAddrs: instanceAddrs, State: state, }, diff --git a/terraform/node_resource_plan.go b/terraform/node_resource_plan.go index 8024fd631..1fcc09f03 100644 --- a/terraform/node_resource_plan.go +++ b/terraform/node_resource_plan.go @@ -209,7 +209,7 @@ func (n *NodePlannableResource) DynamicExpand(ctx EvalContext) (*Graph, error) { // Add the count/for_each orphans &OrphanResourceCountTransformer{ Concrete: concreteResourceOrphan, - Addr: n.ResourceAddr(), + Addr: n.Addr, InstanceAddrs: instanceAddrs, State: state, }, diff --git a/terraform/node_resource_refresh.go b/terraform/node_resource_refresh.go index 8284e8054..98603454d 100644 --- a/terraform/node_resource_refresh.go +++ b/terraform/node_resource_refresh.go @@ -144,7 +144,7 @@ func (n *NodeRefreshableManagedResource) DynamicExpand(ctx EvalContext) (*Graph, // during a scale in. &OrphanResourceCountTransformer{ Concrete: concreteResource, - Addr: n.Addr.Config(), + Addr: n.Addr, InstanceAddrs: instanceAddrs, State: state, }, diff --git a/terraform/transform_orphan_count.go b/terraform/transform_orphan_count.go index ed3dc8f15..8416b5462 100644 --- a/terraform/transform_orphan_count.go +++ b/terraform/transform_orphan_count.go @@ -18,39 +18,37 @@ import ( type OrphanResourceCountTransformer struct { Concrete ConcreteResourceInstanceNodeFunc - Addr addrs.ConfigResource // Addr of the resource to look for orphans + Addr addrs.AbsResource // Addr of the resource to look for orphans InstanceAddrs []addrs.AbsResourceInstance // Addresses that currently exist in config State *states.State // Full global state } func (t *OrphanResourceCountTransformer) Transform(g *Graph) error { - resources := t.State.Resources(t.Addr) - if len(resources) == 0 { + rs := t.State.Resource(t.Addr) + if rs == nil { return nil // Resource doesn't exist in state, so nothing to do! } - for _, rs := range resources { - // This is an O(n*m) analysis, which we accept for now because the - // number of instances of a single resource ought to always be small in any - // reasonable Terraform configuration. - Have: - for key := range rs.Instances { - thisAddr := rs.Addr.Instance(key) - for _, wantAddr := range t.InstanceAddrs { - if wantAddr.Equal(thisAddr) { - continue Have - } + // This is an O(n*m) analysis, which we accept for now because the + // number of instances of a single resource ought to always be small in any + // reasonable Terraform configuration. +Have: + for key := range rs.Instances { + thisAddr := rs.Addr.Instance(key) + for _, wantAddr := range t.InstanceAddrs { + if wantAddr.Equal(thisAddr) { + continue Have } - // If thisAddr is not in t.InstanceAddrs then we've found an "orphan" - - abstract := NewNodeAbstractResourceInstance(thisAddr) - var node dag.Vertex = abstract - if f := t.Concrete; f != nil { - node = f(abstract) - } - log.Printf("[TRACE] OrphanResourceCountTransformer: adding %s as %T", thisAddr, node) - g.Add(node) } + // If thisAddr is not in t.InstanceAddrs then we've found an "orphan" + + abstract := NewNodeAbstractResourceInstance(thisAddr) + var node dag.Vertex = abstract + if f := t.Concrete; f != nil { + node = f(abstract) + } + log.Printf("[TRACE] OrphanResourceCountTransformer: adding %s as %T", thisAddr, node) + g.Add(node) } return nil