Skip to content

Commit

Permalink
feat: Allow outputs integration into the registry even when output is…
Browse files Browse the repository at this point in the history
… null (#228)

If a module output could be null, the generated integration registry entry would be invalid. This PR adds conditions in the generated HCL to handle this case.
  • Loading branch information
vincenthsh authored Nov 24, 2023
1 parent c71f95c commit 342f880
Show file tree
Hide file tree
Showing 2 changed files with 577 additions and 332 deletions.
27 changes: 15 additions & 12 deletions templates/templates/module-invocation/ssm-parameter-store.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,38 @@
{{- end -}}
{{- if $outer.ModuleForEach }}
{{- if .ForEach }}
for_each = { for output in flatten([
for module_key, module_outputs in module.{{$outer.ModuleName}}: [
for output_key, output_value in module_outputs.{{.Output.Name}}: {
module_key = module_key
output_key = output_key
output_value = output_value
}
]
]): "${output.module_key}/${output.output_key}" => output }
for_each = module.{{$outer.ModuleName}}.{{.Output.Name}} != null ? {
for output in flatten([
for module_key, module_outputs in module.{{$outer.ModuleName}}: [
for output_key, output_value in module_outputs.{{.Output.Name}}: {
module_key = module_key
output_key = output_key
output_value = output_value
}
]
]): "${output.module_key}/${output.output_key}" => output
} : {}
{{- if .PathForEach }}
name = "{{ $fullPath }}/{{ .PathForEach }}/${each.key}"
{{- else }}
name = "{{ $fullPath }}/${each.key}"
{{- end }}
{{- else }}
for_each = { for k, v in module.{{$outer.ModuleName}}:
for_each = module.{{$outer.ModuleName}}.{{.Output.Name}} != null ? { for k, v in module.{{$outer.ModuleName}}:
k => v.{{.Output.Name}}
}
} : {}
name = "{{ $fullPath }}/${each.key}"
{{- end }}
{{- else }}
{{- if .ForEach }}
for_each = module.{{$outer.ModuleName}}.{{.Output.Name}}
for_each = module.{{$outer.ModuleName}}.{{.Output.Name}} != null ? module.{{$outer.ModuleName}}.{{.Output.Name}} : {}
{{- if .PathForEach }}
name = "{{ $fullPath }}/{{ .PathForEach }}/${each.key}"
{{- else }}
name = "{{ $fullPath }}/${each.key}"
{{- end }}
{{- else }}
count = module.{{$outer.ModuleName}}.{{.Output.Name}} != null ? 1 : 0
name = "{{ $fullPath }}"
{{- end }}
{{- end }}
Expand Down
Loading

0 comments on commit 342f880

Please sign in to comment.