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 @@ -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.
#>
Expand All @@ -24,7 +24,7 @@ param(

[string]$ResourceGroupName = "",

[string]$PreferredLocation = "",
[string[]]$PreferredLocation = @(),

[string[]]$AllowedEntraUserIds = @()
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 3 additions & 0 deletions 99-MicroHack-Template/labautomation/README.md
Original file line number Diff line number Diff line change
@@ -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).
65 changes: 65 additions & 0 deletions 99-MicroHack-Template/labautomation/deploy-lab.ps1
Original file line number Diff line number Diff line change
@@ -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" }}

8 changes: 8 additions & 0 deletions 99-MicroHack-Template/labautomation/lab-defaults.json
Original file line number Diff line number Diff line change
@@ -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": 25.0
}
34 changes: 34 additions & 0 deletions lab-defaults-schema.json
Original file line number Diff line number Diff line change
@@ -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
}
Loading