-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add template to merge multiple subscription configurations (#1560)
* Add template to merge multiple subscription configurations * Update eng/common/TestResources/build-test-resource-config.yml Co-authored-by: Wes Haggard <[email protected]> Co-authored-by: Wes Haggard <[email protected]>
- Loading branch information
1 parent
15c92f7
commit dd7d2ba
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 for merging | ||
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 |