From de953eca6f5bd7420ffcbb778ca01c63b417e2e3 Mon Sep 17 00:00:00 2001 From: Pam Selle <204372+pselle@users.noreply.github.com> Date: Tue, 3 Dec 2019 16:29:01 -0500 Subject: [PATCH] Fixup for allowing empty lists/sets of resources --- states/module.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/states/module.go b/states/module.go index da4ae4b10..4b93af4eb 100644 --- a/states/module.go +++ b/states/module.go @@ -97,7 +97,9 @@ func (ms *Module) SetResourceInstanceCurrent(addr addrs.ResourceInstance, obj *R if obj == nil && rs != nil { // does the resource have any other objects? // if not then delete the whole resource - if len(rs.Instances) == 0 { + // When deleting the resource, ensure that its EachMode is NoEach, + // as a resource with EachList or EachMap can have 0 instances and be valid + if rs.EachMode == NoEach && len(rs.Instances) == 0 { delete(ms.Resources, addr.Resource.String()) return } @@ -113,7 +115,8 @@ func (ms *Module) SetResourceInstanceCurrent(addr addrs.ResourceInstance, obj *R if !is.HasObjects() { // If we have no objects at all then we'll clean up. delete(rs.Instances, addr.Key) - if len(rs.Instances) == 0 { + // Delete the resource if it has no instances, but only if NoEach + if rs.EachMode == NoEach && len(rs.Instances) == 0 { delete(ms.Resources, addr.Resource.String()) return }