-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathGet-AcceleratorFolderConfiguration.ps1
More file actions
102 lines (89 loc) · 3.58 KB
/
Get-AcceleratorFolderConfiguration.ps1
File metadata and controls
102 lines (89 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
function Get-AcceleratorFolderConfiguration {
<#
.SYNOPSIS
Detects and validates accelerator folder configuration from existing files.
.DESCRIPTION
This function examines an existing accelerator folder to detect the IaC type,
version control system, and validate the configuration files.
.PARAMETER FolderPath
The path to the accelerator folder to analyze.
.OUTPUTS
Returns a hashtable with the following keys:
- IsValid: Boolean indicating if valid configuration was found
- IacType: Detected IaC type (terraform, bicep, or $null)
- VersionControl: Detected version control (github, azure-devops, local, or $null)
- ConfigFolderPath: Path to the config folder
- InputsYamlPath: Path to inputs.yaml
- InputsYaml: Parsed inputs.yaml content (if valid)
- InputsContent: Raw inputs.yaml content (if valid)
- ErrorMessage: Error message if validation failed
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string] $FolderPath
)
$result = @{
FolderExists = $false
IsValid = $false
IacType = $null
VersionControl = $null
ConfigFolderPath = $null
OutputFolderPath = $null
InputsYamlPath = $null
InputsYaml = $null
InputsContent = $null
ErrorMessage = $null
}
# Check if folder exists
if (-not (Test-Path -Path $FolderPath)) {
$result.ErrorMessage = "Folder '$FolderPath' does not exist."
return $result
}
$result.FolderExists = $true
$configFolderPath = Join-Path $FolderPath "config"
$outputFolderPath = Join-Path $FolderPath "output"
$inputsYamlPath = Join-Path $configFolderPath "inputs.yaml"
$result.ConfigFolderPath = $configFolderPath
$result.OutputFolderPath = $outputFolderPath
$result.InputsYamlPath = $inputsYamlPath
# Check if config folder exists
if (-not (Test-Path -Path $configFolderPath)) {
$result.ErrorMessage = "Config folder not found at '$configFolderPath'"
return $result
}
# Check if inputs.yaml exists
if (-not (Test-Path -Path $inputsYamlPath)) {
$result.ErrorMessage = "Required configuration file not found: inputs.yaml"
return $result
}
# Try to read and validate inputs.yaml
try {
$inputsContent = Get-Content -Path $inputsYamlPath -Raw
$inputsYaml = $inputsContent | ConvertFrom-Yaml
$result.InputsContent = $inputsContent
$result.InputsYaml = $inputsYaml
$result.IsValid = $true
} catch {
$result.ErrorMessage = "inputs.yaml is not valid YAML: $($_.Exception.Message)"
return $result
}
# Detect IaC type from existing files
$tfvarsPath = Join-Path $configFolderPath "platform-landing-zone.tfvars"
$bicepYamlPath = Join-Path $configFolderPath "platform-landing-zone.yaml"
if (Test-Path -Path $tfvarsPath) {
$result.IacType = "terraform"
} elseif (Test-Path -Path $bicepYamlPath) {
$result.IacType = "bicep"
}
# Detect version control from bootstrap_module_name in inputs.yaml
if ($inputsYaml.bootstrap_module_name) {
$bootstrapModuleName = $inputsYaml.bootstrap_module_name
switch ($bootstrapModuleName) {
"alz_github" { $result.VersionControl = "github" }
"alz_azuredevops" { $result.VersionControl = "azure-devops" }
"alz_local" { $result.VersionControl = "local" }
}
}
return $result
}