From cca4964552a3141ee7b7ddd215e54616fba37f7e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 22 Apr 2015 10:39:07 +0200 Subject: [PATCH] config: error in validation if module has self variable --- config/config.go | 6 +++++- config/config_test.go | 7 +++++++ config/test-fixtures/validate-module-var-self/main.tf | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 config/test-fixtures/validate-module-var-self/main.tf diff --git a/config/config.go b/config/config.go index 05a25216d..2bdab8947 100644 --- a/config/config.go +++ b/config/config.go @@ -309,9 +309,13 @@ func (c *Config) Validate() error { // Check for invalid count variables for _, v := range m.RawConfig.Variables { - if _, ok := v.(*CountVariable); ok { + switch v.(type) { + case *CountVariable: errs = append(errs, fmt.Errorf( "%s: count variables are only valid within resources", m.Name)) + case *SelfVariable: + errs = append(errs, fmt.Errorf( + "%s: self variables are only valid within resources", m.Name)) } } diff --git a/config/config_test.go b/config/config_test.go index 64b6d6cef..88dbdc6c5 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -175,6 +175,13 @@ func TestConfigValidate_moduleVarMap(t *testing.T) { } } +func TestConfigValidate_moduleVarSelf(t *testing.T) { + c := testConfig(t, "validate-module-var-self") + if err := c.Validate(); err == nil { + t.Fatal("should be invalid") + } +} + func TestConfigValidate_nil(t *testing.T) { var c Config if err := c.Validate(); err != nil { diff --git a/config/test-fixtures/validate-module-var-self/main.tf b/config/test-fixtures/validate-module-var-self/main.tf new file mode 100644 index 000000000..8bec957f4 --- /dev/null +++ b/config/test-fixtures/validate-module-var-self/main.tf @@ -0,0 +1,4 @@ +module "foo" { + source = "./foo" + foo = "${self.bar}" +}