From c661f6c16818fd159da6afad76d4f1b3cb62c97f Mon Sep 17 00:00:00 2001 From: heaths <1532486+heaths@users.noreply.github.com> Date: Fri, 20 Nov 2026 23:29:07 +0000 Subject: [PATCH 1/3] Default test resource deployment to TME Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- .../TestResources/New-TestResources.ps1 | 32 ++++++++++--------- .../TestResources/New-TestResources.ps1.md | 2 ++ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/eng/common/TestResources/New-TestResources.ps1 b/eng/common/TestResources/New-TestResources.ps1 index 6495288b0cd9..21ecde3f9228 100755 --- a/eng/common/TestResources/New-TestResources.ps1 +++ b/eng/common/TestResources/New-TestResources.ps1 @@ -39,7 +39,7 @@ param ( [ValidateNotNullOrEmpty()] [string] $TenantId, - # Azure SDK Developer Playground subscription is assumed if not set + # Azure SDK Test Resources - TME subscription is assumed if not set [Parameter()] [ValidatePattern('^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$')] [string] $SubscriptionId, @@ -248,15 +248,19 @@ try { $context = Get-AzContext; if (!$context) { Log 'User not logged in. Logging in now...' - $context = (Connect-AzAccount).Context + if ($SubscriptionId) { + $context = (Connect-AzAccount).Context + } else { + $context = (Connect-AzAccount -TenantId $wellKnownTMETenants[0]).Context + } } - $currentSubcriptionId = $context.Subscription.Id + $currentSubscriptionId = $context.Subscription.Id - # If no subscription was specified, try to select the Azure SDK Developer Playground subscription. + # If no subscription was specified, use the Azure SDK Test Resources - TME subscription. # Ignore errors to leave the automatically selected subscription. if ($SubscriptionId) { - if ($currentSubcriptionId -ne $SubscriptionId) { + if ($currentSubscriptionId -ne $SubscriptionId) { Log "Selecting subscription '$SubscriptionId'" $null = Select-AzSubscription -Subscription $SubscriptionId @@ -269,16 +273,14 @@ try { $context = Get-AzContext } } else { - if ($context.Tenant.Name -like '*TME*') { - if ($currentSubscriptionId -ne '4d042dc6-fe17-4698-a23f-ec6a8d1e98f4') { - Log "Attempting to select subscription 'Azure SDK Test Resources - TME (4d042dc6-fe17-4698-a23f-ec6a8d1e98f4)'" - $null = Select-AzSubscription -Subscription '4d042dc6-fe17-4698-a23f-ec6a8d1e98f4' -ErrorAction Ignore -WarningAction Ignore - # Update the context. - $context = Get-AzContext - } - } elseif ($currentSubcriptionId -ne 'faa080af-c1d8-40ad-9cce-e1a450ca5b57') { - Log "Attempting to select subscription 'Azure SDK Developer Playground (faa080af-c1d8-40ad-9cce-e1a450ca5b57)'" - $null = Select-AzSubscription -Subscription 'faa080af-c1d8-40ad-9cce-e1a450ca5b57' -ErrorAction Ignore -WarningAction Ignore + if ($context.Tenant.Id -ne $wellKnownTMETenants[0]) { + Log 'User is not logged in to the TME tenant. Logging in now...' + $context = (Connect-AzAccount -TenantId $wellKnownTMETenants[0]).Context + } + + if ($context.Subscription.Id -ne '4d042dc6-fe17-4698-a23f-ec6a8d1e98f4') { + Log "Attempting to select subscription 'Azure SDK Test Resources - TME (4d042dc6-fe17-4698-a23f-ec6a8d1e98f4)'" + $null = Select-AzSubscription -Subscription '4d042dc6-fe17-4698-a23f-ec6a8d1e98f4' -ErrorAction Ignore -WarningAction Ignore # Update the context. $context = Get-AzContext } diff --git a/eng/common/TestResources/New-TestResources.ps1.md b/eng/common/TestResources/New-TestResources.ps1.md index 6b479f23fa0b..7be205a83753 100644 --- a/eng/common/TestResources/New-TestResources.ps1.md +++ b/eng/common/TestResources/New-TestResources.ps1.md @@ -55,6 +55,8 @@ If no service principal is specified, a new one will be created and assigned the This script runs in the context of credentials already specified in Connect-AzAccount or those specified in $ProvisionerApplicationId and $ProvisionerApplicationSecret. +If no subscription is specified, it signs in to the TME tenant if necessary and uses the +Azure SDK Test Resources - TME subscription. Specify `-SubscriptionId` to use another subscription. ## EXAMPLES From 7a8d384ce21b86d7f54cfed5e6e4eb717a11540e Mon Sep 17 00:00:00 2001 From: raych1 <20296335+raych1@users.noreply.github.com> Date: Fri, 20 Nov 2026 23:58:15 +0000 Subject: [PATCH 2/3] Fix exit action subscription variable Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- eng/common/TestResources/New-TestResources.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/common/TestResources/New-TestResources.ps1 b/eng/common/TestResources/New-TestResources.ps1 index 21ecde3f9228..4c9d7a041984 100755 --- a/eng/common/TestResources/New-TestResources.ps1 +++ b/eng/common/TestResources/New-TestResources.ps1 @@ -265,8 +265,8 @@ try { $null = Select-AzSubscription -Subscription $SubscriptionId $exitActions += { - Log "Selecting previous subscription '$currentSubcriptionId'" - $null = Select-AzSubscription -Subscription $currentSubcriptionId + Log "Selecting previous subscription '$currentSubscriptionId'" + $null = Select-AzSubscription -Subscription $currentSubscriptionId } # Update the context. From 477c613c4c7ff964d14fdbc0784ca983e9a4e3ab Mon Sep 17 00:00:00 2001 From: heaths <1532486+heaths@users.noreply.github.com> Date: Sat, 21 Nov 2026 01:53:46 +0000 Subject: [PATCH 3/3] Apply remaining changes Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- .../TestResources/New-TestResources.ps1 | 44 ++++++++++++++----- .../TestResources/New-TestResources.ps1.md | 5 ++- .../TestResources/Remove-TestResources.ps1 | 21 +++++---- .../TestResources/SubConfig-Helpers.ps1 | 14 ++++++ .../TestResources/Update-TestResources.ps1 | 21 +++++---- 5 files changed, 78 insertions(+), 27 deletions(-) diff --git a/eng/common/TestResources/New-TestResources.ps1 b/eng/common/TestResources/New-TestResources.ps1 index 4c9d7a041984..6c1572c7e558 100755 --- a/eng/common/TestResources/New-TestResources.ps1 +++ b/eng/common/TestResources/New-TestResources.ps1 @@ -249,20 +249,26 @@ try { if (!$context) { Log 'User not logged in. Logging in now...' if ($SubscriptionId) { - $context = (Connect-AzAccount).Context + $tenantArgs = if ($TenantId) { @{ Tenant = $TenantId } } else { @{} } + $context = (Connect-AzAccount -Environment $Environment @tenantArgs).Context } else { + if ($Environment -ne 'AzureCloud') { + throw "The TME default is only available for AzureCloud. Specify -SubscriptionId to deploy to '$Environment'." + } $context = (Connect-AzAccount -TenantId $wellKnownTMETenants[0]).Context } } + elseif (!$SubscriptionId -and $Environment -ne 'AzureCloud') { + throw "The TME default is only available for AzureCloud. Specify -SubscriptionId to deploy to '$Environment'." + } $currentSubscriptionId = $context.Subscription.Id # If no subscription was specified, use the Azure SDK Test Resources - TME subscription. - # Ignore errors to leave the automatically selected subscription. if ($SubscriptionId) { if ($currentSubscriptionId -ne $SubscriptionId) { Log "Selecting subscription '$SubscriptionId'" - $null = Select-AzSubscription -Subscription $SubscriptionId + $null = Select-AzSubscription -Subscription $SubscriptionId -ErrorAction Stop $exitActions += { Log "Selecting previous subscription '$currentSubscriptionId'" @@ -275,20 +281,40 @@ try { } else { if ($context.Tenant.Id -ne $wellKnownTMETenants[0]) { Log 'User is not logged in to the TME tenant. Logging in now...' - $context = (Connect-AzAccount -TenantId $wellKnownTMETenants[0]).Context + $context = (Connect-AzAccount -TenantId $wellKnownTMETenants[0] -Environment $Environment).Context } if ($context.Subscription.Id -ne '4d042dc6-fe17-4698-a23f-ec6a8d1e98f4') { Log "Attempting to select subscription 'Azure SDK Test Resources - TME (4d042dc6-fe17-4698-a23f-ec6a8d1e98f4)'" - $null = Select-AzSubscription -Subscription '4d042dc6-fe17-4698-a23f-ec6a8d1e98f4' -ErrorAction Ignore -WarningAction Ignore + $null = Select-AzSubscription -Subscription '4d042dc6-fe17-4698-a23f-ec6a8d1e98f4' -ErrorAction Stop # Update the context. $context = Get-AzContext } + if ($context.Subscription.Id -ne '4d042dc6-fe17-4698-a23f-ec6a8d1e98f4') { + throw "Unable to select Azure SDK Test Resources - TME subscription '4d042dc6-fe17-4698-a23f-ec6a8d1e98f4'. Specify -SubscriptionId to use another subscription." + } + $SubscriptionId = $context.Subscription.Id $PSBoundParameters['SubscriptionId'] = $SubscriptionId } + if ($SubscriptionId -and $context.Subscription.Id -ne $SubscriptionId) { + throw "Unable to select subscription '$SubscriptionId'. Verify that you have access to the subscription." + } + + if ($Environment -eq 'AzureCloud' -and $SubscriptionId -eq '4d042dc6-fe17-4698-a23f-ec6a8d1e98f4' -and (Get-Command az -ErrorAction SilentlyContinue)) { + $cliAccountJson = az account show --output json 2>$null + if ($LASTEXITCODE -ne 0) { + throw "Azure CLI is not logged in to the TME subscription '$SubscriptionId'. Run 'az login --tenant $($wellKnownTMETenants[0])' and 'az account set --subscription $SubscriptionId' before provisioning." + } + + $cliAccount = $cliAccountJson | ConvertFrom-Json + if ($cliAccount.id -ne $SubscriptionId -or $cliAccount.tenantId -ne $wellKnownTMETenants[0]) { + throw "Azure CLI is not set to TME subscription '$SubscriptionId'. Run 'az login --tenant $($wellKnownTMETenants[0])' and 'az account set --subscription $SubscriptionId' before provisioning." + } + } + # Use cache of well-known team subs without having to be authenticated. $wellKnownSubscriptions = @{ 'faa080af-c1d8-40ad-9cce-e1a450ca5b57' = 'Azure SDK Developer Playground' @@ -313,11 +339,9 @@ try { } # This needs to happen after we set the TenantId but before we use the ResourceGroupName - if ($wellKnownTMETenants.Contains($TenantId) -and !$ResourceGroupName.StartsWith("SSS3PT_", [System.StringComparison]::OrdinalIgnoreCase)) { - # Add a prefix to the resource group name to avoid flagging the usages of local auth - # See details at https://eng.ms/docs/products/onecert-certificates-key-vault-and-dsms/key-vault-dsms/certandsecretmngmt/credfreefaqs#how-can-i-disable-s360-reporting-when-testing-customer-facing-3p-features-that-depend-on-use-of-unsafe-local-auth - $ResourceGroupName = "SSS3PT_" + $ResourceGroupName - } + # The SSS3PT prefix avoids flagging use of local auth in TME. + # See details at https://eng.ms/docs/products/onecert-certificates-key-vault-and-dsms/key-vault-dsms/certandsecretmngmt/credfreefaqs#how-can-i-disable-s360-reporting-when-testing-customer-facing-3p-features-that-depend-on-use-of-unsafe-local-auth + $ResourceGroupName = AddTestResourceGroupPrefix $ResourceGroupName $TenantId $SubscriptionId if ($ResourceGroupName.Length -gt 90) { # See limits at https://docs.microsoft.com/azure/architecture/best-practices/resource-naming diff --git a/eng/common/TestResources/New-TestResources.ps1.md b/eng/common/TestResources/New-TestResources.ps1.md index 7be205a83753..85b9e060f52d 100644 --- a/eng/common/TestResources/New-TestResources.ps1.md +++ b/eng/common/TestResources/New-TestResources.ps1.md @@ -56,7 +56,10 @@ If no service principal is specified, a new one will be created and assigned the This script runs in the context of credentials already specified in Connect-AzAccount or those specified in $ProvisionerApplicationId and $ProvisionerApplicationSecret. If no subscription is specified, it signs in to the TME tenant if necessary and uses the -Azure SDK Test Resources - TME subscription. Specify `-SubscriptionId` to use another subscription. +Azure SDK Test Resources - TME subscription for `-Environment AzureCloud`. Specify `-SubscriptionId` +to use another subscription or to deploy to a sovereign cloud. When Azure CLI commands are used +by local tests, run `az login --tenant 70a036f6-8e4d-4615-bad6-149c02e7720d` and +`az account set --subscription 4d042dc6-fe17-4698-a23f-ec6a8d1e98f4`. ## EXAMPLES diff --git a/eng/common/TestResources/Remove-TestResources.ps1 b/eng/common/TestResources/Remove-TestResources.ps1 index 5ca8fc1582a2..1a49170d147a 100755 --- a/eng/common/TestResources/Remove-TestResources.ps1 +++ b/eng/common/TestResources/Remove-TestResources.ps1 @@ -176,17 +176,16 @@ if (!$ResourceGroupName) { } } -# If no subscription was specified, try to select the 'Azure SDK Test Resources - TME' subscription. -# Ignore errors to leave the automatically selected subscription. +# If no subscription was specified, select the 'Azure SDK Test Resources - TME' subscription. if ($SubscriptionId) { - $currentSubcriptionId = $context.Subscription.Id - if ($currentSubcriptionId -ne $SubscriptionId) { + $currentSubscriptionId = $context.Subscription.Id + if ($currentSubscriptionId -ne $SubscriptionId) { Log "Selecting subscription '$SubscriptionId'" - $null = Select-AzSubscription -Subscription $SubscriptionId -WarningAction Ignore + $null = Select-AzSubscription -Subscription $SubscriptionId -ErrorAction Stop $exitActions += { - Log "Selecting previous subscription '$currentSubcriptionId'" - $null = Select-AzSubscription -Subscription $currentSubcriptionId -WarningAction Ignore + Log "Selecting previous subscription '$currentSubscriptionId'" + $null = Select-AzSubscription -Subscription $currentSubscriptionId -WarningAction Ignore } # Update the context. @@ -194,7 +193,7 @@ if ($SubscriptionId) { } } else { Log "Attempting to select subscription 'Azure SDK Test Resources - TME (4d042dc6-fe17-4698-a23f-ec6a8d1e98f4)'" - $null = Select-AzSubscription -Subscription '4d042dc6-fe17-4698-a23f-ec6a8d1e98f4' -ErrorAction Ignore -WarningAction Ignore + $null = Select-AzSubscription -Subscription '4d042dc6-fe17-4698-a23f-ec6a8d1e98f4' -ErrorAction Stop # Update the context. $context = Get-AzContext @@ -203,6 +202,12 @@ if ($SubscriptionId) { $PSBoundParameters['SubscriptionId'] = $SubscriptionId } +if ($SubscriptionId -and $context.Subscription.Id -ne $SubscriptionId) { + throw "Unable to select subscription '$SubscriptionId'. Verify that you have access to the subscription." +} + +$ResourceGroupName = AddTestResourceGroupPrefix $ResourceGroupName $context.Subscription.TenantId $SubscriptionId + # Use cache of well-known team subs without having to be authenticated. $wellKnownSubscriptions = @{ 'faa080af-c1d8-40ad-9cce-e1a450ca5b57' = 'Azure SDK Developer Playground' diff --git a/eng/common/TestResources/SubConfig-Helpers.ps1 b/eng/common/TestResources/SubConfig-Helpers.ps1 index 0e9d878054b8..2c6f7a752edc 100644 --- a/eng/common/TestResources/SubConfig-Helpers.ps1 +++ b/eng/common/TestResources/SubConfig-Helpers.ps1 @@ -19,6 +19,20 @@ function GetUserName() { return $UserName } +function AddTestResourceGroupPrefix([string] $ResourceGroupName, [string] $TenantId, [string] $SubscriptionId) { + $tmeTenantIds = @('70a036f6-8e4d-4615-bad6-149c02e7720d') + $tmeSubscriptionId = '4d042dc6-fe17-4698-a23f-ec6a8d1e98f4' + + if ($ResourceGroupName -and + (($TenantId -and $tmeTenantIds -contains $TenantId) -or + ($SubscriptionId -and $SubscriptionId -ieq $tmeSubscriptionId)) -and + !$ResourceGroupName.StartsWith("SSS3PT_", [System.StringComparison]::OrdinalIgnoreCase)) { + return "SSS3PT_" + $ResourceGroupName + } + + return $ResourceGroupName +} + function GetBaseAndResourceGroupNames( [string]$baseNameDefault, [string]$resourceGroupNameDefault, diff --git a/eng/common/TestResources/Update-TestResources.ps1 b/eng/common/TestResources/Update-TestResources.ps1 index 35e40fbd55ba..33ac01ef8c32 100755 --- a/eng/common/TestResources/Update-TestResources.ps1 +++ b/eng/common/TestResources/Update-TestResources.ps1 @@ -83,17 +83,16 @@ if (!$context) { throw "You must be already logged in to use this script. Run 'Connect-AzAccount' and try again." } -# If no subscription was specified, try to select the 'Azure SDK Test Resources - TME' subscription. -# Ignore errors to leave the automatically selected subscription. +# If no subscription was specified, select the 'Azure SDK Test Resources - TME' subscription. if ($SubscriptionId) { - $currentSubcriptionId = $context.Subscription.Id - if ($currentSubcriptionId -ne $SubscriptionId) { + $currentSubscriptionId = $context.Subscription.Id + if ($currentSubscriptionId -ne $SubscriptionId) { Log "Selecting subscription '$SubscriptionId'" - $null = Select-AzSubscription -Subscription $SubscriptionId -WarningAction Ignore + $null = Select-AzSubscription -Subscription $SubscriptionId -ErrorAction Stop $exitActions += { - Log "Selecting previous subscription '$currentSubcriptionId'" - $null = Select-AzSubscription -Subscription $SubscriptionId -WarningAction Ignore + Log "Selecting previous subscription '$currentSubscriptionId'" + $null = Select-AzSubscription -Subscription $currentSubscriptionId -WarningAction Ignore } # Update the context. @@ -101,7 +100,7 @@ if ($SubscriptionId) { } } else { Log "Attempting to select subscription 'Azure SDK Test Resources - TME (4d042dc6-fe17-4698-a23f-ec6a8d1e98f4)'" - $null = Select-AzSubscription -Subscription '4d042dc6-fe17-4698-a23f-ec6a8d1e98f4' -ErrorAction Ignore -WarningAction Ignore + $null = Select-AzSubscription -Subscription '4d042dc6-fe17-4698-a23f-ec6a8d1e98f4' -ErrorAction Stop # Update the context. $context = Get-AzContext @@ -110,6 +109,12 @@ if ($SubscriptionId) { $PSBoundParameters['SubscriptionId'] = $SubscriptionId } +if ($SubscriptionId -and $context.Subscription.Id -ne $SubscriptionId) { + throw "Unable to select subscription '$SubscriptionId'. Verify that you have access to the subscription." +} + +$ResourceGroupName = AddTestResourceGroupPrefix $ResourceGroupName $context.Subscription.TenantId $SubscriptionId + # Use cache of well-known team subs without having to be authenticated. $wellKnownSubscriptions = @{ 'faa080af-c1d8-40ad-9cce-e1a450ca5b57' = 'Azure SDK Developer Playground'