mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
config: parse TerraformVariables
This commit is contained in:
parent
4d6242dfe0
commit
786334b643
@ -84,6 +84,13 @@ type SimpleVariable struct {
|
||||
Key string
|
||||
}
|
||||
|
||||
// TerraformVariable is a "terraform."-prefixed variable used to access
|
||||
// metadata about the Terraform run.
|
||||
type TerraformVariable struct {
|
||||
Field string
|
||||
key string
|
||||
}
|
||||
|
||||
// A UserVariable is a variable that is referencing a user variable
|
||||
// that is inputted from outside the configuration. This looks like
|
||||
// "${var.foo}"
|
||||
@ -101,6 +108,8 @@ func NewInterpolatedVariable(v string) (InterpolatedVariable, error) {
|
||||
return NewPathVariable(v)
|
||||
} else if strings.HasPrefix(v, "self.") {
|
||||
return NewSelfVariable(v)
|
||||
} else if strings.HasPrefix(v, "terraform.") {
|
||||
return NewTerraformVariable(v)
|
||||
} else if strings.HasPrefix(v, "var.") {
|
||||
return NewUserVariable(v)
|
||||
} else if strings.HasPrefix(v, "module.") {
|
||||
@ -278,6 +287,22 @@ func (v *SimpleVariable) GoString() string {
|
||||
return fmt.Sprintf("*%#v", *v)
|
||||
}
|
||||
|
||||
func NewTerraformVariable(key string) (*TerraformVariable, error) {
|
||||
field := key[len("terraform."):]
|
||||
return &TerraformVariable{
|
||||
Field: field,
|
||||
key: key,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (v *TerraformVariable) FullKey() string {
|
||||
return v.key
|
||||
}
|
||||
|
||||
func (v *TerraformVariable) GoString() string {
|
||||
return fmt.Sprintf("*%#v", *v)
|
||||
}
|
||||
|
||||
func NewUserVariable(key string) (*UserVariable, error) {
|
||||
name := key[len("var."):]
|
||||
elem := ""
|
||||
|
@ -63,6 +63,14 @@ func TestNewInterpolatedVariable(t *testing.T) {
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"terraform.env",
|
||||
&TerraformVariable{
|
||||
Field: "env",
|
||||
key: "terraform.env",
|
||||
},
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
|
Loading…
Reference in New Issue
Block a user