forked from opentofu/opentofu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
input_variable.go
128 lines (99 loc) · 2.9 KB
/
input_variable.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright (c) The OpenTofu Authors
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2023 HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package addrs
import (
"fmt"
)
// InputVariable is the address of an input variable.
type InputVariable struct {
referenceable
Name string
}
func (v InputVariable) String() string {
return "var." + v.Name
}
func (v InputVariable) UniqueKey() UniqueKey {
return v // A InputVariable is its own UniqueKey
}
func (v InputVariable) uniqueKeySigil() {}
// 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,
}
}
func (v InputVariable) InModule(module Module) ConfigInputVariable {
return ConfigInputVariable{
Module: module,
Variable: v,
}
}
// AbsInputVariableInstance is the address of an input variable within a
// particular module instance.
type AbsInputVariableInstance struct {
Module ModuleInstance
Variable InputVariable
}
var _ Checkable = AbsInputVariableInstance{}
// 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 {
return v.Variable.String()
}
return fmt.Sprintf("%s.%s", v.Module.String(), v.Variable.String())
}
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() {}