@@ -16,11 +16,15 @@ var replacer *strings.Replacer
1616var varPrefix = "var."
1717var localPrefix = "local."
1818
19- var varTemplate = template .Must (template .New ("var_file" ).Parse (`{{range .}}
20- variable "{{ . }}" {
19+ var varTemplate = template .Must (template .New ("var_file" ).Funcs (template.FuncMap {"sub" : sub }).Parse (`{{- $length := len .Variables -}}
20+ {{- range $i, $v := .Variables -}}
21+ {{ if $.VariablesDescription }}variable "{{ $v }}" {
2122 description = ""
22- }
23- {{end}}` ))
23+ }{{ else }}variable "{{ $v }}" {}{{ end }}
24+ {{- if lt $i (sub $length 1) }}{{ "\n\n" }}{{ end -}}
25+ {{ end -}}{{printf "\n"}}` ))
26+
27+ func sub (a , b int ) int { return a - b }
2428
2529var localsTemplate = template .Must (template .New ("locals_file" ).Parse (`locals { {{ range . }}
2630 {{ . }} ={{ end }}
@@ -44,11 +48,12 @@ func init() {
4448}
4549
4650// Generate will write inputs to file
47- func Generate (tfFiles []string , varsDstFile string , localsDstFile string ) {
51+ func Generate (tfFiles []string , varsDstFile string , localsDstFile string , varsDescription bool ) {
4852 var wg sync.WaitGroup
4953 messages := make (chan string )
5054 wg .Add (len (tfFiles ))
5155 t := & terraformVars {}
56+ t .VariablesDescription = varsDescription
5257
5358 for _ , file := range tfFiles {
5459 go func (file string ) {
@@ -75,7 +80,7 @@ func Generate(tfFiles []string, varsDstFile string, localsDstFile string) {
7580 log .Infof ("Variables are generated to %q file" , varsDstFile )
7681
7782 t .sort (t .Variables )
78- err = varTemplate .Execute (f , t . Variables )
83+ err = varTemplate .Execute (f , t )
7984 utils .CheckError (err )
8085 }
8186
0 commit comments