Skip to content

Commit 09f9285

Browse files
committed
Fix subscription picker: default to empty for optional, use schema order for nested keys
1 parent ebd82c8 commit 09f9285

3 files changed

Lines changed: 40 additions & 17 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/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)