Skip to content

Commit

Permalink
Change deployment mode to Complete
Browse files Browse the repository at this point in the history
Also fixes an issue where if the user opted not to deploy to the same resource group, the script would continue execution anyway.
  • Loading branch information
heaths authored and azure-sdk committed Mar 31, 2021
1 parent b90815e commit da999ba
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions eng/common/TestResources/New-TestResources.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,11 @@ try {
$context = (Connect-AzAccount).Context
}

$currentSubcriptionId = $context.Subscription.Id

# If no subscription was specified, try to select the Azure SDK Developer Playground subscription.
# Ignore errors to leave the automatically selected subscription.
if ($SubscriptionId) {
$currentSubcriptionId = $context.Subscription.Id
if ($currentSubcriptionId -ne $SubscriptionId) {
Log "Selecting subscription '$SubscriptionId'"
$null = Select-AzSubscription -Subscription $SubscriptionId
Expand All @@ -221,11 +222,13 @@ try {
$context = Get-AzContext
}
} else {
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
if ($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

# Update the context.
$context = Get-AzContext
# Update the context.
$context = Get-AzContext
}

$SubscriptionId = $context.Subscription.Id
$PSBoundParameters['SubscriptionId'] = $SubscriptionId
Expand All @@ -244,7 +247,7 @@ try {
$subscriptionName = '{0} ({1})' -f $wellKnownSubscriptions[$subscriptionName], $subscriptionName
}

Log "Selected subscription '$subscriptionName'"
Log "Using subscription '$subscriptionName'"

# Make sure the TenantId is also updated from the current context.
# PSBoundParameters is not updated to avoid confusing parameter sets.
Expand Down Expand Up @@ -385,11 +388,15 @@ try {
# New-AzResourceGroup would've written an error and stopped the pipeline by default anyway.
Write-Verbose "Successfully created resource group '$($resourceGroup.ResourceGroupName)'"
}
elseif (!$resourceGroup -and !$PSCmdlet.ShouldProcess($resourceGroupName)) {
# If the -WhatIf flag was passed, there will be no resource group created. Fake it.
$resourceGroup = [PSCustomObject]@{
ResourceGroupName = $resourceGroupName
Location = $Location
elseif (!$resourceGroup) {
if (!$PSCmdlet.ShouldProcess($resourceGroupName)) {
# If the -WhatIf flag was passed, there will be no resource group created. Fake it.
$resourceGroup = [PSCustomObject]@{
ResourceGroupName = $resourceGroupName
Location = $Location
}
} else {
Write-Error "Resource group '$ResourceGroupName' already exists." -Category ResourceExists -RecommendedAction "Delete resource group '$ResourceGroupName', or overwrite it when redeploying."
}
}

Expand Down Expand Up @@ -452,7 +459,7 @@ try {
if ($CI) {
$DebugPreference = 'Continue'
}
New-AzResourceGroupDeployment -Name $BaseName -ResourceGroupName $resourceGroup.ResourceGroupName -TemplateFile $templateFile -TemplateParameterObject $templateFileParameters
New-AzResourceGroupDeployment -Name $BaseName -ResourceGroupName $resourceGroup.ResourceGroupName -TemplateFile $templateFile -TemplateParameterObject $templateFileParameters -Mode Complete -Force:$Force
} catch {
Write-Output @'
#####################################################
Expand Down

0 comments on commit da999ba

Please sign in to comment.