config: validate that count vars are valid types
This commit is contained in:
parent
bc26777963
commit
b484ec19b6
|
@ -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{})
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
resource "aws_instance" "foo" {
|
||||
foo = "${count.foo}"
|
||||
}
|
Loading…
Reference in New Issue