github.com/pulumi/terraform@v1.4.0/pkg/addrs/input_variable.go (about)

     1  package addrs
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  // InputVariable is the address of an input variable.
     8  type InputVariable struct {
     9  	referenceable
    10  	Name string
    11  }
    12  
    13  func (v InputVariable) String() string {
    14  	return "var." + v.Name
    15  }
    16  
    17  func (v InputVariable) UniqueKey() UniqueKey {
    18  	return v // A InputVariable is its own UniqueKey
    19  }
    20  
    21  func (v InputVariable) uniqueKeySigil() {}
    22  
    23  // Absolute converts the receiver into an absolute address within the given
    24  // module instance.
    25  func (v InputVariable) Absolute(m ModuleInstance) AbsInputVariableInstance {
    26  	return AbsInputVariableInstance{
    27  		Module:   m,
    28  		Variable: v,
    29  	}
    30  }
    31  
    32  // AbsInputVariableInstance is the address of an input variable within a
    33  // particular module instance.
    34  type AbsInputVariableInstance struct {
    35  	Module   ModuleInstance
    36  	Variable InputVariable
    37  }
    38  
    39  // InputVariable returns the absolute address of the input variable of the
    40  // given name inside the receiving module instance.
    41  func (m ModuleInstance) InputVariable(name string) AbsInputVariableInstance {
    42  	return AbsInputVariableInstance{
    43  		Module: m,
    44  		Variable: InputVariable{
    45  			Name: name,
    46  		},
    47  	}
    48  }
    49  
    50  func (v AbsInputVariableInstance) String() string {
    51  	if len(v.Module) == 0 {
    52  		return v.Variable.String()
    53  	}
    54  
    55  	return fmt.Sprintf("%s.%s", v.Module.String(), v.Variable.String())
    56  }