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}" +}