From 694b16de5d8dc1ac653b2edd9bbaee2535783212 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 24 Oct 2016 23:06:33 -0700 Subject: [PATCH] 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. --- config/config.go | 14 ++++++++++++++ config/config_test.go | 7 +++++++ .../validate-ignore-changes-interpolate/main.tf | 7 +++++++ 3 files changed, 28 insertions(+) create mode 100644 config/test-fixtures/validate-ignore-changes-interpolate/main.tf diff --git a/config/config.go b/config/config.go index da2186b37e..3c8f8826d3 100644 --- a/config/config.go +++ b/config/config.go @@ -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 { diff --git a/config/config_test.go b/config/config_test.go index 201a62893e..7c7776b94e 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -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 { diff --git a/config/test-fixtures/validate-ignore-changes-interpolate/main.tf b/config/test-fixtures/validate-ignore-changes-interpolate/main.tf new file mode 100644 index 0000000000..e3b5a87f45 --- /dev/null +++ b/config/test-fixtures/validate-ignore-changes-interpolate/main.tf @@ -0,0 +1,7 @@ +variable "foo" {} + +resource aws_instance "web" { + lifecycle { + ignore_changes = ["${var.foo}"] + } +}