config: validate no interp in var [GH-180]

This commit is contained in:
Mitchell Hashimoto 2014-08-11 09:46:56 -07:00
parent 637446d1ab
commit fe2a306341
4 changed files with 29 additions and 0 deletions

View File

@ -1,6 +1,8 @@
## 0.2.0 (unreleased)
BUG FIXES:
* core: Variables are validated to not contain interpolations. [GH-180]
## 0.1.1 (August 5, 2014)

View File

@ -9,6 +9,7 @@ import (
"github.com/hashicorp/terraform/flatmap"
"github.com/hashicorp/terraform/helper/multierror"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/reflectwalk"
)
// Config is the configuration that comes from loading a collection
@ -116,6 +117,22 @@ func (c *Config) Validate() error {
errs = append(errs, fmt.Errorf(
"Variable '%s': must be string or mapping",
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))
}
}
}

View File

@ -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) {
pcs := []*ProviderConfig{
&ProviderConfig{Name: "aw"},

View File

@ -0,0 +1,3 @@
variable "foo" {
default = "${aws_instance.foo.bar}"
}