2024-02-08 04:48:59 -05:00
|
|
|
// Copyright (c) The OpenTofu Authors
|
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
// Copyright (c) 2023 HashiCorp, Inc.
|
2023-05-02 11:33:06 -04:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
|
2018-03-30 22:58:57 -04:00
|
|
|
package addrs
|
|
|
|
|
|
2018-04-30 13:06:05 -04:00
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
)
|
|
|
|
|
|
2018-03-30 22:58:57 -04:00
|
|
|
// InputVariable is the address of an input variable.
|
|
|
|
|
type InputVariable struct {
|
|
|
|
|
referenceable
|
|
|
|
|
Name string
|
|
|
|
|
}
|
2018-04-03 21:03:47 -04:00
|
|
|
|
|
|
|
|
func (v InputVariable) String() string {
|
|
|
|
|
return "var." + v.Name
|
|
|
|
|
}
|
2018-04-30 13:06:05 -04:00
|
|
|
|
2021-07-10 18:18:19 -04:00
|
|
|
func (v InputVariable) UniqueKey() UniqueKey {
|
|
|
|
|
return v // A InputVariable is its own UniqueKey
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (v InputVariable) uniqueKeySigil() {}
|
|
|
|
|
|
2020-02-24 17:42:32 -05:00
|
|
|
// Absolute converts the receiver into an absolute address within the given
|
|
|
|
|
// module instance.
|
|
|
|
|
func (v InputVariable) Absolute(m ModuleInstance) AbsInputVariableInstance {
|
|
|
|
|
return AbsInputVariableInstance{
|
|
|
|
|
Module: m,
|
|
|
|
|
Variable: v,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-10 06:33:45 -04:00
|
|
|
func (v InputVariable) InModule(module Module) ConfigInputVariable {
|
|
|
|
|
return ConfigInputVariable{
|
|
|
|
|
Module: module,
|
|
|
|
|
Variable: v,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-30 13:06:05 -04:00
|
|
|
// AbsInputVariableInstance is the address of an input variable within a
|
|
|
|
|
// particular module instance.
|
|
|
|
|
type AbsInputVariableInstance struct {
|
|
|
|
|
Module ModuleInstance
|
|
|
|
|
Variable InputVariable
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-10 06:33:45 -04:00
|
|
|
var _ Checkable = AbsInputVariableInstance{}
|
|
|
|
|
|
2018-04-30 13:06:05 -04:00
|
|
|
// InputVariable returns the absolute address of the input variable of the
|
|
|
|
|
// given name inside the receiving module instance.
|
|
|
|
|
func (m ModuleInstance) InputVariable(name string) AbsInputVariableInstance {
|
|
|
|
|
return AbsInputVariableInstance{
|
|
|
|
|
Module: m,
|
|
|
|
|
Variable: InputVariable{
|
|
|
|
|
Name: name,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (v AbsInputVariableInstance) String() string {
|
|
|
|
|
if len(v.Module) == 0 {
|
2020-01-03 20:43:55 -05:00
|
|
|
return v.Variable.String()
|
2018-04-30 13:06:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fmt.Sprintf("%s.%s", v.Module.String(), v.Variable.String())
|
|
|
|
|
}
|
2023-07-10 06:33:45 -04:00
|
|
|
|
|
|
|
|
func (v AbsInputVariableInstance) UniqueKey() UniqueKey {
|
|
|
|
|
return absInputVariableInstanceUniqueKey(v.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (v AbsInputVariableInstance) checkableSigil() {}
|
|
|
|
|
|
|
|
|
|
func (v AbsInputVariableInstance) CheckRule(typ CheckRuleType, i int) CheckRule {
|
|
|
|
|
return CheckRule{
|
|
|
|
|
Container: v,
|
|
|
|
|
Type: typ,
|
|
|
|
|
Index: i,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (v AbsInputVariableInstance) ConfigCheckable() ConfigCheckable {
|
|
|
|
|
return ConfigInputVariable{
|
|
|
|
|
Module: v.Module.Module(),
|
|
|
|
|
Variable: v.Variable,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (v AbsInputVariableInstance) CheckableKind() CheckableKind {
|
|
|
|
|
return CheckableInputVariable
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ConfigInputVariable struct {
|
|
|
|
|
Module Module
|
|
|
|
|
Variable InputVariable
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var _ ConfigCheckable = ConfigInputVariable{}
|
|
|
|
|
|
|
|
|
|
func (v ConfigInputVariable) UniqueKey() UniqueKey {
|
|
|
|
|
return configInputVariableUniqueKey(v.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (v ConfigInputVariable) configCheckableSigil() {}
|
|
|
|
|
|
|
|
|
|
func (v ConfigInputVariable) CheckableKind() CheckableKind {
|
|
|
|
|
return CheckableInputVariable
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (v ConfigInputVariable) String() string {
|
|
|
|
|
if len(v.Module) == 0 {
|
|
|
|
|
return v.Variable.String()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fmt.Sprintf("%s.%s", v.Module.String(), v.Variable.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type configInputVariableUniqueKey string
|
|
|
|
|
|
|
|
|
|
func (k configInputVariableUniqueKey) uniqueKeySigil() {}
|
|
|
|
|
|
|
|
|
|
type absInputVariableInstanceUniqueKey string
|
|
|
|
|
|
|
|
|
|
func (k absInputVariableInstanceUniqueKey) uniqueKeySigil() {}
|