github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/addrs/local_value.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package addrs 5 6 import ( 7 "fmt" 8 ) 9 10 // LocalValue is the address of a local value. 11 type LocalValue struct { 12 referenceable 13 Name string 14 } 15 16 func (v LocalValue) String() string { 17 return "local." + v.Name 18 } 19 20 func (v LocalValue) UniqueKey() UniqueKey { 21 return v // A LocalValue is its own UniqueKey 22 } 23 24 func (v LocalValue) uniqueKeySigil() {} 25 26 // Absolute converts the receiver into an absolute address within the given 27 // module instance. 28 func (v LocalValue) Absolute(m ModuleInstance) AbsLocalValue { 29 return AbsLocalValue{ 30 Module: m, 31 LocalValue: v, 32 } 33 } 34 35 // AbsLocalValue is the absolute address of a local value within a module instance. 36 type AbsLocalValue struct { 37 Module ModuleInstance 38 LocalValue LocalValue 39 } 40 41 // LocalValue returns the absolute address of a local value of the given 42 // name within the receiving module instance. 43 func (m ModuleInstance) LocalValue(name string) AbsLocalValue { 44 return AbsLocalValue{ 45 Module: m, 46 LocalValue: LocalValue{ 47 Name: name, 48 }, 49 } 50 } 51 52 func (v AbsLocalValue) String() string { 53 if len(v.Module) == 0 { 54 return v.LocalValue.String() 55 } 56 return fmt.Sprintf("%s.%s", v.Module.String(), v.LocalValue.String()) 57 }