github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/instances/set.go (about)

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