mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
config: validate that count is >= 1
This commit is contained in:
parent
82e7d58250
commit
f9f4e62411
@ -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(
|
||||
|
@ -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 {
|
||||
|
3
config/test-fixtures/validate-count-below-zero/main.tf
Normal file
3
config/test-fixtures/validate-count-below-zero/main.tf
Normal file
@ -0,0 +1,3 @@
|
||||
resource "aws_instance" "web" {
|
||||
count = -1
|
||||
}
|
3
config/test-fixtures/validate-count-zero/main.tf
Normal file
3
config/test-fixtures/validate-count-zero/main.tf
Normal file
@ -0,0 +1,3 @@
|
||||
resource "aws_instance" "web" {
|
||||
count = 0
|
||||
}
|
Loading…
Reference in New Issue
Block a user