config: error in validation if module has self variable

This commit is contained in:
Mitchell Hashimoto 2015-04-22 10:39:07 +02:00
parent 5f4e2d9b27
commit cca4964552
3 changed files with 16 additions and 1 deletions

View File

@ -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))
}
}

View File

@ -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 {

View File

@ -0,0 +1,4 @@
module "foo" {
source = "./foo"
foo = "${self.bar}"
}