Skip to content

Commit 37b3dad

Browse files
Add ResourceType parameter - Selects live test or perf test resources (Azure#18431)
Co-authored-by: Mike Harder <mharder@microsoft.com>
1 parent f2e008d commit 37b3dad

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

eng/common/TestResources/New-TestResources.ps1

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ param (
6363
[ValidateSet('AzureCloud', 'AzureUSGovernment', 'AzureChinaCloud', 'Dogfood')]
6464
[string] $Environment = 'AzureCloud',
6565

66+
[Parameter()]
67+
[ValidateSet('test', 'perf')]
68+
[string] $ResourceType = 'test',
69+
6670
[Parameter()]
6771
[hashtable] $ArmTemplateParameters,
6872

@@ -223,7 +227,7 @@ function BuildBicepFile([System.IO.FileSystemInfo] $file)
223227
}
224228

225229
$tmp = $env:TEMP ? $env:TEMP : [System.IO.Path]::GetTempPath()
226-
$templateFilePath = Join-Path $tmp "test-resources.$(New-Guid).compiled.json"
230+
$templateFilePath = Join-Path $tmp "$ResourceType-resources.$(New-Guid).compiled.json"
227231

228232
# Az can deploy bicep files natively, but by compiling here it becomes easier to parse the
229233
# outputted json for mismatched parameter declarations.
@@ -349,7 +353,7 @@ try {
349353
$root = [System.IO.Path]::Combine($repositoryRoot, "sdk", $ServiceDirectory) | Resolve-Path
350354
$templateFiles = @()
351355

352-
'test-resources.json', 'test-resources.bicep' | ForEach-Object {
356+
"$ResourceType-resources.json", "$ResourceType-resources.bicep" | ForEach-Object {
353357
Write-Verbose "Checking for '$_' files under '$root'"
354358
Get-ChildItem -Path $root -Filter "$_" -Recurse | ForEach-Object {
355359
Write-Verbose "Found template '$($_.FullName)'"
@@ -586,9 +590,9 @@ try {
586590
# Service principals in the Microsoft AAD tenant must end with an @microsoft.com domain; those in other tenants
587591
# are not permitted to do so. Format the non-MS name so there's an assocation with the Azure SDK.
588592
if ($TenantId -eq '72f988bf-86f1-41af-91ab-2d7cd011db47') {
589-
$displayName = "test-resources-$($baseName)$suffix.microsoft.com"
593+
$displayName = "$ResourceType-resources-$($baseName)$suffix.microsoft.com"
590594
} else {
591-
$displayName = "$($baseName)$suffix.test-resources.azure.sdk"
595+
$displayName = "$($baseName)$suffix.$ResourceType-resources.azure.sdk"
592596
}
593597

594598
$servicePrincipalWrapper = NewServicePrincipalWrapper -subscription $SubscriptionId -resourceGroup $ResourceGroupName -displayName $DisplayName
@@ -705,7 +709,7 @@ try {
705709
}
706710
}
707711

708-
$preDeploymentScript = $templateFile.originalFilePath | Split-Path | Join-Path -ChildPath 'test-resources-pre.ps1'
712+
$preDeploymentScript = $templateFile.originalFilePath | Split-Path | Join-Path -ChildPath "$ResourceType-resources-pre.ps1"
709713
if (Test-Path $preDeploymentScript) {
710714
Log "Invoking pre-deployment script '$preDeploymentScript'"
711715
&$preDeploymentScript -ResourceGroupName $ResourceGroupName @PSBoundParameters
@@ -745,7 +749,7 @@ try {
745749

746750
$deploymentOutputs = SetDeploymentOutputs $serviceName $context $deployment $templateFile
747751

748-
$postDeploymentScript = $templateFile.originalFilePath | Split-Path | Join-Path -ChildPath 'test-resources-post.ps1'
752+
$postDeploymentScript = $templateFile.originalFilePath | Split-Path | Join-Path -ChildPath "$ResourceType-resources-post.ps1"
749753
if (Test-Path $postDeploymentScript) {
750754
Log "Invoking post-deployment script '$postDeploymentScript'"
751755
&$postDeploymentScript -ResourceGroupName $ResourceGroupName -DeploymentOutputs $deploymentOutputs @PSBoundParameters

eng/common/TestResources/Remove-TestResources.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ param (
5252
[Parameter(ParameterSetName = 'ResourceGroup+Provisioner')]
5353
[switch] $CI,
5454

55+
[Parameter()]
56+
[ValidateSet('test', 'perf')]
57+
[string] $ResourceType = 'test',
58+
5559
[Parameter()]
5660
[switch] $Force,
5761

@@ -198,7 +202,7 @@ Log "Selected subscription '$subscriptionName'"
198202

199203
if ($ServiceDirectory) {
200204
$root = [System.IO.Path]::Combine("$PSScriptRoot/../../../sdk", $ServiceDirectory) | Resolve-Path
201-
$preRemovalScript = Join-Path -Path $root -ChildPath 'remove-test-resources-pre.ps1'
205+
$preRemovalScript = Join-Path -Path $root -ChildPath "remove-$ResourceType-resources-pre.ps1"
202206
if (Test-Path $preRemovalScript) {
203207
Log "Invoking pre resource removal script '$preRemovalScript'"
204208

@@ -210,7 +214,7 @@ if ($ServiceDirectory) {
210214
}
211215

212216
# Make sure environment files from New-TestResources -OutFile are removed.
213-
Get-ChildItem -Path $root -Filter test-resources.json.env -Recurse | Remove-Item -Force:$Force
217+
Get-ChildItem -Path $root -Filter "$ResourceType-resources.json.env" -Recurse | Remove-Item -Force:$Force
214218
}
215219

216220
$verifyDeleteScript = {

eng/common/TestResources/deploy-test-resources.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ parameters:
44
DeleteAfterHours: 8
55
Location: ''
66
SubscriptionConfiguration: $(sub-config-azure-cloud-test-resources)
7+
ResourceType: test
78

89
# SubscriptionConfiguration will be splatted into the parameters of the test
910
# resources script. It should be JSON in the form:
@@ -48,6 +49,7 @@ steps:
4849
# pass those in via the ArmTemplateParameters flag, and handle any
4950
# additional parameters from the pipelines via AdditionalParameters
5051
eng/common/TestResources/New-TestResources.ps1 `
52+
-ResourceType '${{ parameters.ResourceType }}' `
5153
-ServiceDirectory '${{ parameters.ServiceDirectory }}' `
5254
-Location '${{ parameters.Location }}' `
5355
-DeleteAfterHours '${{ parameters.DeleteAfterHours }}' `

eng/common/TestResources/remove-test-resources.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
parameters:
55
ServiceDirectory: ''
66
SubscriptionConfiguration: $(sub-config-azure-cloud-test-resources)
7+
ResourceType: test
78

89
# SubscriptionConfiguration will be splat into the parameters of the test
910
# resources script. It should be JSON in the form:
@@ -29,6 +30,7 @@ steps:
2930
3031
eng/common/TestResources/Remove-TestResources.ps1 `
3132
@subscriptionConfiguration `
33+
-ResourceType '${{ parameters.ResourceType }}' `
3234
-ServiceDirectory "${{ parameters.ServiceDirectory }}" `
3335
-CI `
3436
-Force `

0 commit comments

Comments
 (0)