From c5c56ffd247c1901d1c094382d3cd8d0d77e12f7 Mon Sep 17 00:00:00 2001 From: Oliver Hahn Date: Fri, 28 Aug 2026 15:11:58 +0200 Subject: [PATCH] Updates 20260828 --- .../labautomation/deploy-lab.ps1 | 6 +-- .../infra/modules/sql2016-vm.bicep | 4 +- .../infra/modules/sql2022-vm.bicep | 4 +- .../labautomation/infra/modules/team-vm.bicep | 4 +- .../labautomation/shared-deploy-lab.ps1 | 53 ++++++++++++++++--- 5 files changed, 58 insertions(+), 13 deletions(-) diff --git a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/deploy-lab.ps1 b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/deploy-lab.ps1 index 29cae4e30..b82705648 100644 --- a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/deploy-lab.ps1 +++ b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/deploy-lab.ps1 @@ -90,9 +90,9 @@ $TeamName = $me.ShortName $TeamName = $TeamName.ToUpper() # feed the effective resource group back to the console -@{"HackboxCredential" = @{ name = "ResourceGroupName" ; value = $effectiveResourceGroup; note = "The name of the resource group where lab resources are deployed" }} -@{"HackboxCredential" = @{ name = "Team VM Name" ; value = $vmName; note = "The name of the Team VM" }} -@{"HackboxCredential" = @{ name = "Team / Link Name" ; value = $TeamName; note = "Name of the Team (Prefix for DBs and to use as Link Name for SQLMI)" }} +#@{"HackboxCredential" = @{ name = "ResourceGroupName" ; value = $effectiveResourceGroup; note = "The name of the resource group where lab resources are deployed" }} +@{"HackboxCredential" = @{ name = "Team VM Name" ; value = $vmName; note = "The name of the Team VM"; group = 'Lab-General'}} +@{"HackboxCredential" = @{ name = "Team / Link Name" ; value = $TeamName; note = "Name of the Team (Prefix for DBs and to use as Link Name for SQLMI)"; group = 'Lab-General'}} $legacySQLName = "legacySQL2016" diff --git a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/infra/modules/sql2016-vm.bicep b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/infra/modules/sql2016-vm.bicep index 3129d1f17..9cd6379cc 100644 --- a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/infra/modules/sql2016-vm.bicep +++ b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/infra/modules/sql2016-vm.bicep @@ -84,6 +84,7 @@ resource virtualMachine 'Microsoft.Compute/virtualMachines@2024-11-01' = { } } +/* resource autoShutdownConfig 'Microsoft.DevTestLab/schedules@2018-09-15' = { name: 'shutdown-computevm-${vmName}' location: location @@ -102,7 +103,8 @@ resource autoShutdownConfig 'Microsoft.DevTestLab/schedules@2018-09-15' = { targetResourceId: virtualMachine.id } } - + */ + resource sqlVirtualMachine 'Microsoft.SqlVirtualMachine/sqlVirtualMachines@2023-10-01' = { name: vmName location: location diff --git a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/infra/modules/sql2022-vm.bicep b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/infra/modules/sql2022-vm.bicep index f0364d542..af35d1ddf 100644 --- a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/infra/modules/sql2022-vm.bicep +++ b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/infra/modules/sql2022-vm.bicep @@ -80,6 +80,7 @@ resource virtualMachine 'Microsoft.Compute/virtualMachines@2024-11-01' = { } } +/* resource autoShutdownConfig 'Microsoft.DevTestLab/schedules@2018-09-15' = { name: 'shutdown-computevm-${vmName}' location: location @@ -98,7 +99,8 @@ resource autoShutdownConfig 'Microsoft.DevTestLab/schedules@2018-09-15' = { targetResourceId: virtualMachine.id } } - + */ + resource sqlVirtualMachine 'Microsoft.SqlVirtualMachine/sqlVirtualMachines@2023-10-01' = { name: vmName location: location diff --git a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/infra/modules/team-vm.bicep b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/infra/modules/team-vm.bicep index 2a24da620..c0f4c724a 100644 --- a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/infra/modules/team-vm.bicep +++ b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/infra/modules/team-vm.bicep @@ -86,6 +86,7 @@ resource virtualMachine 'Microsoft.Compute/virtualMachines@2024-11-01' = { } } +/* resource autoShutdownConfigs 'Microsoft.DevTestLab/schedules@2018-09-15' = { name: 'shutdown-computevm-${vmName}' location: location @@ -104,5 +105,6 @@ resource autoShutdownConfigs 'Microsoft.DevTestLab/schedules@2018-09-15' = { targetResourceId: virtualMachine.id } } - + */ + output vmName string = virtualMachine.name diff --git a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/shared-deploy-lab.ps1 b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/shared-deploy-lab.ps1 index a59ad516c..2f212b699 100644 --- a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/shared-deploy-lab.ps1 +++ b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/shared-deploy-lab.ps1 @@ -78,6 +78,39 @@ Write-Host "[$SubscriptionId] Deploying shared resources from template $template Write-Host $AllowedEntraUserIds +#Check if shared-rg was successfully deployed already +$SkipSharedDeployment = $false +$rg = Get-AzResourceGroup -Name $sharedResourceGroup -ErrorAction SilentlyContinue +if ($rg) { + if ($null -eq $rg.Tags) { + $tags = @{} + } + else { + $tags = $rg.Tags + } + if ($tags["microhack-shared-deployment"] -eq "Succeeded") { + $SkipSharedDeployment = $true + } +} + +if ($SkipSharedDeployment) { + $managedInstance = Get-AzSqlInstance -ResourceGroupName $sharedResourceGroup -ErrorAction SilentlyContinue | Select-Object -First 1 + $managedInstanceName = $managedInstance.ManagedInstanceName + $managedInstanceFQDN = $managedInstance.FullyQualifiedDomainName + + @{"HackboxCredential" = @{name = 'Legacy SQL Server Name'; value = $legacySQLName; note = 'Name of legacy SQL Server'; group = 'Lab-General'}} + @{"HackboxCredential" = @{name = 'SQLMI FQDN'; value = $managedInstanceFQDN; note = 'FQDN of SQLMI'; group = 'Lab-General'}} + @{"HackboxCredential" = @{name = 'Arc SQL Server Name'; value = $arcSQLName; note = 'Name of new SQL Server'; group = 'Lab-General'}} + + @{"HackboxCredential" = @{name = 'VM User Name'; value = $adminUsername; note = 'Username to connect for every VM'; group = 'Lab-Credentials'}} + @{"HackboxCredential" = @{name = 'VM User Password'; value = $adminPassword; note = 'Password to connect to every VM'; group = 'Lab-Credentials'}} + @{"HackboxCredential" = @{name = 'SQLMI User Name'; value = $sqlMiAdminUsername; note = 'Username to connect to SQLMI'; group = 'Lab-Credentials'}} + @{"HackboxCredential" = @{name = 'SQLMI User Password'; value = $sqlMiAdminPassword; note = 'Password to connect to SQLMI'; group = 'Lab-Credentials'}} + + return +} + + New-AzResourceGroup -Name $sharedResourceGroup -Location $PreferredLocation[0] -Force -ErrorAction Stop $tags = @{ @@ -88,6 +121,7 @@ $result = Invoke-MhhDeploymentWithRegionFallback ` -PreferredLocations $PreferredLocation ` -RgOwnerEntraObjectIds @($AllowedEntraUserIds) ` -ResourceGroupName $sharedResourceGroup ` + -CleanupTimeoutSeconds 1800 -TemplateFile $template ` -Tag $tags ` -TemplateParameterObject @{ @@ -111,14 +145,14 @@ $managedInstance = Get-AzSqlInstance -ResourceGroupName $sharedResourceGroup -Er $managedInstanceName = $managedInstance.ManagedInstanceName $managedInstanceFQDN = $managedInstance.FullyQualifiedDomainName -@{"HackboxCredential" = @{name = 'Legacy SQL Server Name'; value = $legacySQLName; note = 'Name of legacy SQL Server'}} -@{"HackboxCredential" = @{name = 'SQLMI FQDN'; value = $managedInstanceFQDN; note = 'FQDN of SQLMI'}} -@{"HackboxCredential" = @{name = 'Arc SQL Server Name'; value = $arcSQLName; note = 'Name of new SQL Server'}} +@{"HackboxCredential" = @{name = 'Legacy SQL Server Name'; value = $legacySQLName; note = 'Name of legacy SQL Server'; group = 'Lab-General'}} +@{"HackboxCredential" = @{name = 'SQLMI FQDN'; value = $managedInstanceFQDN; note = 'FQDN of SQLMI'; group = 'Lab-General'}} +@{"HackboxCredential" = @{name = 'Arc SQL Server Name'; value = $arcSQLName; note = 'Name of new SQL Server'; group = 'Lab-General'}} -@{"HackboxCredential" = @{name = 'VM User Name'; value = $adminUsername; note = 'Username to connect for every VM'}} -@{"HackboxCredential" = @{name = 'VM User Password'; value = $adminPassword; note = 'Password to connect to every VM'}} -@{"HackboxCredential" = @{name = 'SQLMI User Name'; value = $sqlMiAdminUsername; note = 'Username to connect to SQLMI'}} -@{"HackboxCredential" = @{name = 'SQLMI User Password'; value = $sqlMiAdminPassword; note = 'Password to connect to SQLMI'}} +@{"HackboxCredential" = @{name = 'VM User Name'; value = $adminUsername; note = 'Username to connect for every VM'; group = 'Lab-Credentials'}} +@{"HackboxCredential" = @{name = 'VM User Password'; value = $adminPassword; note = 'Password to connect to every VM'; group = 'Lab-Credentials'}} +@{"HackboxCredential" = @{name = 'SQLMI User Name'; value = $sqlMiAdminUsername; note = 'Username to connect to SQLMI'; group = 'Lab-Credentials'}} +@{"HackboxCredential" = @{name = 'SQLMI User Password'; value = $sqlMiAdminPassword; note = 'Password to connect to SQLMI'; group = 'Lab-Credentials'}} [string]$managedInstanceResourceId = $managedInstance.Id #$managedInstancePrincipalId = $managedInstance.Identity.PrincipalId @@ -204,3 +238,8 @@ if (-not $found) { throw "Expected Entra ID Admin was not configured within 2 minutes." } + +$rg = Get-AzResourceGroup -Name $sharedResourceGroup -ErrorAction SilentlyContinue +$tags = $rg.Tags +$tags["microhack-shared-deployment"] = "Succeeded" +Set-AzResourceGroup -Name $sharedResourceGroup -Tags $tags | Out-Null