diff --git a/config/config.go b/config/config.go index fae135dec..e6cd2a8c3 100644 --- a/config/config.go +++ b/config/config.go @@ -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 diff --git a/config/config_test.go b/config/config_test.go index e4892a277..f5208b032 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -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 { diff --git a/config/test-fixtures/validate-module-source-var/main.tf b/config/test-fixtures/validate-module-source-var/main.tf new file mode 100644 index 000000000..ee3bda608 --- /dev/null +++ b/config/test-fixtures/validate-module-source-var/main.tf @@ -0,0 +1,3 @@ +module "foo" { + source = "${path.cwd}/foo" +}