config: validate that module source can't contain interpolations

This commit is contained in:
Mitchell Hashimoto 2014-10-07 20:19:32 -07:00
parent 28cd738edc
commit c1fa4c2e4b
3 changed files with 28 additions and 0 deletions

View File

@ -220,6 +220,7 @@ func (c *Config) Validate() error {
modules := make(map[string]*Module)
dupped := make(map[string]struct{})
for _, m := range c.Modules {
// Check for duplicates
if _, ok := modules[m.Id()]; ok {
if _, ok := dupped[m.Id()]; !ok {
dupped[m.Id()] = struct{}{}
@ -230,6 +231,23 @@ func (c *Config) Validate() error {
}
}
// If we haven't seen this module before, check that the
// source has no interpolations.
if _, ok := modules[m.Id()]; !ok {
rc, err := NewRawConfig(map[string]interface{}{
"root": m.Source,
})
if err != nil {
errs = append(errs, fmt.Errorf(
"%s: module source error: %s",
m.Id(), err))
} else if len(rc.Interpolations) > 0 {
errs = append(errs, fmt.Errorf(
"%s: module source cannot contain interpolations",
m.Id()))
}
}
modules[m.Id()] = m
}
dupped = nil

View File

@ -123,6 +123,13 @@ func TestConfigValidate_dupResource(t *testing.T) {
}
}
func TestConfigValidate_moduleSourceVar(t *testing.T) {
c := testConfig(t, "validate-module-source-var")
if err := c.Validate(); err == nil {
t.Fatal("should not be valid")
}
}
func TestConfigValidate_nil(t *testing.T) {
var c Config
if err := c.Validate(); err != nil {

View File

@ -0,0 +1,3 @@
module "foo" {
source = "${path.cwd}/foo"
}