@@ -17,23 +17,71 @@ function Write-TfvarsFile {
1717 foreach ($configurationProperty in $configuration.PSObject.Properties ) {
1818 $configurationValueRaw = $configurationProperty.Value.Value
1919
20- if ($configurationProperty.Value.Validator -eq " configuration_file_path" ) {
20+ if ($configurationProperty.Value.Validator -eq " configuration_file_path" ) {
2121 $configurationValueRaw = [System.IO.Path ]::GetFileName($configurationValueRaw )
2222 }
2323
2424 $configurationValue = " `" $ ( $configurationValueRaw ) `" "
2525
26- if ($configurationProperty.Value.DataType -eq " list(string)" ) {
27- if ($configurationValueRaw -eq " " ) {
28- $configurationValue = " []"
26+ if ($configurationProperty.Value.DataType -eq " list(string)" ) {
27+ if (-not $configurationValueRaw -or $configurationValueRaw.Count -eq 0 ) {
28+ if ($configurationProperty.Value.DefaultValue ) {
29+ $configurationValue = $configurationProperty.Value.DefaultValue
30+ } else {
31+ $configurationValue = " []"
32+ }
2933 } else {
3034 $split = $configurationValueRaw -split " ,"
3135 $join = $split -join " `" ,`" "
3236 $configurationValue = " [`" $join `" ]"
3337 }
3438 }
3539
36- if ($configurationProperty.Value.DataType -eq " number" -or $configurationProperty.Value.DataType -eq " bool" ) {
40+ if ($configurationProperty.Value.DataType -eq " map(string)" ) {
41+ if (-not $configurationValueRaw -or $configurationValueRaw.Count -eq 0 ) {
42+ if ($configurationProperty.Value.DefaultValue ) {
43+ $configurationValue = $configurationProperty.Value.DefaultValue
44+ } else {
45+ $configurationValue = " {}"
46+ }
47+ } else {
48+ $configurationValue = " {"
49+ $entries = @ ()
50+
51+ foreach ($key in $configurationValueRaw.Keys ) {
52+ $value = $configurationValueRaw [$key ]
53+ $entries += " `" $key `" : `" $value `" "
54+ }
55+
56+ $configurationValue = $entries -join " , "
57+ $configurationValue = " { $configurationValue }"
58+ }
59+ }
60+
61+ if ($configurationProperty.Value.DataType -like " list(object*" ) {
62+ if (-not $configurationValueRaw -or $configurationValueRaw.Count -eq 0 ) {
63+ if ($configurationProperty.Value.DefaultValue ) {
64+ $configurationValue = $configurationProperty.Value.DefaultValue
65+ } else {
66+ $configurationValue = " []"
67+ }
68+ } else {
69+ $configurationValue = " ["
70+ foreach ($entry in $configurationValueRaw ) {
71+ $configurationValue += " { "
72+ foreach ($key in $entry.Keys ) {
73+ $value = $entry [$key ]
74+ $configurationValue += " `" $key `" : `" $value `" , "
75+ }
76+ $configurationValue = $configurationValue.TrimEnd (" , " )
77+ $configurationValue += " }, "
78+ }
79+ $configurationValue = $configurationValue.TrimEnd (" , " )
80+ $configurationValue += " ]"
81+ }
82+ }
83+
84+ if ($configurationProperty.Value.DataType -eq " number" -or $configurationProperty.Value.DataType -eq " bool" ) {
3785 $configurationValue = $configurationValueRaw
3886 } else {
3987 $configurationValue = $configurationValue.Replace (" \" , " \\" )
@@ -46,4 +94,4 @@ function Write-TfvarsFile {
4694
4795 terraform - chdir= " $tfvarsFolderPath " fmt | Out-String | Write-Verbose
4896 }
49- }
97+ }
0 commit comments