Skip to content

Commit a2ae8e0

Browse files
Sync eng/common directory with azure-sdk-tools for PR 7580 (#33993)
* Support creating resources with user auth * Log warning if TestApplicationId is set * missing space * regenerate md file * Rename * Update link --------- Co-authored-by: jolov <[email protected]>
1 parent d8ce519 commit a2ae8e0

File tree

2 files changed

+141
-12
lines changed

2 files changed

+141
-12
lines changed

eng/common/TestResources/New-TestResources.ps1

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ param (
9292
[Parameter()]
9393
[switch] $SuppressVsoCommands = ($null -eq $env:SYSTEM_TEAMPROJECTID),
9494

95+
[Parameter()]
96+
[switch] $UserAuth,
97+
9598
# Captures any arguments not declared here (no parameter errors)
9699
# This enables backwards compatibility with old script versions in
97100
# hotfix branches if and when the dynamic subscription configuration
@@ -611,8 +614,17 @@ try {
611614
}
612615
}
613616

617+
if ($UserAuth) {
618+
if ($TestApplicationId) {
619+
Write-Warning "The specified TestApplicationId '$TestApplicationId' will be ignored when UserAuth is set."
620+
}
621+
622+
$TestApplicationOid = (Get-AzADUser -UserPrincipalName (Get-AzContext).Account).Id
623+
$TestApplicationId = $testApplicationOid
624+
Log "User-based app id '$TestApplicationId' will be used."
625+
}
614626
# If no test application ID was specified during an interactive session, create a new service principal.
615-
if (!$CI -and !$TestApplicationId) {
627+
elseif (!$CI -and !$TestApplicationId) {
616628
# Cache the created service principal in this session for frequent reuse.
617629
$servicePrincipal = if ($AzureTestPrincipal -and (Get-AzADServicePrincipal -ApplicationId $AzureTestPrincipal.AppId) -and $AzureTestSubscription -eq $SubscriptionId) {
618630
Log "TestApplicationId was not specified; loading cached service principal '$($AzureTestPrincipal.AppId)'"
@@ -1001,6 +1013,14 @@ The environment file will be named for the test resources template that it was
10011013
generated for. For ARM templates, it will be test-resources.json.env. For
10021014
Bicep templates, test-resources.bicep.env.
10031015
1016+
.PARAMETER UserAuth
1017+
Create the resource group and deploy the template using the signed in user's credentials.
1018+
No service principal will be created or used.
1019+
1020+
The environment file will be named for the test resources template that it was
1021+
generated for. For ARM templates, it will be test-resources.json.env. For
1022+
Bicep templates, test-resources.bicep.env.
1023+
10041024
.PARAMETER SuppressVsoCommands
10051025
By default, the -CI parameter will print out secrets to logs with Azure Pipelines log
10061026
commands that cause them to be redacted. For CI environments that don't support this (like

eng/common/TestResources/New-TestResources.ps1.md

Lines changed: 120 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,25 @@ Deploys live test resources defined for a service directory to Azure.
1515
### Default (Default)
1616
```
1717
New-TestResources.ps1 [-BaseName <String>] [-ResourceGroupName <String>] [-ServiceDirectory] <String>
18-
[-TestApplicationId <String>] [-TestApplicationSecret <String>] [-TestApplicationOid <String>]
19-
[-SubscriptionId <String>] [-DeleteAfterHours <Int32>] [-Location <String>] [-Environment <String>]
20-
[-ArmTemplateParameters <Hashtable>] [-AdditionalParameters <Hashtable>] [-EnvironmentVariables <Hashtable>]
21-
[-CI] [-Force] [-OutFile] [-SuppressVsoCommands] [-WhatIf] [-Confirm] [<CommonParameters>]
18+
[-TestResourcesDirectory <String>] [-TestApplicationId <String>] [-TestApplicationSecret <String>]
19+
[-TestApplicationOid <String>] [-SubscriptionId <String>] [-DeleteAfterHours <Int32>] [-Location <String>]
20+
[-Environment <String>] [-ResourceType <String>] [-ArmTemplateParameters <Hashtable>]
21+
[-AdditionalParameters <Hashtable>] [-EnvironmentVariables <Hashtable>] [-CI] [-Force] [-OutFile]
22+
[-SuppressVsoCommands] [-UserAuth] [-NewTestResourcesRemainingArguments <Object>]
23+
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
2224
```
2325

2426
### Provisioner
2527
```
2628
New-TestResources.ps1 [-BaseName <String>] [-ResourceGroupName <String>] [-ServiceDirectory] <String>
27-
[-TestApplicationId <String>] [-TestApplicationSecret <String>] [-TestApplicationOid <String>]
28-
-TenantId <String> [-SubscriptionId <String>] -ProvisionerApplicationId <String>
29+
[-TestResourcesDirectory <String>] [-TestApplicationId <String>] [-TestApplicationSecret <String>]
30+
[-TestApplicationOid <String>] -TenantId <String> [-SubscriptionId <String>]
31+
-ProvisionerApplicationId <String> [-ProvisionerApplicationOid <String>]
2932
-ProvisionerApplicationSecret <String> [-DeleteAfterHours <Int32>] [-Location <String>]
30-
[-Environment <String>] [-ArmTemplateParameters <Hashtable>] [-AdditionalParameters <Hashtable>]
31-
[-EnvironmentVariables <Hashtable>] [-CI] [-Force] [-OutFile] [-SuppressVsoCommands] [-WhatIf] [-Confirm]
32-
[<CommonParameters>]
33+
[-Environment <String>] [-ResourceType <String>] [-ArmTemplateParameters <Hashtable>]
34+
[-AdditionalParameters <Hashtable>] [-EnvironmentVariables <Hashtable>] [-CI] [-Force] [-OutFile]
35+
[-SuppressVsoCommands] [-UserAuth] [-NewTestResourcesRemainingArguments <Object>]
36+
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
3337
```
3438

3539
## DESCRIPTION
@@ -206,8 +210,10 @@ Accept wildcard characters: False
206210
A directory under 'sdk' in the repository root - optionally with subdirectories
207211
specified - in which to discover ARM templates named 'test-resources.json' and
208212
Bicep templates named 'test-resources.bicep'.
209-
This can also be an absolute path
213+
This can be an absolute path
210214
or specify parent directories.
215+
ServiceDirectory is also used for resource and
216+
environment variable naming.
211217
212218
```yaml
213219
Type: String
@@ -221,6 +227,24 @@ Accept pipeline input: False
221227
Accept wildcard characters: False
222228
```
223229
230+
### -TestResourcesDirectory
231+
An override directory in which to discover ARM templates named 'test-resources.json' and
232+
Bicep templates named 'test-resources.bicep'.
233+
This can be an absolute path
234+
or specify parent directories.
235+
236+
```yaml
237+
Type: String
238+
Parameter Sets: (All)
239+
Aliases:
240+
241+
Required: False
242+
Position: Named
243+
Default value: None
244+
Accept pipeline input: False
245+
Accept wildcard characters: False
246+
```
247+
224248
### -TestApplicationId
225249
Optional Azure Active Directory Application ID to authenticate the test runner
226250
against deployed resources.
@@ -376,6 +400,21 @@ Accept pipeline input: False
376400
Accept wildcard characters: False
377401
```
378402
403+
### -ProvisionerApplicationOid
404+
{{ Fill ProvisionerApplicationOid Description }}
405+
406+
```yaml
407+
Type: String
408+
Parameter Sets: Provisioner
409+
Aliases:
410+
411+
Required: False
412+
Position: Named
413+
Default value: None
414+
Accept pipeline input: False
415+
Accept wildcard characters: False
416+
```
417+
379418
### -ProvisionerApplicationSecret
380419
A service principal secret (password) used to provision test resources when a
381420
provisioner is specified.
@@ -456,6 +495,21 @@ Accept pipeline input: False
456495
Accept wildcard characters: False
457496
```
458497
498+
### -ResourceType
499+
{{ Fill ResourceType Description }}
500+
501+
```yaml
502+
Type: String
503+
Parameter Sets: (All)
504+
Aliases:
505+
506+
Required: False
507+
Position: Named
508+
Default value: Test
509+
Accept pipeline input: False
510+
Accept wildcard characters: False
511+
```
512+
459513
### -ArmTemplateParameters
460514
Optional key-value pairs of parameters to pass to the ARM template(s).
461515
@@ -560,7 +614,7 @@ Accept wildcard characters: False
560614
### -SuppressVsoCommands
561615
By default, the -CI parameter will print out secrets to logs with Azure Pipelines log
562616
commands that cause them to be redacted.
563-
For CI environments that don't support this (like
617+
For CI environments that don't support this (like
564618
stress test clusters), this flag can be set to $false to avoid printing out these secrets to the logs.
565619
566620
```yaml
@@ -575,6 +629,46 @@ Accept pipeline input: False
575629
Accept wildcard characters: False
576630
```
577631
632+
### -UserAuth
633+
Create the resource group and deploy the template using the signed in user's credentials.
634+
No service principal will be created or used.
635+
636+
The environment file will be named for the test resources template that it was
637+
generated for.
638+
For ARM templates, it will be test-resources.json.env.
639+
For
640+
Bicep templates, test-resources.bicep.env.
641+
642+
```yaml
643+
Type: SwitchParameter
644+
Parameter Sets: (All)
645+
Aliases:
646+
647+
Required: False
648+
Position: Named
649+
Default value: False
650+
Accept pipeline input: False
651+
Accept wildcard characters: False
652+
```
653+
654+
### -NewTestResourcesRemainingArguments
655+
Captures any arguments not declared here (no parameter errors)
656+
This enables backwards compatibility with old script versions in
657+
hotfix branches if and when the dynamic subscription configuration
658+
secrets get updated to add new parameters.
659+
660+
```yaml
661+
Type: Object
662+
Parameter Sets: (All)
663+
Aliases:
664+
665+
Required: False
666+
Position: Named
667+
Default value: None
668+
Accept pipeline input: False
669+
Accept wildcard characters: False
670+
```
671+
578672
### -WhatIf
579673
Shows what would happen if the cmdlet runs.
580674
The cmdlet is not run.
@@ -606,6 +700,21 @@ Accept pipeline input: False
606700
Accept wildcard characters: False
607701
```
608702
703+
### -ProgressAction
704+
{{ Fill ProgressAction Description }}
705+
706+
```yaml
707+
Type: ActionPreference
708+
Parameter Sets: (All)
709+
Aliases: proga
710+
711+
Required: False
712+
Position: Named
713+
Default value: None
714+
Accept pipeline input: False
715+
Accept wildcard characters: False
716+
```
717+
609718
### CommonParameters
610719
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
611720

0 commit comments

Comments
 (0)