kubeform.dev/terraform-backend-sdk@v0.0.0-20220310143633-45f07fe731c5/instances/set.go (about)

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