mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-20 11:48:24 -06:00
config: error if variable interpolation can't find variable
This commit is contained in:
parent
7578fb8bdc
commit
aeb085c5f0
@ -193,7 +193,13 @@ func (i *VariableInterpolation) FullString() string {
|
|||||||
|
|
||||||
func (i *VariableInterpolation) Interpolate(
|
func (i *VariableInterpolation) Interpolate(
|
||||||
vs map[string]string) (string, error) {
|
vs map[string]string) (string, error) {
|
||||||
return vs[i.key], nil
|
v, ok := vs[i.key]
|
||||||
|
if !ok {
|
||||||
|
return "", fmt.Errorf(
|
||||||
|
"%s: value for variable '%s' not found", v)
|
||||||
|
}
|
||||||
|
|
||||||
|
return v, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *VariableInterpolation) Variables() map[string]InterpolatedVariable {
|
func (i *VariableInterpolation) Variables() map[string]InterpolatedVariable {
|
||||||
|
@ -273,3 +273,18 @@ func TestVariableInterpolation(t *testing.T) {
|
|||||||
t.Fatalf("bad: %#v", actual)
|
t.Fatalf("bad: %#v", actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestVariableInterpolation_missing(t *testing.T) {
|
||||||
|
uv, err := NewUserVariable("var.foo")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
i := &VariableInterpolation{Variable: uv, key: "var.foo"}
|
||||||
|
_, err = i.Interpolate(map[string]string{
|
||||||
|
"var.bar": "bar",
|
||||||
|
})
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("should error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user