config: self variables
This commit is contained in:
parent
492c6ef377
commit
9c612964d8
|
@ -68,6 +68,14 @@ type ResourceVariable struct {
|
||||||
key string
|
key string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SelfVariable is a variable that is referencing the same resource
|
||||||
|
// it is running on: "${self.address}"
|
||||||
|
type SelfVariable struct {
|
||||||
|
Field string
|
||||||
|
|
||||||
|
key string
|
||||||
|
}
|
||||||
|
|
||||||
// A UserVariable is a variable that is referencing a user variable
|
// A UserVariable is a variable that is referencing a user variable
|
||||||
// that is inputted from outside the configuration. This looks like
|
// that is inputted from outside the configuration. This looks like
|
||||||
// "${var.foo}"
|
// "${var.foo}"
|
||||||
|
@ -83,6 +91,8 @@ func NewInterpolatedVariable(v string) (InterpolatedVariable, error) {
|
||||||
return NewCountVariable(v)
|
return NewCountVariable(v)
|
||||||
} else if strings.HasPrefix(v, "path.") {
|
} else if strings.HasPrefix(v, "path.") {
|
||||||
return NewPathVariable(v)
|
return NewPathVariable(v)
|
||||||
|
} else if strings.HasPrefix(v, "self.") {
|
||||||
|
return NewSelfVariable(v)
|
||||||
} else if strings.HasPrefix(v, "var.") {
|
} else if strings.HasPrefix(v, "var.") {
|
||||||
return NewUserVariable(v)
|
return NewUserVariable(v)
|
||||||
} else if strings.HasPrefix(v, "module.") {
|
} else if strings.HasPrefix(v, "module.") {
|
||||||
|
@ -199,6 +209,24 @@ func (v *ResourceVariable) FullKey() string {
|
||||||
return v.key
|
return v.key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewSelfVariable(key string) (*SelfVariable, error) {
|
||||||
|
field := key[len("self."):]
|
||||||
|
|
||||||
|
return &SelfVariable{
|
||||||
|
Field: field,
|
||||||
|
|
||||||
|
key: key,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *SelfVariable) FullKey() string {
|
||||||
|
return v.key
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *SelfVariable) GoString() string {
|
||||||
|
return fmt.Sprintf("*%#v", *v)
|
||||||
|
}
|
||||||
|
|
||||||
func NewUserVariable(key string) (*UserVariable, error) {
|
func NewUserVariable(key string) (*UserVariable, error) {
|
||||||
name := key[len("var."):]
|
name := key[len("var."):]
|
||||||
elem := ""
|
elem := ""
|
||||||
|
|
|
@ -54,6 +54,14 @@ func TestNewInterpolatedVariable(t *testing.T) {
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"self.address",
|
||||||
|
&SelfVariable{
|
||||||
|
Field: "address",
|
||||||
|
key: "self.address",
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range cases {
|
for i, tc := range cases {
|
||||||
|
|
Loading…
Reference in New Issue