don't allow count && for_each

This commit is contained in:
James Bardin 2020-04-07 14:18:08 -04:00
parent 6ec5e0fc88
commit 939d045a0b
2 changed files with 10 additions and 0 deletions

View File

@ -71,6 +71,15 @@ func decodeModuleBlock(block *hcl.Block, override bool) (*ModuleCall, hcl.Diagno
}
if attr, exists := content.Attributes["for_each"]; exists {
if mc.Count != nil {
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: `Invalid combination of "count" and "for_each"`,
Detail: `The "count" and "for_each" meta-arguments are mutually-exclusive, only one should be used to be explicit about the number of resources to be created.`,
Subject: &attr.NameRange,
})
}
mc.ForEach = attr.Expr
}

View File

@ -21,6 +21,7 @@ func TestLoadModuleCall(t *testing.T) {
file, diags := parser.LoadConfigFile("module-calls.tf")
assertExactDiagnostics(t, diags, []string{
`module-calls.tf:22,3-13: Reserved argument name in module block; The name "depends_on" is reserved for use in a future version of Terraform.`,
`module-calls.tf:20,3-11: Invalid combination of "count" and "for_each"; The "count" and "for_each" meta-arguments are mutually-exclusive, only one should be used to be explicit about the number of resources to be created.`,
})
gotModules := file.ModuleCalls