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:
commit
ecc8b9dfc6
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
module "foo" {
|
||||
source = "./foo"
|
||||
foo = "${self.bar}"
|
||||
}
|
Loading…
Reference in New Issue