From 939d045a0bc610aa9c0cad6e6db569039e17ff0e Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 7 Apr 2020 14:18:08 -0400 Subject: [PATCH] don't allow count && for_each --- configs/module_call.go | 9 +++++++++ configs/module_call_test.go | 1 + 2 files changed, 10 insertions(+) diff --git a/configs/module_call.go b/configs/module_call.go index 83d41d5f5..cf6d1acbd 100644 --- a/configs/module_call.go +++ b/configs/module_call.go @@ -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 } diff --git a/configs/module_call_test.go b/configs/module_call_test.go index 0b4b7371f..d1164635e 100644 --- a/configs/module_call_test.go +++ b/configs/module_call_test.go @@ -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