Skip to content

Commit edafac6

Browse files
committed
remove bicep classic and minor improvements
1 parent 8525395 commit edafac6

File tree

2 files changed

+111
-125
lines changed

2 files changed

+111
-125
lines changed

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

Lines changed: 106 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,17 @@ function Request-AcceleratorConfigurationInput {
5151
$inputsYamlPath = $null
5252
$inputsContent = $null
5353
$useExistingFolder = $false
54+
$forceFlag = $false
5455

55-
# If folder exists, try to detect configuration from existing files
56+
# If folder exists, ask about overwriting before other prompts
5657
if ($folderExists) {
5758
$configFolderPath = Join-Path $normalizedTargetPath "config"
5859
$inputsYamlPath = Join-Path $configFolderPath "inputs.yaml"
5960

60-
if ((Test-Path -Path $configFolderPath) -and (Test-Path -Path $inputsYamlPath)) {
61+
# Check if valid config exists
62+
$hasValidConfig = (Test-Path -Path $configFolderPath) -and (Test-Path -Path $inputsYamlPath)
63+
64+
if ($hasValidConfig) {
6165
Write-InformationColored "`nDetected existing accelerator folder. Analyzing configuration..." -ForegroundColor Cyan -InformationAction Continue
6266

6367
# Try to read and validate inputs.yaml
@@ -75,9 +79,6 @@ function Request-AcceleratorConfigurationInput {
7579
} elseif (Test-Path -Path $bicepYamlPath) {
7680
$detectedIacType = "bicep"
7781
Write-InformationColored " Detected IaC type: bicep (found platform-landing-zone.yaml)" -ForegroundColor Green -InformationAction Continue
78-
} else {
79-
$detectedIacType = "bicep-classic"
80-
Write-InformationColored " Detected IaC type: bicep-classic" -ForegroundColor Green -InformationAction Continue
8182
}
8283

8384
# Detect version control from bootstrap_module_name in inputs.yaml
@@ -99,6 +100,34 @@ function Request-AcceleratorConfigurationInput {
99100
} catch {
100101
Write-InformationColored " Warning: inputs.yaml exists but is not valid YAML: $($_.Exception.Message)" -ForegroundColor Yellow -InformationAction Continue
101102
$inputsContent = $null
103+
$hasValidConfig = $false
104+
}
105+
}
106+
107+
# Ask about overwriting the folder
108+
Write-InformationColored "`nTarget folder '$normalizedTargetPath' already exists." -ForegroundColor Yellow -InformationAction Continue
109+
$forceResponse = Read-Host "Do you want to overwrite it? (y/N)"
110+
if ($forceResponse -eq "y" -or $forceResponse -eq "Y") {
111+
$forceFlag = $true
112+
# Clear detected values since we're recreating - they'll be used as defaults in prompts
113+
} else {
114+
# User wants to keep existing folder
115+
$useExistingFolder = $true
116+
117+
# Validate config files exist
118+
if (-not $hasValidConfig) {
119+
if (-not (Test-Path -Path $configFolderPath)) {
120+
Write-InformationColored "ERROR: Config folder not found at '$configFolderPath'" -ForegroundColor Red -InformationAction Continue
121+
} elseif (-not (Test-Path -Path $inputsYamlPath)) {
122+
Write-InformationColored "ERROR: Required configuration file not found: inputs.yaml" -ForegroundColor Red -InformationAction Continue
123+
}
124+
Write-InformationColored "Please overwrite the folder structure by choosing 'y', or run New-AcceleratorFolderStructure manually." -ForegroundColor Yellow -InformationAction Continue
125+
return @{
126+
Continue = $false
127+
InputConfigFilePaths = @()
128+
StarterAdditionalFiles = @()
129+
OutputFolderPath = ""
130+
}
102131
}
103132
}
104133
}
@@ -167,137 +196,90 @@ function Request-AcceleratorConfigurationInput {
167196
}
168197
}
169198

170-
# Normal mode continues here - prompt for IaC type with detected value as default
171-
$iacTypeOptions = @("terraform", "bicep", "bicep-classic")
172-
$defaultIacTypeIndex = 0
173-
if ($null -ne $detectedIacType) {
174-
$detectedIndex = $iacTypeOptions.IndexOf($detectedIacType)
175-
if ($detectedIndex -ge 0) {
176-
$defaultIacTypeIndex = $detectedIndex
177-
}
178-
}
179-
180-
Write-InformationColored "`nSelect the Infrastructure as Code (IaC) type:" -ForegroundColor Yellow -InformationAction Continue
181-
for ($i = 0; $i -lt $iacTypeOptions.Count; $i++) {
182-
$default = if ($i -eq $defaultIacTypeIndex) { " (Default)" } else { "" }
183-
$recommended = if ($iacTypeOptions[$i] -eq "terraform" -or $iacTypeOptions[$i] -eq "bicep") { " (Recommended)" } else { " (Not Recommended)" }
184-
Write-InformationColored " [$($i + 1)] $($iacTypeOptions[$i])$default$recommended" -ForegroundColor White -InformationAction Continue
185-
}
186-
do {
187-
$iacTypeSelection = Read-Host "Enter selection (1-$($iacTypeOptions.Count), default: $($defaultIacTypeIndex + 1))"
188-
if ([string]::IsNullOrWhiteSpace($iacTypeSelection)) {
189-
$iacTypeIndex = $defaultIacTypeIndex
190-
} else {
191-
$iacTypeIndex = [int]$iacTypeSelection - 1
192-
}
193-
} while ($iacTypeIndex -lt 0 -or $iacTypeIndex -ge $iacTypeOptions.Count)
194-
$selectedIacType = $iacTypeOptions[$iacTypeIndex]
195-
196-
# Prompt for version control with detected value as default
197-
$versionControlOptions = @("github", "azure-devops", "local")
198-
$defaultVcsIndex = 0
199-
if ($null -ne $detectedVersionControl) {
200-
$detectedIndex = $versionControlOptions.IndexOf($detectedVersionControl)
201-
if ($detectedIndex -ge 0) {
202-
$defaultVcsIndex = $detectedIndex
203-
}
204-
}
199+
# Set selectedIacType and selectedVersionControl from detected values (for use existing folder case)
200+
$selectedIacType = $detectedIacType
201+
$selectedVersionControl = $detectedVersionControl
202+
$selectedScenarioNumber = 1
205203

206-
Write-InformationColored "`nSelect the Version Control System:" -ForegroundColor Yellow -InformationAction Continue
207-
for ($i = 0; $i -lt $versionControlOptions.Count; $i++) {
208-
$default = if ($i -eq $defaultVcsIndex) { " (Default)" } else { "" }
209-
Write-InformationColored " [$($i + 1)] $($versionControlOptions[$i])$default" -ForegroundColor White -InformationAction Continue
210-
}
211-
do {
212-
$vcsSelection = Read-Host "Enter selection (1-$($versionControlOptions.Count), default: $($defaultVcsIndex + 1))"
213-
if ([string]::IsNullOrWhiteSpace($vcsSelection)) {
214-
$vcsIndex = $defaultVcsIndex
215-
} else {
216-
$vcsIndex = [int]$vcsSelection - 1
204+
# Only prompt for IaC type, version control, and scenario if creating new folder or overwriting
205+
if (-not $useExistingFolder) {
206+
# Prompt for IaC type with detected value as default
207+
$iacTypeOptions = @("terraform", "bicep")
208+
$defaultIacTypeIndex = 0
209+
if ($null -ne $detectedIacType) {
210+
$detectedIndex = $iacTypeOptions.IndexOf($detectedIacType)
211+
if ($detectedIndex -ge 0) {
212+
$defaultIacTypeIndex = $detectedIndex
213+
}
217214
}
218-
} while ($vcsIndex -lt 0 -or $vcsIndex -ge $versionControlOptions.Count)
219-
$selectedVersionControl = $versionControlOptions[$vcsIndex]
220215

221-
# Prompt for scenario number (Terraform only)
222-
$selectedScenarioNumber = 1
223-
if ($selectedIacType -eq "terraform") {
224-
Write-InformationColored "`nSelect the Terraform scenario (see https://aka.ms/alz/acc/scenarios):" -ForegroundColor Yellow -InformationAction Continue
225-
$scenarioDescriptions = @(
226-
"Full Multi-Region - Hub and Spoke VNet",
227-
"Full Multi-Region - Virtual WAN",
228-
"Full Multi-Region NVA - Hub and Spoke VNet",
229-
"Full Multi-Region NVA - Virtual WAN",
230-
"Management Only",
231-
"Full Single-Region - Hub and Spoke VNet",
232-
"Full Single-Region - Virtual WAN",
233-
"Full Single-Region NVA - Hub and Spoke VNet",
234-
"Full Single-Region NVA - Virtual WAN"
235-
)
236-
for ($i = 0; $i -lt $scenarioDescriptions.Count; $i++) {
237-
$default = if ($i -eq 0) { " (Default)" } else { "" }
238-
Write-InformationColored " [$($i + 1)] $($scenarioDescriptions[$i])$default" -ForegroundColor White -InformationAction Continue
216+
Write-InformationColored "`nSelect the Infrastructure as Code (IaC) type:" -ForegroundColor Yellow -InformationAction Continue
217+
for ($i = 0; $i -lt $iacTypeOptions.Count; $i++) {
218+
$default = if ($i -eq $defaultIacTypeIndex) { " (Default)" } else { "" }
219+
Write-InformationColored " [$($i + 1)] $($iacTypeOptions[$i])$default" -ForegroundColor White -InformationAction Continue
239220
}
240221
do {
241-
$scenarioSelection = Read-Host "Enter selection (1-$($scenarioDescriptions.Count), default: 1)"
242-
if ([string]::IsNullOrWhiteSpace($scenarioSelection)) {
243-
$scenarioIndex = 1
222+
$iacTypeSelection = Read-Host "Enter selection (1-$($iacTypeOptions.Count), default: $($defaultIacTypeIndex + 1))"
223+
if ([string]::IsNullOrWhiteSpace($iacTypeSelection)) {
224+
$iacTypeIndex = $defaultIacTypeIndex
244225
} else {
245-
$scenarioIndex = [int]$scenarioSelection
226+
$iacTypeIndex = [int]$iacTypeSelection - 1
246227
}
247-
} while ($scenarioIndex -lt 1 -or $scenarioIndex -gt $scenarioDescriptions.Count)
248-
$selectedScenarioNumber = $scenarioIndex
249-
}
250-
251-
# Handle existing folder - prompt for recreate or use existing
252-
$forceFlag = $false
253-
if ($folderExists) {
254-
Write-InformationColored "`nTarget folder '$normalizedTargetPath' already exists." -ForegroundColor Yellow -InformationAction Continue
255-
$forceResponse = Read-Host "Do you want to recreate it? (y/N)"
256-
if ($forceResponse -eq "y" -or $forceResponse -eq "Y") {
257-
$forceFlag = $true
258-
} else {
259-
# User wants to keep existing folder - validate config files exist
260-
$useExistingFolder = $true
261-
262-
if (-not (Test-Path -Path $configFolderPath)) {
263-
Write-InformationColored "ERROR: Config folder not found at '$configFolderPath'" -ForegroundColor Red -InformationAction Continue
264-
Write-InformationColored "Please create the folder structure first by choosing 'y' to recreate, or run New-AcceleratorFolderStructure manually." -ForegroundColor Yellow -InformationAction Continue
265-
return @{
266-
Continue = $false
267-
InputConfigFilePaths = @()
268-
StarterAdditionalFiles = @()
269-
OutputFolderPath = ""
270-
}
228+
} while ($iacTypeIndex -lt 0 -or $iacTypeIndex -ge $iacTypeOptions.Count)
229+
$selectedIacType = $iacTypeOptions[$iacTypeIndex]
230+
231+
# Prompt for version control with detected value as default
232+
$versionControlOptions = @("github", "azure-devops", "local")
233+
$defaultVcsIndex = 0
234+
if ($null -ne $detectedVersionControl) {
235+
$detectedIndex = $versionControlOptions.IndexOf($detectedVersionControl)
236+
if ($detectedIndex -ge 0) {
237+
$defaultVcsIndex = $detectedIndex
271238
}
239+
}
272240

273-
if (-not (Test-Path -Path $inputsYamlPath)) {
274-
Write-InformationColored "ERROR: Required configuration file not found: inputs.yaml" -ForegroundColor Red -InformationAction Continue
275-
Write-InformationColored "Please create the folder structure first by choosing 'y' to recreate, or run New-AcceleratorFolderStructure manually." -ForegroundColor Yellow -InformationAction Continue
276-
return @{
277-
Continue = $false
278-
InputConfigFilePaths = @()
279-
StarterAdditionalFiles = @()
280-
OutputFolderPath = ""
281-
}
241+
Write-InformationColored "`nSelect the Version Control System:" -ForegroundColor Yellow -InformationAction Continue
242+
for ($i = 0; $i -lt $versionControlOptions.Count; $i++) {
243+
$default = if ($i -eq $defaultVcsIndex) { " (Default)" } else { "" }
244+
Write-InformationColored " [$($i + 1)] $($versionControlOptions[$i])$default" -ForegroundColor White -InformationAction Continue
245+
}
246+
do {
247+
$vcsSelection = Read-Host "Enter selection (1-$($versionControlOptions.Count), default: $($defaultVcsIndex + 1))"
248+
if ([string]::IsNullOrWhiteSpace($vcsSelection)) {
249+
$vcsIndex = $defaultVcsIndex
250+
} else {
251+
$vcsIndex = [int]$vcsSelection - 1
282252
}
253+
} while ($vcsIndex -lt 0 -or $vcsIndex -ge $versionControlOptions.Count)
254+
$selectedVersionControl = $versionControlOptions[$vcsIndex]
283255

284-
# Validate that inputs.yaml is valid YAML (if not already validated)
285-
if ($null -eq $inputsContent) {
286-
$inputsContent = Get-Content -Path $inputsYamlPath -Raw
287-
try {
288-
$null = $inputsContent | ConvertFrom-Yaml
289-
} catch {
290-
Write-InformationColored "ERROR: inputs.yaml is not valid YAML." -ForegroundColor Red -InformationAction Continue
291-
Write-InformationColored "Parse error: $($_.Exception.Message)" -ForegroundColor Red -InformationAction Continue
292-
Write-InformationColored "Please fix the YAML syntax in '$inputsYamlPath' and try again." -ForegroundColor Yellow -InformationAction Continue
293-
return @{
294-
Continue = $false
295-
InputConfigFilePaths = @()
296-
StarterAdditionalFiles = @()
297-
OutputFolderPath = ""
298-
}
299-
}
256+
# Prompt for scenario number (Terraform only)
257+
if ($selectedIacType -eq "terraform") {
258+
Write-InformationColored "`nSelect the Terraform scenario (see https://aka.ms/alz/acc/scenarios):" -ForegroundColor Yellow -InformationAction Continue
259+
$scenarioDescriptions = @(
260+
"Full Multi-Region - Hub and Spoke VNet",
261+
"Full Multi-Region - Virtual WAN",
262+
"Full Multi-Region NVA - Hub and Spoke VNet",
263+
"Full Multi-Region NVA - Virtual WAN",
264+
"Management Only",
265+
"Full Single-Region - Hub and Spoke VNet",
266+
"Full Single-Region - Virtual WAN",
267+
"Full Single-Region NVA - Hub and Spoke VNet",
268+
"Full Single-Region NVA - Virtual WAN"
269+
)
270+
for ($i = 0; $i -lt $scenarioDescriptions.Count; $i++) {
271+
$default = if ($i -eq 0) { " (Default)" } else { "" }
272+
Write-InformationColored " [$($i + 1)] $($scenarioDescriptions[$i])$default" -ForegroundColor White -InformationAction Continue
300273
}
274+
do {
275+
$scenarioSelection = Read-Host "Enter selection (1-$($scenarioDescriptions.Count), default: 1)"
276+
if ([string]::IsNullOrWhiteSpace($scenarioSelection)) {
277+
$scenarioIndex = 1
278+
} else {
279+
$scenarioIndex = [int]$scenarioSelection
280+
}
281+
} while ($scenarioIndex -lt 1 -or $scenarioIndex -gt $scenarioDescriptions.Count)
282+
$selectedScenarioNumber = $scenarioIndex
301283
}
302284
}
303285

src/ALZ/Public/New-AcceleratorFolderStructure.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ function New-AcceleratorFolderStructure {
3939
if(Test-Path -Path $targetFolderPath) {
4040
if($force.IsPresent) {
4141
Write-Host "Force flag is set, removing existing target folder at $targetFolderPath"
42-
Remove-Item -Recurse -Force -Path $targetFolderPath | Write-Verbose | Out-Null
42+
try {
43+
Remove-Item -Recurse -Force -Path $targetFolderPath -ErrorAction Stop | Write-Verbose | Out-Null
44+
} catch {
45+
throw "Failed to remove existing folder at '$targetFolderPath'. The folder may be locked by another process or you may not have permission to remove it. Please close any applications that may be using files in this folder and try again. Error: $($_.Exception.Message)"
46+
}
4347
} else {
4448
throw "Target folder $targetFolderPath already exists. Please specify a different folder path or remove the existing folder."
4549
}

0 commit comments

Comments
 (0)