Skip to content

Commit 87ad898

Browse files
committed
Add fallback user id lookup for test resource deployment
1 parent de053c2 commit 87ad898

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

eng/common/TestResources/New-TestResources.ps1

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,14 @@ try {
320320
# Make sure the provisioner OID is set so we can pass it through to the deployment.
321321
if (!$ProvisionerApplicationId -and !$ProvisionerApplicationOid) {
322322
if ($context.Account.Type -eq 'User') {
323-
# Use -Mail as the lookup works in both corp and TME tenants
323+
# Support corp tenant and TME tenant user id lookups
324324
$user = Get-AzADUser -Mail $context.Account.Id
325+
if ($user -eq $null -or !$user.Id) {
326+
$user = Get-AzADUser -UserPrincipalName $context.Account.Id
327+
}
328+
if ($user -eq $null -or !$user.Id) {
329+
throw "Failed to find entra object ID for the current user"
330+
}
325331
$ProvisionerApplicationOid = $user.Id
326332
} elseif ($context.Account.Type -eq 'ServicePrincipal') {
327333
$sp = Get-AzADServicePrincipal -ApplicationId $context.Account.Id
@@ -391,8 +397,15 @@ try {
391397
Write-Warning "The specified TestApplicationId '$TestApplicationId' will be ignored when -ServicePrincipalAutth is not set."
392398
}
393399

394-
# Use -Mail as the lookup works in both corp and TME tenants
400+
# Support corp tenant and TME tenant user id lookups
395401
$userAccount = (Get-AzADUser -Mail (Get-AzContext).Account.Id)
402+
if (!$userAccount.Id) {
403+
if ($userAccount -eq $null -or !$userAccount.Id) {
404+
$userAccount = (Get-AzADUser -UserPrincipalName (Get-AzContext).Account)
405+
}
406+
if ($userAccount -eq $null -or !$userAccount.Id) {
407+
throw "Failed to find entra object ID for the current user"
408+
}
396409
$TestApplicationOid = $userAccount.Id
397410
$TestApplicationId = $testApplicationOid
398411
$userAccountName = $userAccount.UserPrincipalName

0 commit comments

Comments
 (0)