mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-14 02:32:39 -06:00
config: validate no interp in var [GH-180]
This commit is contained in:
parent
637446d1ab
commit
fe2a306341
@ -1,6 +1,8 @@
|
|||||||
## 0.2.0 (unreleased)
|
## 0.2.0 (unreleased)
|
||||||
|
|
||||||
|
BUG FIXES:
|
||||||
|
|
||||||
|
* core: Variables are validated to not contain interpolations. [GH-180]
|
||||||
|
|
||||||
## 0.1.1 (August 5, 2014)
|
## 0.1.1 (August 5, 2014)
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform/flatmap"
|
"github.com/hashicorp/terraform/flatmap"
|
||||||
"github.com/hashicorp/terraform/helper/multierror"
|
"github.com/hashicorp/terraform/helper/multierror"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
|
"github.com/mitchellh/reflectwalk"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config is the configuration that comes from loading a collection
|
// Config is the configuration that comes from loading a collection
|
||||||
@ -116,6 +117,22 @@ func (c *Config) Validate() error {
|
|||||||
errs = append(errs, fmt.Errorf(
|
errs = append(errs, fmt.Errorf(
|
||||||
"Variable '%s': must be string or mapping",
|
"Variable '%s': must be string or mapping",
|
||||||
v.Name))
|
v.Name))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
interp := false
|
||||||
|
fn := func(i Interpolation) (string, error) {
|
||||||
|
interp = true
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
w := &interpolationWalker{F: fn}
|
||||||
|
if err := reflectwalk.Walk(v.Default, w); err == nil {
|
||||||
|
if interp {
|
||||||
|
errs = append(errs, fmt.Errorf(
|
||||||
|
"Variable '%s': cannot contain interpolations",
|
||||||
|
v.Name))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,6 +100,13 @@ func TestConfigValidate_varDefaultBadType(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConfigValidate_varDefaultInterpolate(t *testing.T) {
|
||||||
|
c := testConfig(t, "validate-var-default-interpolate")
|
||||||
|
if err := c.Validate(); err == nil {
|
||||||
|
t.Fatal("should not be valid")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestProviderConfigName(t *testing.T) {
|
func TestProviderConfigName(t *testing.T) {
|
||||||
pcs := []*ProviderConfig{
|
pcs := []*ProviderConfig{
|
||||||
&ProviderConfig{Name: "aw"},
|
&ProviderConfig{Name: "aw"},
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
variable "foo" {
|
||||||
|
default = "${aws_instance.foo.bar}"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user