config: ignore_changes cannot have interpolations

This is the limitation of all lifecycle attributes currently. Right now,
interpolations are allowed through and the user ends up thinking it
should work. We should give an error.

In the future it should be possible to support some minimal set of
interpolations (static variables, data sources even perhaps) but for now
let's validate that this doesn't work.
This commit is contained in:
Mitchell Hashimoto 2016-10-24 23:06:33 -07:00
parent fa9758e162
commit 694b16de5d
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
3 changed files with 28 additions and 0 deletions

View File

@ -579,6 +579,20 @@ func (c *Config) Validate() error {
"together with a wildcard: %s", n, v))
}
}
// Verify ignore_changes has no interpolations
rc, err := NewRawConfig(map[string]interface{}{
"root": r.Lifecycle.IgnoreChanges,
})
if err != nil {
errs = append(errs, fmt.Errorf(
"%s: lifecycle ignore_changes error: %s",
n, err))
} else if len(rc.Interpolations) > 0 {
errs = append(errs, fmt.Errorf(
"%s: lifecycle ignore_changes cannot contain interpolations",
n))
}
}
for source, vs := range vars {

View File

@ -265,6 +265,13 @@ func TestConfigValidate_ignoreChangesBad(t *testing.T) {
}
}
func TestConfigValidate_ignoreChangesInterpolate(t *testing.T) {
c := testConfig(t, "validate-ignore-changes-interpolate")
if err := c.Validate(); err == nil {
t.Fatal("should not be valid")
}
}
func TestConfigValidate_moduleNameBad(t *testing.T) {
c := testConfig(t, "validate-module-name-bad")
if err := c.Validate(); err == nil {

View File

@ -0,0 +1,7 @@
variable "foo" {}
resource aws_instance "web" {
lifecycle {
ignore_changes = ["${var.foo}"]
}
}