config: validate that count vars are valid types

This commit is contained in:
Mitchell Hashimoto 2014-10-02 18:24:37 -07:00
parent bc26777963
commit b484ec19b6
3 changed files with 27 additions and 0 deletions

View File

@ -199,6 +199,23 @@ func (c *Config) Validate() error {
}
}
// Check that all count variables are valid.
for source, vs := range vars {
for _, v := range vs {
cv, ok := v.(*CountVariable)
if !ok {
continue
}
if cv.Type == CountValueInvalid {
errs = append(errs, fmt.Errorf(
"%s: invalid count variable: %s",
source,
cv.FullKey()))
}
}
}
// Check that all references to modules are valid
modules := make(map[string]*Module)
dupped := make(map[string]struct{})

View File

@ -95,6 +95,13 @@ func TestConfigValidate_countUserVar(t *testing.T) {
}
}
func TestConfigValidate_countVarInvalid(t *testing.T) {
c := testConfig(t, "validate-count-var-invalid")
if err := c.Validate(); err == nil {
t.Fatal("should not be valid")
}
}
func TestConfigValidate_dupModule(t *testing.T) {
c := testConfig(t, "validate-dup-module")
if err := c.Validate(); err == nil {

View File

@ -0,0 +1,3 @@
resource "aws_instance" "foo" {
foo = "${count.foo}"
}