Skip to content

Commit f249ed8

Browse files
committed
Add logic for map of strings and list of objects
1 parent dbef58c commit f249ed8

1 file changed

Lines changed: 21 additions & 17 deletions

File tree

src/ALZ/Private/Config-Helpers/Write-TfvarsFile.ps1

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,33 @@ 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

2626
if ($configurationProperty.Value.DataType -eq "list(string)") {
27-
if ($configurationValueRaw -eq "") {
28-
$configurationValue = "[]"
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
}
34-
Write-Host "list(string) - Raw Value: $configurationValueRaw"
3538
}
3639

3740
if ($configurationProperty.Value.DataType -eq "map(string)") {
3841
if (-not $configurationValueRaw -or $configurationValueRaw.Count -eq 0) {
39-
$configurationValue = "{}"
42+
if ($configurationProperty.Value.DefaultValue) {
43+
$configurationValue = $configurationProperty.Value.DefaultValue
44+
} else {
45+
$configurationValue = "{}"
46+
}
4047
} else {
4148
$configurationValue = "{"
4249
$entries = @()
@@ -49,21 +56,21 @@ function Write-TfvarsFile {
4956
$configurationValue = $entries -join ", "
5057
$configurationValue = "{ $configurationValue }"
5158
}
52-
Write-Host "map(string) - Processed Value: $configurationValue"
5359
}
5460

55-
if ($configurationProperty.Value.DataType -eq "list(object)") {
56-
if ($configurationValueRaw -eq "") {
57-
$configurationValue = "[]"
58-
} elseif ($configurationValueRaw -eq "[]") {
59-
$configurationValue = "[]"
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+
}
6068
} else {
6169
$configurationValue = "["
6270
foreach ($entry in $configurationValueRaw) {
6371
$configurationValue += "{ "
64-
foreach ($keyValue in $entry.PSObject.Properties) {
65-
$key = $keyValue.Name
66-
$value = $keyValue.Value
72+
foreach ($key in $entry.Keys) {
73+
$value = $entry[$key]
6774
$configurationValue += "`"$key`": `"$value`", "
6875
}
6976
$configurationValue = $configurationValue.TrimEnd(", ")
@@ -72,11 +79,8 @@ function Write-TfvarsFile {
7279
$configurationValue = $configurationValue.TrimEnd(", ")
7380
$configurationValue += "]"
7481
}
75-
Write-Host "list(object) - Raw Value: $configurationValueRaw"
76-
Write-Host "list(object) - Processed Value: $configurationValue"
7782
}
7883

79-
8084
if ($configurationProperty.Value.DataType -eq "number" -or $configurationProperty.Value.DataType -eq "bool") {
8185
$configurationValue = $configurationValueRaw
8286
} else {

0 commit comments

Comments
 (0)