github.com/opentofu/opentofu@v1.7.1/internal/instances/set.go (about) 1 // Copyright (c) The OpenTofu Authors 2 // SPDX-License-Identifier: MPL-2.0 3 // Copyright (c) 2023 HashiCorp, Inc. 4 // SPDX-License-Identifier: MPL-2.0 5 6 package instances 7 8 import ( 9 "github.com/opentofu/opentofu/internal/addrs" 10 ) 11 12 // Set is a set of instances, intended mainly for the return value of 13 // Expander.AllInstances, where it therefore represents all of the module 14 // and resource instances known to the expander. 15 type Set struct { 16 // Set currently really just wraps Expander with a reduced API that 17 // only supports lookups, to make it clear that a holder of a Set should 18 // not be modifying the expander any further. 19 exp *Expander 20 } 21 22 // HasModuleInstance returns true if and only if the set contains the module 23 // instance with the given address. 24 func (s Set) HasModuleInstance(want addrs.ModuleInstance) bool { 25 return s.exp.knowsModuleInstance(want) 26 } 27 28 // HasModuleCall returns true if and only if the set contains the module 29 // call with the given address, even if that module call has no instances. 30 func (s Set) HasModuleCall(want addrs.AbsModuleCall) bool { 31 return s.exp.knowsModuleCall(want) 32 } 33 34 // HasResourceInstance returns true if and only if the set contains the resource 35 // instance with the given address. 36 // TODO: 37 func (s Set) HasResourceInstance(want addrs.AbsResourceInstance) bool { 38 return s.exp.knowsResourceInstance(want) 39 } 40 41 // HasResource returns true if and only if the set contains the resource with 42 // the given address, even if that resource has no instances. 43 // TODO: 44 func (s Set) HasResource(want addrs.AbsResource) bool { 45 return s.exp.knowsResource(want) 46 } 47 48 // InstancesForModule returns all of the module instances that correspond with 49 // the given static module path. 50 // 51 // If there are multiple module calls in the path that have repetition enabled 52 // then the result is the full expansion of all combinations of all of their 53 // declared instance keys. 54 func (s Set) InstancesForModule(modAddr addrs.Module) []addrs.ModuleInstance { 55 return s.exp.expandModule(modAddr, true) 56 }