config: validate that count is >= 1

This commit is contained in:
Mitchell Hashimoto 2014-07-26 14:49:55 -07:00
parent 82e7d58250
commit f9f4e62411
4 changed files with 27 additions and 1 deletions

View File

@ -155,8 +155,14 @@ func (c *Config) Validate() error {
}
dupped = nil
// Make sure all dependsOn are valid in resources
// Validate resources
for n, r := range resources {
if r.Count < 1 {
errs = append(errs, fmt.Errorf(
"%s: count must be greater than or equal to 1",
n))
}
for _, d := range r.DependsOn {
if _, ok := resources[d]; !ok {
errs = append(errs, fmt.Errorf(

View File

@ -30,6 +30,20 @@ func TestConfigValidate_badMultiResource(t *testing.T) {
}
}
func TestConfigValidate_countBelowZero(t *testing.T) {
c := testConfig(t, "validate-count-below-zero")
if err := c.Validate(); err == nil {
t.Fatal("should not be valid")
}
}
func TestConfigValidate_countZero(t *testing.T) {
c := testConfig(t, "validate-count-zero")
if err := c.Validate(); err == nil {
t.Fatal("should not be valid")
}
}
func TestConfigValidate_dupResource(t *testing.T) {
c := testConfig(t, "validate-dup-resource")
if err := c.Validate(); err == nil {

View File

@ -0,0 +1,3 @@
resource "aws_instance" "web" {
count = -1
}

View File

@ -0,0 +1,3 @@
resource "aws_instance" "web" {
count = 0
}