Merge pull request #1622 from hashicorp/b-self-in-module

config: error in validation if module has self variable [GH-1609]
This commit is contained in:
Mitchell Hashimoto 2015-04-22 15:53:20 +02:00
commit ecc8b9dfc6
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}"
}