From 19678342a6b34680517a9ef76eaa013008a4a622 Mon Sep 17 00:00:00 2001 From: Marco Weber Date: Fri, 5 Jun 2026 13:58:16 +0200 Subject: [PATCH 1/2] added automated lab deployments --- .../Infra/App1/deploy-lab.ps1 | 4 +- .../Infra/App1/lab-defaults.json | 8 +++ 99-MicroHack-Template/labautomation/README.md | 3 + .../labautomation/deploy-lab.ps1 | 65 +++++++++++++++++++ .../labautomation/lab-defaults.json | 8 +++ lab-defaults-schema.json | 34 ++++++++++ 6 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 03-Azure/01-03-Infrastructure/04_BCDR_Azure_Native/Infra/App1/lab-defaults.json create mode 100644 99-MicroHack-Template/labautomation/README.md create mode 100644 99-MicroHack-Template/labautomation/deploy-lab.ps1 create mode 100644 99-MicroHack-Template/labautomation/lab-defaults.json create mode 100644 lab-defaults-schema.json diff --git a/03-Azure/01-03-Infrastructure/04_BCDR_Azure_Native/Infra/App1/deploy-lab.ps1 b/03-Azure/01-03-Infrastructure/04_BCDR_Azure_Native/Infra/App1/deploy-lab.ps1 index 43f1e861e..978dfc490 100644 --- a/03-Azure/01-03-Infrastructure/04_BCDR_Azure_Native/Infra/App1/deploy-lab.ps1 +++ b/03-Azure/01-03-Infrastructure/04_BCDR_Azure_Native/Infra/App1/deploy-lab.ps1 @@ -10,7 +10,7 @@ Specifies the Azure subscription that contains the lab resources. .PARAMETER ResourceGroupName In case of resourcegroup deployment, specifies the target resource group name. .PARAMETER PreferredLocation -Specifies the preferred Azure region for resource deployment. "" indicates no preference. +Specifies the preferred Azure regions (ordered by preference) for resource deployment. An empty array indicates no preference. .PARAMETER AllowedEntraUserIds Optional list of Entra user object IDs permitted to access the lab resources. #> @@ -24,7 +24,7 @@ param( [string]$ResourceGroupName = "", - [string]$PreferredLocation = "", + [string[]]$PreferredLocation = @(), [string[]]$AllowedEntraUserIds = @() ) diff --git a/03-Azure/01-03-Infrastructure/04_BCDR_Azure_Native/Infra/App1/lab-defaults.json b/03-Azure/01-03-Infrastructure/04_BCDR_Azure_Native/Infra/App1/lab-defaults.json new file mode 100644 index 000000000..7c830a20d --- /dev/null +++ b/03-Azure/01-03-Infrastructure/04_BCDR_Azure_Native/Infra/App1/lab-defaults.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://raw.githubusercontent.com/microsoft/MicroHack/refs/heads/main/lab-defaults-schema.json", + "groups": [ "" ], + "deploymentType": "resourcegroup", + "labsPerSubscription": 4, + "preferredLocation": "swedencentral, norwayeast, spaincentral", + "estimatedDailyCostsUsd": 20.0 +} diff --git a/99-MicroHack-Template/labautomation/README.md b/99-MicroHack-Template/labautomation/README.md new file mode 100644 index 000000000..e2a194978 --- /dev/null +++ b/99-MicroHack-Template/labautomation/README.md @@ -0,0 +1,3 @@ +# Labautomation + +This folder is optional. Please delete it if you don't want to have a lab automation script (to spin up lab environments in Azure). diff --git a/99-MicroHack-Template/labautomation/deploy-lab.ps1 b/99-MicroHack-Template/labautomation/deploy-lab.ps1 new file mode 100644 index 000000000..03547a904 --- /dev/null +++ b/99-MicroHack-Template/labautomation/deploy-lab.ps1 @@ -0,0 +1,65 @@ +<# +.SYNOPSIS +Deploys the lab resources scoped to a subscription or resource group. +.DESCRIPTION +Provides a controlled deployment flow for lab environments, optionally limited to a resource group and specific Entra user IDs. +.PARAMETER DeploymentType +Defines the deployment scope; allowed values are subscription or resourcegroup. +.PARAMETER SubscriptionId +Specifies the Azure subscription that contains the lab resources. +.PARAMETER ResourceGroupName +In case of resourcegroup deployment, specifies the target resource group name. +.PARAMETER PreferredLocation +Specifies the preferred Azure regions (ordered by preference) for resource deployment. An empty array indicates no preference. +.PARAMETER AllowedEntraUserIds +Optional list of Entra user object IDs permitted to access the lab resources. +#> +param( + [Parameter(Mandatory=$true)] + [ValidateSet('subscription','resourcegroup', 'resourcegroup-with-subscriptionowner')] + [string]$DeploymentType, + + [Parameter(Mandatory=$true)] + [string]$SubscriptionId, + + [string]$ResourceGroupName = "", + + [string[]]$PreferredLocation = @(), + + [string[]]$AllowedEntraUserIds = @() +) + +$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Definition + +# Validate parameters +if($DeploymentType -eq 'resourcegroup' -and [string]::IsNullOrEmpty($ResourceGroupName)) { + throw "ResourceGroupName must be provided when DeploymentType is 'resourcegroup'." +} + +# set the effective location (example) +if($PreferredLocation.Count -gt 0) { + $effectiveLocation = $PreferredLocation[0] +} else { + $effectiveLocation = "swedencentral" # Default location if no preference is provided +} + +# set the effective resource group based on deployment type (example) +if($DeploymentType -eq 'subscription') { + $stableHash = Get-MhhStablehash $AllowedEntraUserIds -Length 24 + $effectiveResourceGroup = "lab-$stableHash" + Write-Host "Deploying lab resources at the subscription level in subscription $SubscriptionId..." + New-AzResourceGroup -Name $effectiveResourceGroup -Location $effectiveLocation -Verbose +} +else { + $effectiveResourceGroup = $ResourceGroupName +} +# 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" }} + +# $template = Join-Path $scriptPath "template.bicep" +# $template = Join-Path $scriptPath "template.json" +# New-AzResourceGroupDeployment -ResourceGroupName $effectiveResourceGroup -TemplateFile $template -Verbose + +# You can send back information to the hackbox console (credentials) - Simply return a hashtable like this: +# @{"HackboxCredential" = @{ name = "AdminPassword" ; value = "TopSecret"; note = "Useful info here" }} + diff --git a/99-MicroHack-Template/labautomation/lab-defaults.json b/99-MicroHack-Template/labautomation/lab-defaults.json new file mode 100644 index 000000000..7c830a20d --- /dev/null +++ b/99-MicroHack-Template/labautomation/lab-defaults.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://raw.githubusercontent.com/microsoft/MicroHack/refs/heads/main/lab-defaults-schema.json", + "groups": [ "" ], + "deploymentType": "resourcegroup", + "labsPerSubscription": 4, + "preferredLocation": "swedencentral, norwayeast, spaincentral", + "estimatedDailyCostsUsd": 20.0 +} diff --git a/lab-defaults-schema.json b/lab-defaults-schema.json new file mode 100644 index 000000000..39eac5544 --- /dev/null +++ b/lab-defaults-schema.json @@ -0,0 +1,34 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Lab Defaults", + "description": "Smart defaults for the lab lifecycle wizard. Only include fields you want to override — missing fields are ignored.", + "type": "object", + "properties": { + "groups": { + "type": "array", + "items": { "type": "string" }, + "description": "Group-based feature activation names (e.g. [\"GHCPUsers\"]). Each group provisions a feature for the created Entra ID users." + }, + "deploymentType": { + "type": "string", + "enum": ["resourcegroup", "subscription", "resourcegroup-with-subscriptionowner"], + "description": "Azure deployment scope." + }, + "labsPerSubscription": { + "type": "integer", + "minimum": 1, + "maximum": 100, + "description": "Number of lab environments to pack per Azure subscription." + }, + "preferredLocation": { + "type": "string", + "description": "Comma-separated list of preferred Azure regions, in priority order (e.g. \"swedencentral, norwayeast\")." + }, + "estimatedDailyCostsUsd": { + "type": "number", + "minimum": 0, + "description": "Estimated daily cost per lab environment in USD. Used for cost forecasting in the lab lifecycle wizard." + } + }, + "additionalProperties": false +} \ No newline at end of file From 4ef959504966202c623c2d7236dbed767ac874b3 Mon Sep 17 00:00:00 2001 From: Marco Weber Date: Fri, 5 Jun 2026 14:00:42 +0200 Subject: [PATCH 2/2] better sample --- 99-MicroHack-Template/labautomation/lab-defaults.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/99-MicroHack-Template/labautomation/lab-defaults.json b/99-MicroHack-Template/labautomation/lab-defaults.json index 7c830a20d..e54697288 100644 --- a/99-MicroHack-Template/labautomation/lab-defaults.json +++ b/99-MicroHack-Template/labautomation/lab-defaults.json @@ -4,5 +4,5 @@ "deploymentType": "resourcegroup", "labsPerSubscription": 4, "preferredLocation": "swedencentral, norwayeast, spaincentral", - "estimatedDailyCostsUsd": 20.0 + "estimatedDailyCostsUsd": 25.0 }