From 4dad8fe78335514dee4610f8bf097c1acc49e5ed Mon Sep 17 00:00:00 2001 From: osherElm <52105667+osherElm@users.noreply.github.com> Date: Wed, 24 May 2023 11:43:05 +0300 Subject: [PATCH] fix: changing len to 0 for empty maps (#42) Co-authored-by: osher.elmakaies --- internal/services/templates/locals_file.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/templates/locals_file.tmpl b/internal/services/templates/locals_file.tmpl index 4f67db8..4a6d964 100644 --- a/internal/services/templates/locals_file.tmpl +++ b/internal/services/templates/locals_file.tmpl @@ -9,7 +9,7 @@ locals{ {{range $moduleName,$moduleData := .Module}} {{$localName}} = coalesce(var.{{$moduleName}}.{{$localName}},{{$localValue}}) {{end}}{{end}} {{define "typeMapLocalBlock"}} {{$moduleData := .ModuleData}} {{$moduleName := .ModuleName}}{{range $mapKey,$mapValue := $moduleData.MapLocals}} -{{$tempLen := len $mapValue }}{{if eq $tempLen 1}} {{$mapKey}} = var.{{$moduleName}}.{{$mapKey}} != null ? var.{{$moduleName}}.{{$mapKey}}:{} {{else}} +{{$tempLen := len $mapValue }}{{if eq $tempLen 0}} {{$mapKey}} = var.{{$moduleName}}.{{$mapKey}} != null ? var.{{$moduleName}}.{{$mapKey}}:{} {{else}} {{$mapKey}} = var.{{$moduleName}}.{{$mapKey}} != null ? merge(var.{{$moduleName}}.{{$mapKey}}, tomap({ {{range $propertyName, $propertyValue := $mapValue}} {{$propertyName}} = contains(keys(var.{{$moduleName}}.{{$mapKey}}),{{$propertyName}}) != false ? var.{{$moduleName}}.{{$mapKey}}[{{$propertyName}}] : {{$propertyValue}}{{end}}}