github.com/hashicorp/terraform-plugin-sdk@v1.17.2/internal/addrs/module_call.go (about)

     1  package addrs
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  // ModuleCall is the address of a call from the current module to a child
     8  // module.
     9  //
    10  // There is no "Abs" version of ModuleCall because an absolute module path
    11  // is represented by ModuleInstance.
    12  type ModuleCall struct {
    13  	referenceable
    14  	Name string
    15  }
    16  
    17  func (c ModuleCall) String() string {
    18  	return "module." + c.Name
    19  }
    20  
    21  // ModuleCallInstance is the address of one instance of a module created from
    22  // a module call, which might create multiple instances using "count" or
    23  // "for_each" arguments.
    24  type ModuleCallInstance struct {
    25  	referenceable
    26  	Call ModuleCall
    27  	Key  InstanceKey
    28  }
    29  
    30  func (c ModuleCallInstance) String() string {
    31  	if c.Key == NoKey {
    32  		return c.Call.String()
    33  	}
    34  	return fmt.Sprintf("module.%s%s", c.Call.Name, c.Key)
    35  }
    36  
    37  // ModuleInstance returns the address of the module instance that corresponds
    38  // to the receiving call instance when resolved in the given calling module.
    39  // In other words, it returns the child module instance that the receving
    40  // call instance creates.
    41  func (c ModuleCallInstance) ModuleInstance(caller ModuleInstance) ModuleInstance {
    42  	return caller.Child(c.Call.Name, c.Key)
    43  }
    44  
    45  // ModuleCallOutput is the address of a particular named output produced by
    46  // an instance of a module call.
    47  type ModuleCallOutput struct {
    48  	referenceable
    49  	Call ModuleCallInstance
    50  	Name string
    51  }
    52  
    53  func (co ModuleCallOutput) String() string {
    54  	return fmt.Sprintf("%s.%s", co.Call.String(), co.Name)
    55  }
    56  
    57  // AbsOutputValue returns the absolute output value address that corresponds
    58  // to the receving module call output address, once resolved in the given
    59  // calling module.
    60  func (co ModuleCallOutput) AbsOutputValue(caller ModuleInstance) AbsOutputValue {
    61  	moduleAddr := co.Call.ModuleInstance(caller)
    62  	return moduleAddr.OutputValue(co.Name)
    63  }