From 0e7b150c5bdb0447227ab6b2016711d50c6776bf Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 20 Feb 2015 09:07:41 -0800 Subject: [PATCH] config: depends on cannot contain interpolations [GH-985] --- config/config.go | 11 +++++++++++ config/config_test.go | 7 +++++++ config/test-fixtures/validate-depends-on-var/main.tf | 7 +++++++ 3 files changed, 25 insertions(+) create mode 100644 config/test-fixtures/validate-depends-on-var/main.tf diff --git a/config/config.go b/config/config.go index 0a538449e..8c31b405b 100644 --- a/config/config.go +++ b/config/config.go @@ -379,6 +379,17 @@ func (c *Config) Validate() error { // Verify depends on points to resources that all exist for _, d := range r.DependsOn { + // Check if we contain interpolations + rc, err := NewRawConfig(map[string]interface{}{ + "value": d, + }) + if err == nil && len(rc.Variables) > 0 { + errs = append(errs, fmt.Errorf( + "%s: depends on value cannot contain interpolations: %s", + n, d)) + continue + } + if _, ok := resources[d]; !ok { errs = append(errs, fmt.Errorf( "%s: resource depends on non-existent resource '%s'", diff --git a/config/config_test.go b/config/config_test.go index 5586f60f1..2d7c2675c 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -109,6 +109,13 @@ func TestConfigValidate_countVarInvalid(t *testing.T) { } } +func TestConfigValidate_dependsOnVar(t *testing.T) { + c := testConfig(t, "validate-depends-on-var") + if err := c.Validate(); err == nil { + t.Fatal("should not be valid") + } +} + func TestConfigValidate_dupModule(t *testing.T) { c := testConfig(t, "validate-dup-module") if err := c.Validate(); err == nil { diff --git a/config/test-fixtures/validate-depends-on-var/main.tf b/config/test-fixtures/validate-depends-on-var/main.tf new file mode 100644 index 000000000..482a04f31 --- /dev/null +++ b/config/test-fixtures/validate-depends-on-var/main.tf @@ -0,0 +1,7 @@ +variable "foo" { + description = "bar" +} + +resource aws_instance "web" { + depends_on = ["${var.foo}"] +}