diff --git a/.github/workflows/6-subscriptions.yml b/.github/workflows/6-subscriptions.yml index 61755f6..cbd1098 100644 --- a/.github/workflows/6-subscriptions.yml +++ b/.github/workflows/6-subscriptions.yml @@ -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 diff --git a/scripts/deployments/Functions/Subscriptions.ps1 b/scripts/deployments/Functions/Subscriptions.ps1 index 2495e2e..f257325 100644 --- a/scripts/deployments/Functions/Subscriptions.ps1 +++ b/scripts/deployments/Functions/Subscriptions.ps1 @@ -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 }