Skip to content

Commit

Permalink
Fixup for allowing empty lists/sets of resources
Browse files Browse the repository at this point in the history
  • Loading branch information
pselle committed Dec 3, 2019
1 parent 19b408e commit de953ec
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions states/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit de953ec

Please sign in to comment.