From b368e9aa5ed2fb86da53321e9d0c37893e986dc6 Mon Sep 17 00:00:00 2001 From: Ben Broderick Phillips Date: Thu, 15 Apr 2021 14:29:41 -0400 Subject: [PATCH 1/2] Add template to merge multiple subscription configurations --- .../build-test-resource-config.yml | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 eng/common/TestResources/build-test-resource-config.yml diff --git a/eng/common/TestResources/build-test-resource-config.yml b/eng/common/TestResources/build-test-resource-config.yml new file mode 100644 index 0000000000..271b3227e5 --- /dev/null +++ b/eng/common/TestResources/build-test-resource-config.yml @@ -0,0 +1,65 @@ +parameters: + - name: SubscriptionConfiguration + type: string + default: $(sub-config-azure-cloud-test-resources) + - name: SubscriptionConfigurations + type: object + default: null + +steps: + - ${{ if parameters.SubscriptionConfiguration }}: + - pwsh: | + $config = @' + ${{ parameters.SubscriptionConfiguration }} + '@ | ConvertFrom-Json -AsHashtable + + foreach($pair in $config.GetEnumerator()) { + if ($pair.Value -is [Hashtable]) { + foreach($nestedPair in $pair.Value.GetEnumerator()) { + Write-Host "##vso[task.setvariable variable=$($nestedPair.Name);issecret=true;]$($nestedPair.Value)" + } + } else { + Write-Host "##vso[task.setvariable variable=$($pair.Name);issecret=true;]$($pair.Value)" + } + } + + Write-Host ($config | ConvertTo-Json) + $serialized = $config | ConvertTo-Json -Compress + Write-Host "##vso[task.setvariable variable=SubscriptionConfiguration;]$serialized" + displayName: Initialize SubscriptionConfiguration variable + + - ${{ if parameters.SubscriptionConfigurations }}: + - pwsh: | + Write-Host "##vso[task.setvariable variable=SubscriptionConfiguration;]{}" + displayName: Initialize SubscriptionConfiguration variable + condition: eq(variables['SubscriptionConfiguration'], '') + + - ${{ each config in parameters.SubscriptionConfigurations }}: + - pwsh: | + $config = @' + $(SubscriptionConfiguration) + '@ | ConvertFrom-Json -AsHashtable + $addToConfig = @' + ${{ config }} + '@ | ConvertFrom-Json -AsHashtable + + foreach ($pair in $addToConfig.GetEnumerator()) { + if ($pair.Value -is [Hashtable]) { + if (!$config.ContainsKey($pair.Name)) { + $config[$pair.Name] = @{} + } + foreach($nestedPair in $pair.Value.GetEnumerator()) { + Write-Host "##vso[task.setvariable variable=$($nestedPair.Name);issecret=true;]$($nestedPair.Value)" + $config[$pair.Name][$nestedPair.Name] = $nestedPair.Value + } + } else { + Write-Host "##vso[task.setvariable variable=$($pair.Name);issecret=true;]$($pair.Value)" + $config[$pair.Name] = $pair.Value + } + } + + $serialized = $config | ConvertTo-Json -Compress + Write-Host ($config | ConvertTo-Json) + Write-Host "##vso[task.setvariable variable=SubscriptionConfiguration;]$serialized" + + displayName: Merge Test Resource Configurations From e776fb17c046fbb137e0a9b1251709bb9d31dafa Mon Sep 17 00:00:00 2001 From: Ben Broderick Phillips Date: Fri, 16 Apr 2021 17:14:53 -0400 Subject: [PATCH 2/2] Update eng/common/TestResources/build-test-resource-config.yml Co-authored-by: Wes Haggard --- eng/common/TestResources/build-test-resource-config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/TestResources/build-test-resource-config.yml b/eng/common/TestResources/build-test-resource-config.yml index 271b3227e5..98cdd96f5a 100644 --- a/eng/common/TestResources/build-test-resource-config.yml +++ b/eng/common/TestResources/build-test-resource-config.yml @@ -31,7 +31,7 @@ steps: - ${{ if parameters.SubscriptionConfigurations }}: - pwsh: | Write-Host "##vso[task.setvariable variable=SubscriptionConfiguration;]{}" - displayName: Initialize SubscriptionConfiguration variable + displayName: Initialize SubscriptionConfiguration variable for merging condition: eq(variables['SubscriptionConfiguration'], '') - ${{ each config in parameters.SubscriptionConfigurations }}: