Skip to content

Commit 2190423

Browse files
refactor: extract Terraform scenarios to JSON config and add SMB scenarios (#531)
## Summary Azure/Azure-Landing-Zones#4095 Extract the hardcoded Terraform scenario options from `Request-AcceleratorConfigurationInput.ps1` into a dedicated `TerraformScenarios.json` config file, making it easier to add, remove, or update scenarios without modifying PowerShell code. ## Changes - **New file**: `TerraformScenarios.json` - JSON array of scenario objects with `label` and `value` properties - **Modified**: `Request-AcceleratorConfigurationInput.ps1` - loads scenarios from the JSON file via `ConvertFrom-Json` instead of inline array - **Added scenarios 10-11**: SMB Single-Region Hub and Spoke VNet / Virtual WAN (per Azure/alz-terraform-accelerator#305)
1 parent a7b0b3c commit 2190423

5 files changed

Lines changed: 55 additions & 28 deletions

File tree

‎src/ALZ/Private/Deploy-Accelerator-Helpers/AcceleratorInputSchema.json‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,28 @@
2828
"type": "object",
2929
"required": true,
3030
"properties": {
31-
"management": {
32-
"description": "The subscription ID for the Management subscription where logging, monitoring, and automation resources will be deployed",
31+
"connectivity": {
32+
"description": "The subscription ID for the Connectivity subscription where networking resources like hubs, firewalls, and DNS will be deployed",
3333
"type": "guid",
3434
"required": true,
3535
"source": "subscription"
3636
},
3737
"identity": {
3838
"description": "The subscription ID for the Identity subscription where identity resources like domain controllers will be deployed",
3939
"type": "guid",
40-
"required": true,
40+
"required": false,
4141
"source": "subscription"
4242
},
43-
"connectivity": {
44-
"description": "The subscription ID for the Connectivity subscription where networking resources like hubs, firewalls, and DNS will be deployed",
43+
"management": {
44+
"description": "The subscription ID for the Management subscription where logging, monitoring, and automation resources will be deployed",
4545
"type": "guid",
4646
"required": true,
4747
"source": "subscription"
4848
},
4949
"security": {
5050
"description": "The subscription ID for the Security subscription where security monitoring and governance resources will be deployed",
5151
"type": "guid",
52-
"required": true,
52+
"required": false,
5353
"source": "subscription"
5454
}
5555
}

‎src/ALZ/Private/Deploy-Accelerator-Helpers/Request-ALZConfigurationValue.ps1‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ function Request-ALZConfigurationValue {
127127
$menuParams.ManualEntryPrompt = "Enter subscription ID"
128128
$menuParams.RequiredMessage = "This field is required. Please select a subscription."
129129
$menuParams.EmptyMessage = "No subscriptions found in Azure context."
130+
if (-not $isRequired) {
131+
$menuParams.ManualEntryLabel = "Enter manually or don't supply"
132+
$menuParams.DefaultToManualEntry = $true
133+
$menuParams.DefaultValue = ""
134+
}
130135
} elseif ($source -eq "managementGroup") {
131136
$menuParams.OptionsTitle = "Available management groups:"
132137
$menuParams.Options = $AzureContext.ManagementGroups
@@ -252,15 +257,13 @@ function Request-ALZConfigurationValue {
252257
continue
253258
}
254259

255-
foreach ($subKey in @($currentValue.Keys)) {
256-
$subCurrentValue = $currentValue[$subKey]
257-
$subSchemaInfo = $null
258-
259-
if ($nestedSchema.PSObject.Properties.Name -contains $subKey) {
260-
$subSchemaInfo = $nestedSchema.$subKey
261-
} else {
260+
# Iterate using schema property order to ensure consistent display ordering
261+
foreach ($subKey in @($nestedSchema.PSObject.Properties.Name)) {
262+
if (-not $currentValue.Contains($subKey)) {
262263
continue
263264
}
265+
$subCurrentValue = $currentValue[$subKey]
266+
$subSchemaInfo = $nestedSchema.$subKey
264267

265268
$result = Read-InputValue -Key $subKey -CurrentValue $subCurrentValue -SchemaInfo $subSchemaInfo -DefaultDescription "$key - $subKey" -AzureContext $AzureContext
266269
$subNewValue = $result.Value

‎src/ALZ/Private/Deploy-Accelerator-Helpers/Request-AcceleratorConfigurationInput.ps1‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,8 @@ function Request-AcceleratorConfigurationInput {
161161

162162
# Prompt for scenario number (Terraform only)
163163
if ($selectedIacType -eq "terraform") {
164-
$scenarioOptions = @(
165-
@{ label = "1 - Full Multi-Region - Hub and Spoke VNet"; value = 1 },
166-
@{ label = "2 - Full Multi-Region - Virtual WAN"; value = 2 },
167-
@{ label = "3 - Full Multi-Region NVA - Hub and Spoke VNet"; value = 3 },
168-
@{ label = "4 - Full Multi-Region NVA - Virtual WAN"; value = 4 },
169-
@{ label = "5 - Management Only"; value = 5 },
170-
@{ label = "6 - Full Single-Region - Hub and Spoke VNet"; value = 6 },
171-
@{ label = "7 - Full Single-Region - Virtual WAN"; value = 7 },
172-
@{ label = "8 - Full Single-Region NVA - Hub and Spoke VNet"; value = 8 },
173-
@{ label = "9 - Full Single-Region NVA - Virtual WAN"; value = 9 }
174-
)
164+
$scenariosJsonPath = Join-Path $PSScriptRoot "TerraformScenarios.json"
165+
$scenarioOptions = Get-Content -Path $scenariosJsonPath -Raw | ConvertFrom-Json
175166

176167
$selectedScenarioNumber = Read-MenuSelection `
177168
-Title "Select the Terraform scenario (see https://aka.ms/alz/acc/scenarios):" `
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{ "label": "1 - Full Multi-Region - Hub and Spoke VNet", "value": 1 },
3+
{ "label": "2 - Full Multi-Region - Virtual WAN", "value": 2 },
4+
{ "label": "3 - Full Multi-Region NVA - Hub and Spoke VNet", "value": 3 },
5+
{ "label": "4 - Full Multi-Region NVA - Virtual WAN", "value": 4 },
6+
{ "label": "5 - Management Only", "value": 5 },
7+
{ "label": "6 - Full Single-Region - Hub and Spoke VNet", "value": 6 },
8+
{ "label": "7 - Full Single-Region - Virtual WAN", "value": 7 },
9+
{ "label": "8 - Full Single-Region NVA - Hub and Spoke VNet", "value": 8 },
10+
{ "label": "9 - Full Single-Region NVA - Virtual WAN", "value": 9 },
11+
{ "label": "10 - SMB Single-Region - Hub and Spoke VNet", "value": 10 },
12+
{ "label": "11 - SMB Single-Region - Virtual WAN", "value": 11 }
13+
]

‎src/ALZ/Private/Shared/Read-MenuSelection.ps1‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ function Read-MenuSelection {
7373
[Parameter(Mandatory = $false)]
7474
[switch] $AllowManualEntry,
7575

76+
[Parameter(Mandatory = $false)]
77+
[string] $ManualEntryLabel = "Enter manually",
78+
79+
[Parameter(Mandatory = $false)]
80+
[switch] $DefaultToManualEntry,
81+
7682
[Parameter(Mandatory = $false)]
7783
[string] $ManualEntryPrompt = "Enter value",
7884

@@ -331,7 +337,12 @@ function Read-MenuSelection {
331337

332338
# Show manual entry option if allowed
333339
if ($AllowManualEntry.IsPresent) {
334-
Write-ToConsoleLog "[0] Enter manually" -IsSelection -IndentLevel 1
340+
$manualEntryMarker = if ($DefaultToManualEntry.IsPresent) { " (current)" } else { "" }
341+
if ($DefaultToManualEntry.IsPresent) {
342+
Write-ToConsoleLog "[0] $ManualEntryLabel$manualEntryMarker" -IsSelection -Color Green -IndentLevel 1
343+
} else {
344+
Write-ToConsoleLog "[0] $ManualEntryLabel" -IsSelection -IndentLevel 1
345+
}
335346
}
336347

337348
# Build prompt text
@@ -340,16 +351,25 @@ function Read-MenuSelection {
340351
if ($AllowManualEntry.IsPresent) {
341352
$promptText += ", 0 for manual entry"
342353
}
343-
$promptText += ", default: $($DefaultIndex + 1))"
354+
if ($DefaultToManualEntry.IsPresent) {
355+
$promptText += ", default: 0)"
356+
} else {
357+
$promptText += ", default: $($DefaultIndex + 1))"
358+
}
344359

345360
# Get selection
346361
$result = $null
347362
do {
348363
$selection = Read-InputValue -Prompt $promptText -Sensitive $IsSensitive.IsPresent
349364

350365
if ([string]::IsNullOrWhiteSpace($selection)) {
351-
# Use default
352-
$result = Get-OptionValue -Option $Options[$DefaultIndex]
366+
if ($DefaultToManualEntry.IsPresent) {
367+
# Default to manual entry - return DefaultValue (empty string)
368+
$result = if ($null -ne $DefaultValue) { $DefaultValue } else { "" }
369+
} else {
370+
# Use default option
371+
$result = Get-OptionValue -Option $Options[$DefaultIndex]
372+
}
353373
} elseif ($AllowManualEntry.IsPresent -and $selection -eq "0") {
354374
# Manual entry
355375
do {

0 commit comments

Comments
 (0)