From e76fb9f3d9ca2da5a29802609e0dd5d77b39fd7c Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Mon, 23 Oct 2023 17:55:10 -0700 Subject: [PATCH] states: State.AllResourceInstanceObjectAddrs is back! In the previous commit we renamed AllResourceInstaceObjectAddrs to AllManagedResourceInstanceObjectAddrs to reflect that it filters out any resource instances that aren't "managed". This now adds back in a State.AllResourceInstanceObjectAddrs method which does what the other one sounded like it did before: returns all of the known addresses without any filtering whatsoever. --- internal/states/state.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/internal/states/state.go b/internal/states/state.go index 8a75896265..20e25341c9 100644 --- a/internal/states/state.go +++ b/internal/states/state.go @@ -215,6 +215,18 @@ func (s *State) Resources(addr addrs.ConfigResource) []*Resource { return ret } +// AllResourceInstanceObjectAddrs returns a set of addresses for all of +// the leaf resource instance objects of any mode that are tracked in this +// state. +// +// If you only care about objects belonging to managed resources, use +// [State.AllManagedResourceInstanceObjectAddrs] instead. +func (s *State) AllResourceInstanceObjectAddrs() addrs.Set[addrs.AbsResourceInstanceObject] { + return s.allResourceInstanceObjectAddrs(func(addr addrs.AbsResourceInstanceObject) bool { + return true // we filter nothing + }) +} + // AllManagedResourceInstanceObjectAddrs returns a set of addresses for all of // the leaf resource instance objects associated with managed resources that // are tracked in this state. @@ -224,12 +236,6 @@ func (s *State) Resources(addr addrs.ConfigResource) []*Resource { // by deleting a workspace. This function is intended only for reporting // context in error messages, such as when we reject deleting a "non-empty" // workspace as detected by s.HasManagedResourceInstanceObjects. -// -// The ordering of the result is meaningless but consistent. DeposedKey will -// be NotDeposed (the zero value of DeposedKey) for any "current" objects. -// This method is guaranteed to return at least one item if -// s.HasManagedResourceInstanceObjects returns true for the same state, and -// to return a zero-length slice if it returns false. func (s *State) AllManagedResourceInstanceObjectAddrs() addrs.Set[addrs.AbsResourceInstanceObject] { return s.allResourceInstanceObjectAddrs(func(addr addrs.AbsResourceInstanceObject) bool { return addr.ResourceInstance.Resource.Resource.Mode == addrs.ManagedResourceMode