-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathConvert-HCLVariablesToInputConfig.ps1
More file actions
50 lines (38 loc) · 1.98 KB
/
Convert-HCLVariablesToInputConfig.ps1
File metadata and controls
50 lines (38 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function Convert-HCLVariablesToInputConfig {
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[Parameter(Mandatory = $false)]
[string] $targetVariableFile,
[Parameter(Mandatory = $false)]
[string] $hclParserToolPath,
[Parameter(Mandatory = $false)]
[PSCustomObject]$appendToObject = $null
)
if ($PSCmdlet.ShouldProcess("Parse HCL Variables into Config", "modify")) {
$terraformVariables = & $hclParserToolPath $targetVariableFile | ConvertFrom-Json
if ($terraformVariables.PSObject.Properties.Name -notcontains "variable") {
Write-Verbose "No variables found in $targetVariableFile, skipping..."
return $appendToObject
}
Write-Verbose "Variables found in $targetVariableFile, processing..."
$configItems = [PSCustomObject]@{}
if ($appendToObject -ne $null) {
$configItems = $appendToObject
}
foreach ($variable in $terraformVariables.variable.PSObject.Properties) {
if ($variable.Value[0].PSObject.Properties.Name -contains "description") {
$description = $variable.Value[0].description
}
$configItem = [PSCustomObject]@{}
$configItem | Add-Member -NotePropertyName "Value" -NotePropertyValue ""
$configItem | Add-Member -NotePropertyName "Source" -NotePropertyValue "input"
if ($variable.Value[0].PSObject.Properties.Name -contains "default") {
$configItem | Add-Member -NotePropertyName "DefaultValue" -NotePropertyValue $variable.Value[0].default
}
$configItem | Add-Member -NotePropertyName "Description" -NotePropertyValue $description
Write-Verbose "Adding variable $($variable.Name) to the configuration..."
$configItems | Add-Member -NotePropertyName $variable.Name -NotePropertyValue $configItem
}
}
return $configItems
}