Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Commit

Permalink
Ensure multiple subscriptions can be moved to a management in parallel (
Browse files Browse the repository at this point in the history
Azure#288)

Ensure deployment name for moving subscription is unique
  • Loading branch information
SenthuranSivananthan authored May 10, 2022
1 parent 93d2f13 commit c413307
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/6-subscriptions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
inputs:
subscriptionIds:
type: string
description: Subscription ID(s) (optional), e.g. "abcd", "1234"
description: Subscription ID(s), e.g. "abcd", "1234"
required: true
environmentName:
type: string
Expand Down
23 changes: 14 additions & 9 deletions scripts/deployments/Functions/Subscriptions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,30 @@ function Set-Subscriptions {
Write-Output "Creating new file with runtime populated parameters: $PopulatedParametersFilePath"
$Configuration | ConvertTo-Json -Depth 100 | Set-Content $PopulatedParametersFilePath

$MoveDeploymentName="move-subscription-$SubscriptionId-$DeploymentRegion"
$MoveDeploymentName=-join $MoveDeploymentName[0..63]

Write-Output "Moving Subscription ($SubscriptionId) to Management Group ($ManagementGroupId)"
New-AzManagementGroupDeployment `
-Name $MoveDeploymentName `
-ManagementGroupId $ManagementGroupId `
-Location $Context.DeploymentRegion `
-TemplateFile "$($Context.WorkingDirectory)/landingzones/utils/mg-move/move-subscription.bicep" `
-TemplateParameterObject @{
managementGroupId = $ManagementGroupId
subscriptionId = $SubscriptionId
}
} `
-Verbose

Write-Output "Deploying $PopulatedParametersFilePath to $SubscriptionId in $Region"
Write-Output "Deploying $PopulatedParametersFilePath to $SubscriptionId in $Region"

Set-AzContext -Subscription $SubscriptionId
New-AzSubscriptionDeployment `
-Name "main-$DeploymentRegion" `
-Location $DeploymentRegion `
-TemplateFile "$($Context.WorkingDirectory)/landingzones/lz-$ArchetypeName/main.bicep" `
-TemplateParameterFile $PopulatedParametersFilePath `
-Verbose
Set-AzContext -Subscription $SubscriptionId
New-AzSubscriptionDeployment `
-Name "main-$DeploymentRegion" `
-Location $DeploymentRegion `
-TemplateFile "$($Context.WorkingDirectory)/landingzones/lz-$ArchetypeName/main.bicep" `
-TemplateParameterFile $PopulatedParametersFilePath `
-Verbose

Remove-Item $PopulatedParametersFilePath
}
Expand Down

0 comments on commit c413307

Please # to comment.