Skip to content

Commit b3d8feb

Browse files
committed
tidy up
1 parent edafac6 commit b3d8feb

File tree

8 files changed

+348
-219
lines changed

8 files changed

+348
-219
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
function ConvertTo-AcceleratorResult {
2+
<#
3+
.SYNOPSIS
4+
Creates a standardized result hashtable for accelerator configuration functions.
5+
.DESCRIPTION
6+
This function creates a consistent result structure used by accelerator configuration
7+
functions to return their status and configuration data.
8+
.PARAMETER Continue
9+
Boolean indicating whether to continue with deployment.
10+
.PARAMETER InputConfigFilePaths
11+
Array of input configuration file paths.
12+
.PARAMETER StarterAdditionalFiles
13+
Array of additional files/folders for the starter module.
14+
.PARAMETER OutputFolderPath
15+
Path to the output folder.
16+
.OUTPUTS
17+
Returns a hashtable with Continue, InputConfigFilePaths, StarterAdditionalFiles, and OutputFolderPath keys.
18+
.EXAMPLE
19+
return ConvertTo-AcceleratorResult -Continue $false
20+
.EXAMPLE
21+
return ConvertTo-AcceleratorResult -Continue $true -InputConfigFilePaths @("config/inputs.yaml") -OutputFolderPath "~/accelerator/output"
22+
#>
23+
[CmdletBinding()]
24+
param(
25+
[Parameter(Mandatory = $true)]
26+
[bool] $Continue,
27+
28+
[Parameter(Mandatory = $false)]
29+
[array] $InputConfigFilePaths = @(),
30+
31+
[Parameter(Mandatory = $false)]
32+
[array] $StarterAdditionalFiles = @(),
33+
34+
[Parameter(Mandatory = $false)]
35+
[string] $OutputFolderPath = ""
36+
)
37+
38+
return @{
39+
Continue = $Continue
40+
InputConfigFilePaths = $InputConfigFilePaths
41+
StarterAdditionalFiles = $StarterAdditionalFiles
42+
OutputFolderPath = $OutputFolderPath
43+
}
44+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
function Get-AcceleratorConfigPath {
2+
<#
3+
.SYNOPSIS
4+
Builds the input configuration file paths and additional files based on IaC type.
5+
.DESCRIPTION
6+
This function generates the list of configuration file paths and additional files
7+
needed for the accelerator based on the IaC type (terraform, bicep, etc.).
8+
.PARAMETER ConfigFolderPath
9+
The path to the config folder containing the configuration files.
10+
.PARAMETER IacType
11+
The Infrastructure as Code type (terraform, bicep, or bicep-classic).
12+
.OUTPUTS
13+
Returns a hashtable with the following keys:
14+
- InputConfigFilePaths: Array of input configuration file paths
15+
- StarterAdditionalFiles: Array of additional files/folders for the starter module
16+
#>
17+
[CmdletBinding()]
18+
param(
19+
[Parameter(Mandatory = $true)]
20+
[string] $ConfigFolderPath,
21+
22+
[Parameter(Mandatory = $true)]
23+
[AllowNull()]
24+
[string] $IacType
25+
)
26+
27+
$inputConfigFilePaths = @("$ConfigFolderPath/inputs.yaml")
28+
$starterAdditionalFiles = @()
29+
30+
switch ($IacType) {
31+
"terraform" {
32+
$inputConfigFilePaths += "$ConfigFolderPath/platform-landing-zone.tfvars"
33+
$libFolderPath = "$ConfigFolderPath/lib"
34+
if (Test-Path $libFolderPath) {
35+
$starterAdditionalFiles = @($libFolderPath)
36+
}
37+
}
38+
"bicep" {
39+
$inputConfigFilePaths += "$ConfigFolderPath/platform-landing-zone.yaml"
40+
}
41+
# bicep-classic and others just use inputs.yaml
42+
}
43+
44+
return @{
45+
InputConfigFilePaths = $inputConfigFilePaths
46+
StarterAdditionalFiles = $starterAdditionalFiles
47+
}
48+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
function Get-AcceleratorFolderConfiguration {
2+
<#
3+
.SYNOPSIS
4+
Detects and validates accelerator folder configuration from existing files.
5+
.DESCRIPTION
6+
This function examines an existing accelerator folder to detect the IaC type,
7+
version control system, and validate the configuration files.
8+
.PARAMETER FolderPath
9+
The path to the accelerator folder to analyze.
10+
.OUTPUTS
11+
Returns a hashtable with the following keys:
12+
- IsValid: Boolean indicating if valid configuration was found
13+
- IacType: Detected IaC type (terraform, bicep, or $null)
14+
- VersionControl: Detected version control (github, azure-devops, local, or $null)
15+
- ConfigFolderPath: Path to the config folder
16+
- InputsYamlPath: Path to inputs.yaml
17+
- InputsYaml: Parsed inputs.yaml content (if valid)
18+
- InputsContent: Raw inputs.yaml content (if valid)
19+
- ErrorMessage: Error message if validation failed
20+
#>
21+
[CmdletBinding()]
22+
param(
23+
[Parameter(Mandatory = $true)]
24+
[string] $FolderPath
25+
)
26+
27+
$result = @{
28+
FolderExists = $false
29+
IsValid = $false
30+
IacType = $null
31+
VersionControl = $null
32+
ConfigFolderPath = $null
33+
InputsYamlPath = $null
34+
InputsYaml = $null
35+
InputsContent = $null
36+
ErrorMessage = $null
37+
}
38+
39+
# Check if folder exists
40+
if (-not (Test-Path -Path $FolderPath)) {
41+
$result.ErrorMessage = "Folder '$FolderPath' does not exist."
42+
return $result
43+
}
44+
45+
$result.FolderExists = $true
46+
47+
$configFolderPath = Join-Path $FolderPath "config"
48+
$inputsYamlPath = Join-Path $configFolderPath "inputs.yaml"
49+
50+
$result.ConfigFolderPath = $configFolderPath
51+
$result.InputsYamlPath = $inputsYamlPath
52+
53+
# Check if config folder exists
54+
if (-not (Test-Path -Path $configFolderPath)) {
55+
$result.ErrorMessage = "Config folder not found at '$configFolderPath'"
56+
return $result
57+
}
58+
59+
# Check if inputs.yaml exists
60+
if (-not (Test-Path -Path $inputsYamlPath)) {
61+
$result.ErrorMessage = "Required configuration file not found: inputs.yaml"
62+
return $result
63+
}
64+
65+
# Try to read and validate inputs.yaml
66+
try {
67+
$inputsContent = Get-Content -Path $inputsYamlPath -Raw
68+
$inputsYaml = $inputsContent | ConvertFrom-Yaml
69+
70+
$result.InputsContent = $inputsContent
71+
$result.InputsYaml = $inputsYaml
72+
$result.IsValid = $true
73+
} catch {
74+
$result.ErrorMessage = "inputs.yaml is not valid YAML: $($_.Exception.Message)"
75+
return $result
76+
}
77+
78+
# Detect IaC type from existing files
79+
$tfvarsPath = Join-Path $configFolderPath "platform-landing-zone.tfvars"
80+
$bicepYamlPath = Join-Path $configFolderPath "platform-landing-zone.yaml"
81+
82+
if (Test-Path -Path $tfvarsPath) {
83+
$result.IacType = "terraform"
84+
} elseif (Test-Path -Path $bicepYamlPath) {
85+
$result.IacType = "bicep"
86+
}
87+
88+
# Detect version control from bootstrap_module_name in inputs.yaml
89+
if ($inputsYaml.bootstrap_module_name) {
90+
$bootstrapModuleName = $inputsYaml.bootstrap_module_name
91+
switch ($bootstrapModuleName) {
92+
"alz_github" { $result.VersionControl = "github" }
93+
"alz_azuredevops" { $result.VersionControl = "azure-devops" }
94+
"alz_local" { $result.VersionControl = "local" }
95+
}
96+
}
97+
98+
return $result
99+
}

0 commit comments

Comments
 (0)