mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 17:01:04 -06:00
02b25e7057
This "kitchen sink" commit is mainly focused on supporting "targets" as a new sub-category of addresses, for use-case like the -target CLI option, but also includes some other functionality to get closer to replacing terraform.ResourceAddress and fill out some missing parts for representing various other address types that are currently represented as strings in the "terraform" package.
49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
package addrs
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// LocalValue is the address of a local value.
|
|
type LocalValue struct {
|
|
referenceable
|
|
Name string
|
|
}
|
|
|
|
func (v LocalValue) String() string {
|
|
return "local." + v.Name
|
|
}
|
|
|
|
// Absolute converts the receiver into an absolute address within the given
|
|
// module instance.
|
|
func (v LocalValue) Absolute(m ModuleInstance) AbsLocalValue {
|
|
return AbsLocalValue{
|
|
Module: m,
|
|
LocalValue: v,
|
|
}
|
|
}
|
|
|
|
// AbsLocalValue is the absolute address of a local value within a module instance.
|
|
type AbsLocalValue struct {
|
|
Module ModuleInstance
|
|
LocalValue LocalValue
|
|
}
|
|
|
|
// LocalValue returns the absolute address of a local value of the given
|
|
// name within the receiving module instance.
|
|
func (m ModuleInstance) LocalValue(name string) AbsLocalValue {
|
|
return AbsLocalValue{
|
|
Module: m,
|
|
LocalValue: LocalValue{
|
|
Name: name,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (v AbsLocalValue) String() string {
|
|
if len(v.Module) == 0 {
|
|
return v.LocalValue.String()
|
|
}
|
|
return fmt.Sprintf("%s.%s", v.Module.String(), v.LocalValue.String())
|
|
}
|