Merge pull request #24587 from hashicorp/jbardin/disallow-count-and-foreach
don't allow count && for_each in module calls
This commit is contained in:
commit
2eba39a671
|
@ -71,6 +71,15 @@ func decodeModuleBlock(block *hcl.Block, override bool) (*ModuleCall, hcl.Diagno
|
||||||
}
|
}
|
||||||
|
|
||||||
if attr, exists := content.Attributes["for_each"]; exists {
|
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
|
mc.ForEach = attr.Expr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ func TestLoadModuleCall(t *testing.T) {
|
||||||
file, diags := parser.LoadConfigFile("module-calls.tf")
|
file, diags := parser.LoadConfigFile("module-calls.tf")
|
||||||
assertExactDiagnostics(t, diags, []string{
|
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: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
|
gotModules := file.ModuleCalls
|
||||||
|
|
Loading…
Reference in New Issue