Skip to content

Commit 167264d

Browse files
authored
Sync eng/common directory with azure-sdk-tools repository (#11469)
1 parent f377d1c commit 167264d

File tree

4 files changed

+62
-132
lines changed

4 files changed

+62
-132
lines changed

eng/common/TestResources/New-TestResources.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ if ($ProvisionerApplicationId) {
156156
}
157157

158158
$provisionerAccount = Retry {
159-
Connect-AzAccount -Tenant $TenantId -Credential $provisionerCredential -ServicePrincipal -Environment $Environment @subscriptionArgs
159+
Connect-AzAccount -Force:$Force -Tenant $TenantId -Credential $provisionerCredential -ServicePrincipal -Environment $Environment @subscriptionArgs
160160
}
161161

162162
$exitActions += {

eng/common/TestResources/Remove-TestResources.ps1

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ param (
4747
[string] $Environment = 'AzureCloud',
4848

4949
[Parameter()]
50-
[switch] $Force
50+
[switch] $Force,
51+
52+
# Captures any arguments not declared here (no parameter errors)
53+
[Parameter(ValueFromRemainingArguments = $true)]
54+
$RemoveTestResourcesRemainingArguments
5155
)
5256

5357
# By default stop for any error.
@@ -105,7 +109,7 @@ if ($ProvisionerApplicationId) {
105109
}
106110

107111
$provisionerAccount = Retry {
108-
Connect-AzAccount -Tenant $TenantId -Credential $provisionerCredential -ServicePrincipal -Environment $Environment @subscriptionArgs
112+
Connect-AzAccount -Force:$Force -Tenant $TenantId -Credential $provisionerCredential -ServicePrincipal -Environment $Environment @subscriptionArgs
109113
}
110114

111115
$exitActions += {
@@ -143,54 +147,40 @@ $exitActions.Invoke()
143147
<#
144148
.SYNOPSIS
145149
Deletes the resource group deployed for a service directory from Azure.
146-
147150
.DESCRIPTION
148151
Removes a resource group and all its resources previously deployed using
149152
New-TestResources.ps1.
150-
151153
If you are not currently logged into an account in the Az PowerShell module,
152154
you will be asked to log in with Connect-AzAccount. Alternatively, you (or a
153155
build pipeline) can pass $ProvisionerApplicationId and
154156
$ProvisionerApplicationSecret to authenticate a service principal with access to
155157
create resources.
156-
157158
.PARAMETER BaseName
158159
A name to use in the resource group and passed to the ARM template as 'baseName'.
159160
This will delete the resource group named 'rg-<baseName>'
160-
161161
.PARAMETER ResourceGroupName
162162
The name of the resource group to delete.
163-
164163
.PARAMETER TenantId
165164
The tenant ID of a service principal when a provisioner is specified.
166-
167165
.PARAMETER SubscriptionId
168166
Optional subscription ID to use for new resources when logging in as a
169167
provisioner. You can also use Set-AzContext if not provisioning.
170-
171168
.PARAMETER ProvisionerApplicationId
172169
A service principal ID to provision test resources when a provisioner is specified.
173-
174170
.PARAMETER ProvisionerApplicationSecret
175171
A service principal secret (password) to provision test resources when a provisioner is specified.
176-
177172
.PARAMETER ServiceDirectory
178173
A directory under 'sdk' in the repository root - optionally with subdirectories
179174
specified - in which to discover pre removal script named 'remove-test-resources-pre.json'.
180-
181175
.PARAMETER Environment
182176
Name of the cloud environment. The default is the Azure Public Cloud
183177
('PublicCloud')
184-
185178
.PARAMETER Force
186179
Force removal of resource group without asking for user confirmation
187-
188180
.EXAMPLE
189181
Remove-TestResources.ps1 -BaseName 'uuid123' -Force
190-
191182
Use the currently logged-in account to delete the resource group by the name of
192183
'rg-uuid123'
193-
194184
.EXAMPLE
195185
Remove-TestResources.ps1 `
196186
-ResourceGroupName "${env:AZURE_RESOURCEGROUP_NAME}" `
@@ -199,11 +189,9 @@ Remove-TestResources.ps1 `
199189
-ProvisionerApplicationSecret '$(AppSecret)' `
200190
-Force `
201191
-Verbose `
202-
203192
When run in the context of an Azure DevOps pipeline, this script removes the
204193
resource group whose name is stored in the environment variable
205194
AZURE_RESOURCEGROUP_NAME.
206-
207195
.LINK
208196
New-TestResources.ps1
209-
#>
197+
#>
Lines changed: 28 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,40 @@
1-
# Deploys resources to a cloud type specified by the variable (not parameter)
2-
# 'CloudType'. Use this as part of a matrix to deploy resources to a particular
3-
# cloud instance. Normally we would use template parameters instead of variables
4-
# but matrix variables are not available during template expansion so any
5-
# benefits of parameters are lost.
6-
71
parameters:
82
ServiceDirectory: not-set
93
ArmTemplateParameters: '@{}'
104
DeleteAfterHours: 24
115
Location: ''
6+
SubscriptionConfiguration: $(sub-config-azure-cloud-test-resources)
7+
8+
# SubscriptionConfiguration will be splat into the parameters of the test
9+
# resources script. It should be JSON in the form:
10+
# {
11+
# "SubscriptionId": "<subscription id>",
12+
# "TenantId": "<tenant id>",
13+
# "TestApplicationId": "<test app id>",
14+
# "TestApplicationSecret": "<test app secret>",
15+
# "ProvisionerApplicationId": "<provisoner app id>",
16+
# "ProvisoinerApplicationSecret": "<provisoner app secert>",
17+
# "Environment": "AzureCloud | AzureGov | AzureChina | <other environment>"
18+
# }
1219

1320
steps:
1421
# New-TestResources command requires Az module
1522
- pwsh: Install-Module -Name Az -Scope CurrentUser -AllowClobber -Force -Verbose
1623
displayName: Install Azure PowerShell module
1724

18-
- pwsh: >
19-
eng/common/TestResources/New-TestResources.ps1
20-
-BaseName 'Generated'
21-
-ServiceDirectory '${{ parameters.ServiceDirectory }}'
22-
-TenantId '$(aad-azure-sdk-test-tenant-id)'
23-
-SubscriptionId '$(azure-subscription-id)'
24-
-TestApplicationId '$(aad-azure-sdk-test-client-id)'
25-
-TestApplicationSecret '$(aad-azure-sdk-test-client-secret)'
26-
-ProvisionerApplicationId '$(aad-azure-sdk-test-client-id)'
27-
-ProvisionerApplicationSecret '$(aad-azure-sdk-test-client-secret)'
28-
-AdditionalParameters ${{ parameters.ArmTemplateParameters }}
29-
-DeleteAfterHours ${{ parameters.DeleteAfterHours }}
30-
-Location '${{ parameters.Location }}'
31-
-Environment 'AzureCloud'
32-
-CI
33-
-Force
34-
-Verbose
35-
displayName: Deploy test resources (AzureCloud)
36-
condition: and(succeeded(), eq(variables['CloudType'], 'AzureCloud'))
37-
38-
- pwsh: >
39-
eng/common/TestResources/New-TestResources.ps1
40-
-BaseName 'Generated'
41-
-ServiceDirectory '${{ parameters.ServiceDirectory }}'
42-
-TenantId '$(aad-azure-sdk-test-tenant-id-gov)'
43-
-SubscriptionId '$(azure-subscription-id-gov)'
44-
-TestApplicationId '$(aad-azure-sdk-test-client-id-gov)'
45-
-TestApplicationSecret '$(aad-azure-sdk-test-client-secret-gov)'
46-
-ProvisionerApplicationId '$(aad-azure-sdk-test-client-id-gov)'
47-
-ProvisionerApplicationSecret '$(aad-azure-sdk-test-client-secret-gov)'
48-
-AdditionalParameters ${{ parameters.ArmTemplateParameters }}
49-
-DeleteAfterHours ${{ parameters.DeleteAfterHours }}
50-
-Location '${{ parameters.Location }}'
51-
-Environment 'AzureUSGovernment'
52-
-CI
53-
-Force
54-
-Verbose
55-
displayName: Deploy test resources (AzureUSGovernment)
56-
condition: and(succeeded(), eq(variables['CloudType'], 'AzureUSGovernment'))
25+
- pwsh: |
26+
$subscriptionConfiguration = @"
27+
${{ parameters.SubscriptionConfiguration }}
28+
"@ | ConvertFrom-Json -AsHashtable;
5729
58-
- pwsh: >
59-
eng/common/TestResources/New-TestResources.ps1
60-
-BaseName 'Generated'
61-
-ServiceDirectory '${{ parameters.ServiceDirectory }}'
62-
-TenantId '$(aad-azure-sdk-test-tenant-id-cn)'
63-
-SubscriptionId '$(azure-subscription-id-cn)'
64-
-TestApplicationId '$(aad-azure-sdk-test-client-id-cn)'
65-
-TestApplicationSecret '$(aad-azure-sdk-test-client-secret-cn)'
66-
-ProvisionerApplicationId '$(aad-azure-sdk-test-client-id-cn)'
67-
-ProvisionerApplicationSecret '$(aad-azure-sdk-test-client-secret-cn)'
68-
-AdditionalParameters ${{ parameters.ArmTemplateParameters }}
69-
-DeleteAfterHours ${{ parameters.DeleteAfterHours }}
70-
-Location '${{ parameters.Location }}'
71-
-Environment 'AzureChinaCloud'
72-
-CI
73-
-Force
74-
-Verbose
75-
displayName: Deploy test resources (AzureChinaCloud)
76-
condition: and(succeeded(), eq(variables['CloudType'], 'AzureChinaCloud'))
30+
eng/common/TestResources/New-TestResources.ps1 `
31+
-BaseName 'Generated' `
32+
-ServiceDirectory ${{ parameters.ServiceDirectory }} `
33+
-Location '${{ parameters.Location }}' `
34+
-DeleteAfterHours ${{ parameters.DeleteAfterHours }} `
35+
-AdditionalParameters ${{ parameters.ArmTemplateParameters }} `
36+
@subscriptionConfiguration `
37+
-CI `
38+
-Force `
39+
-Verbose
40+
displayName: Deploy test resources
Lines changed: 26 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,35 @@
1-
# Removes resources from a cloud type specified by the variable (not parameter)
2-
# 'CloudType'. Use this as part of a matrix to remove resources from a
3-
# particular cloud instance. Normally we would use template variables instead of
4-
# parameters but matrix variables are not available during template expansion
5-
# so any benefits of parameters are lost.
6-
71
# Assumes steps in deploy-test-resources.yml was run previously. Requires
82
# environment variable: AZURE_RESOURCEGROUP_NAME and Az PowerShell module
93

104
parameters:
115
ServiceDirectory: ''
6+
SubscriptionConfiguration: $(sub-config-azure-cloud-test-resources)
127

13-
steps:
14-
- pwsh: >
15-
eng/common/TestResources/Remove-TestResources.ps1
16-
-ResourceGroupName "${env:AZURE_RESOURCEGROUP_NAME}"
17-
-TenantId '$(aad-azure-sdk-test-tenant-id)'
18-
-SubscriptionId '$(azure-subscription-id)'
19-
-ProvisionerApplicationId '$(aad-azure-sdk-test-client-id)'
20-
-ProvisionerApplicationSecret '$(aad-azure-sdk-test-client-secret)'
21-
-ServiceDirectory '${{ parameters.ServiceDirectory }}'
22-
-Environment 'AzureCloud'
23-
-Force
24-
-Verbose
25-
displayName: Remove test resources (AzureCloud)
26-
condition: and(ne(variables['AZURE_RESOURCEGROUP_NAME'], ''), eq(variables['CloudType'], 'AzureCloud'))
27-
continueOnError: true
8+
# SubscriptionConfiguration will be splat into the parameters of the test
9+
# resources script. It should be JSON in the form:
10+
# {
11+
# "SubscriptionId": "<subscription id>",
12+
# "TenantId": "<tenant id>",
13+
# "TestApplicationId": "<test app id>",
14+
# "TestApplicationSecret": "<test app secret>",
15+
# "ProvisionerApplicationId": "<provisoner app id>",
16+
# "ProvisoinerApplicationSecret": "<provisoner app secert>",
17+
# "Environment": "AzureCloud | AzureGov | AzureChina | <other environment>"
18+
# }
19+
# The Remove-TestResources.ps1 script accommodates extra parameters so it will
20+
# not error when parameters are provided which the script doesn't use.
2821

29-
- pwsh: >
30-
eng/common/TestResources/Remove-TestResources.ps1
31-
-ResourceGroupName "${env:AZURE_RESOURCEGROUP_NAME}"
32-
-TenantId '$(aad-azure-sdk-test-tenant-id-gov)'
33-
-SubscriptionId '$(azure-subscription-id-gov)'
34-
-ProvisionerApplicationId '$(aad-azure-sdk-test-client-id-gov)'
35-
-ProvisionerApplicationSecret '$(aad-azure-sdk-test-client-secret-gov)'
36-
-ServiceDirectory '${{ parameters.ServiceDirectory }}'
37-
-Environment 'AzureUSGovernment'
38-
-Force
39-
-Verbose
40-
displayName: Remove test resources (AzureUSGovernment)
41-
condition: and(ne(variables['AZURE_RESOURCEGROUP_NAME'], ''), eq(variables['CloudType'], 'AzureUSGovernment'))
42-
continueOnError: true
22+
steps:
23+
- pwsh: |
24+
$subscriptionConfiguration = @"
25+
${{ parameters.SubscriptionConfiguration }}
26+
"@ | ConvertFrom-Json -AsHashtable;
4327
44-
- pwsh: >
45-
eng/common/TestResources/Remove-TestResources.ps1
46-
-ResourceGroupName "${env:AZURE_RESOURCEGROUP_NAME}"
47-
-TenantId '$(aad-azure-sdk-test-tenant-id-cn)'
48-
-SubscriptionId '$(azure-subscription-id-cn)'
49-
-ProvisionerApplicationId '$(aad-azure-sdk-test-client-id-cn)'
50-
-ProvisionerApplicationSecret '$(aad-azure-sdk-test-client-secret-cn)'
51-
-ServiceDirectory '${{ parameters.ServiceDirectory }}'
52-
-Environment 'AzureChinaCloud'
53-
-Force
54-
-Verbose
55-
displayName: Remove test resources (AzureChinaCloud)
56-
condition: and(ne(variables['AZURE_RESOURCEGROUP_NAME'], ''), eq(variables['CloudType'], 'AzureChinaCloud'))
28+
eng/common/TestResources/Remove-TestResources.ps1 `
29+
-ResourceGroupName "${env:AZURE_RESOURCEGROUP_NAME}" `
30+
-ServiceDirectory ${{ parameters.ServiceDirectory }} `
31+
@subscriptionConfiguration `
32+
-Force `
33+
-Verbose
34+
displayName: Remove test resources
5735
continueOnError: true

0 commit comments

Comments
 (0)