Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -104,5 +105,6 @@ resource autoShutdownConfigs 'Microsoft.DevTestLab/schedules@2018-09-15' = {
targetResourceId: virtualMachine.id
}
}

*/

output vmName string = virtualMachine.name
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @{
Expand All @@ -88,6 +121,7 @@ $result = Invoke-MhhDeploymentWithRegionFallback `
-PreferredLocations $PreferredLocation `
-RgOwnerEntraObjectIds @($AllowedEntraUserIds) `
-ResourceGroupName $sharedResourceGroup `
-CleanupTimeoutSeconds 1800
-TemplateFile $template `
-Tag $tags `
-TemplateParameterObject @{
Expand All @@ -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
Expand Down Expand Up @@ -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