From d164f07fb45ffbf077ee4badb282bce7faeef293 Mon Sep 17 00:00:00 2001 From: djpbessems Date: Wed, 27 Jan 2021 16:54:32 +0100 Subject: [PATCH] Add missing yaml-parse logic --- scripts/Update-OvfConfiguration.ps1 | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts/Update-OvfConfiguration.ps1 b/scripts/Update-OvfConfiguration.ps1 index 1d75895..07908fa 100644 --- a/scripts/Update-OvfConfiguration.ps1 +++ b/scripts/Update-OvfConfiguration.ps1 @@ -22,7 +22,24 @@ $ConvertFromYamlSplat = @{ Yaml = $RawContent AllDocuments = $True } -$OVFConfig = ConvertFrom-Yaml @ConvertFromYamlSplat +$YamlDocuments = ConvertFrom-Yaml @ConvertFromYamlSplat + +# Check if the respective .yml file declared substitutions which need to be parsed +If (($YamlDocuments.Count -gt 1) -and $YamlDocuments[-1].Variables) { + ForEach ($Pattern in $YamlDocuments[-1].Variables) { + $RawContent = $RawContent -replace "\{\{ ($($Pattern.Name)) \}\}", [string](Invoke-Expression -Command $Pattern.Expression) + } + # Perform conversion to Yaml again, now with parsed file contents + $ConvertFromYamlSplat = @{ + Yaml = $RawContent + AllDocuments = $True + } + $YamlDocuments = ConvertFrom-Yaml @ConvertFromYamlSplat + $OVFConfig = $YamlDocuments[0..($YamlDocuments.Count - 2)] +} +Else { + $OVFConfig = $YamlDocuments +} $SourceFile = Get-Item -Path $OVFFile $GetContentSplat = @{