Skip to content

Commit 0985e2d

Browse files
azure-sdkbenbp
andauthored
Add fallback user id lookup for test resource deployment (Azure#39439)
Co-authored-by: Ben Broderick Phillips <[email protected]>
1 parent 4ff5b54 commit 0985e2d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

eng/common/TestResources/New-TestResources.ps1

Lines changed: 14 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,14 @@ 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 -eq $null -or !$userAccount.Id) {
403+
$userAccount = (Get-AzADUser -UserPrincipalName (Get-AzContext).Account)
404+
}
405+
if ($userAccount -eq $null -or !$userAccount.Id) {
406+
throw "Failed to find entra object ID for the current user"
407+
}
396408
$TestApplicationOid = $userAccount.Id
397409
$TestApplicationId = $testApplicationOid
398410
$userAccountName = $userAccount.UserPrincipalName

0 commit comments

Comments
 (0)