Skip to content

Commit

Permalink
Support creating resources with user auth
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLove-msft committed Jan 24, 2024
1 parent 1d213ef commit aaa5959
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion eng/common/TestResources/New-TestResources.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ param (
[Parameter()]
[switch] $SuppressVsoCommands = ($null -eq $env:SYSTEM_TEAMPROJECTID),

[Parameter()]
[switch] $UseUserCredentials,

# Captures any arguments not declared here (no parameter errors)
# This enables backwards compatibility with old script versions in
# hotfix branches if and when the dynamic subscription configuration
Expand Down Expand Up @@ -611,8 +614,14 @@ try {
}
}


if ($UseUserCredentials) {
$TestApplicationOid = (Get-AzADUser -UserPrincipalName (Get-AzContext).Account).Id
$TestApplicationId = $testApplicationOid
Log "User-based app id '$TestApplicationId' will be used."
}
# If no test application ID was specified during an interactive session, create a new service principal.
if (!$CI -and !$TestApplicationId) {
elseif (!$CI -and !$TestApplicationId) {
# Cache the created service principal in this session for frequent reuse.
$servicePrincipal = if ($AzureTestPrincipal -and (Get-AzADServicePrincipal -ApplicationId $AzureTestPrincipal.AppId) -and $AzureTestSubscription -eq $SubscriptionId) {
Log "TestApplicationId was not specified; loading cached service principal '$($AzureTestPrincipal.AppId)'"
Expand Down Expand Up @@ -1001,6 +1010,14 @@ The environment file will be named for the test resources template that it was
generated for. For ARM templates, it will be test-resources.json.env. For
Bicep templates, test-resources.bicep.env.
.PARAMETER UseUserCredentials
Create the resource group and deploy the template using the signed in user's credentials.
No service principal will be created or used.
The environment file will be named for the test resources template that it was
generated for. For ARM templates, it will be test-resources.json.env. For
Bicep templates, test-resources.bicep.env.
.PARAMETER SuppressVsoCommands
By default, the -CI parameter will print out secrets to logs with Azure Pipelines log
commands that cause them to be redacted. For CI environments that don't support this (like
Expand Down

0 comments on commit aaa5959

Please sign in to comment.