Skip to content

Commit 2290e7c

Browse files
feat: flatten permissions (#525)
## Pull Request Improve cleanup and flatten permissions
1 parent 2837072 commit 2290e7c

41 files changed

Lines changed: 2691 additions & 1220 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/ALZ/ALZ.psd1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Included Cmdlets:
4141
- Grant-SubscriptionCreatorRole: Grants the Subscription Creator role to a specified user or service principal.
4242
- Remove-PlatformLandingZone: Removes the deployed Azure Landing Zone from your Azure subscription
4343
- New-AcceleratorFolderStructure: Creates a new folder structure for the Azure Landing Zone accelerator with necessary configuration files.
44+
- Remove-GitHubAccelerator: Removes GitHub resources (repositories, teams, runner groups) created by the ALZ accelerator bootstrap.
45+
- Remove-AzureDevOpsAccelerator: Removes Azure DevOps resources (projects, agent pools) created by the ALZ accelerator bootstrap.
4446
'@
4547

4648
CompatiblePSEditions = 'Core'
@@ -87,7 +89,9 @@ Included Cmdlets:
8789
'Deploy-Accelerator',
8890
'Grant-SubscriptionCreatorRole',
8991
'Remove-PlatformLandingZone',
90-
'New-AcceleratorFolderStructure'
92+
'New-AcceleratorFolderStructure',
93+
'Remove-GitHubAccelerator',
94+
'Remove-AzureDevOpsAccelerator'
9195
)
9296

9397
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.

src/ALZ/Private/Config-Helpers/Format-TokenizedConfigurationString.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function Format-TokenizedConfigurationString {
1515
if ($null -ne $configuration.$value) {
1616
$returnValue += $configuration.$value.Value
1717
} elseif (($null -eq $configuration.$value) -and $isToken) {
18-
Write-InformationColored "Specified replacement token '${value}' not found in configuration." -ForegroundColor Yellow -InformationAction Continue
18+
Write-ToConsoleLog "Specified replacement token '${value}' not found in configuration." -IsWarning
1919
$returnValue += "{%$value%}"
2020
} else {
2121
$returnValue += $value

src/ALZ/Private/Config-Helpers/Remove-TerraformMetaFileSet.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ function Remove-TerraformMetaFileSet {
1212
".terraform.lock.hcl",
1313
"examples",
1414
"yaml.tf",
15-
".alzlib"
15+
".alzlib",
16+
"tfplan",
17+
"tfplan.json"
1618
),
1719
[Parameter(Mandatory = $false)]
1820
[switch]$writeVerboseLogs

src/ALZ/Private/Config-Helpers/Set-Config.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ function Set-Config {
150150
continue
151151
}
152152

153-
Write-InformationColored "Input not supplied, and no default for $($configurationValue.Name)..." -ForegroundColor Red -InformationAction Continue
153+
Write-ToConsoleLog "Input not supplied, and no default for $($configurationValue.Name)..." -IsError
154154
throw "Input not supplied, and no default for $($configurationValue.Name)..."
155155
}
156156

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

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,25 @@
3030
"properties": {
3131
"management": {
3232
"description": "The subscription ID for the Management subscription where logging, monitoring, and automation resources will be deployed",
33-
"type": "string",
34-
"format": "guid",
33+
"type": "guid",
3534
"required": true,
3635
"source": "subscription"
3736
},
3837
"identity": {
3938
"description": "The subscription ID for the Identity subscription where identity resources like domain controllers will be deployed",
40-
"type": "string",
41-
"format": "guid",
39+
"type": "guid",
4240
"required": true,
4341
"source": "subscription"
4442
},
4543
"connectivity": {
4644
"description": "The subscription ID for the Connectivity subscription where networking resources like hubs, firewalls, and DNS will be deployed",
47-
"type": "string",
48-
"format": "guid",
45+
"type": "guid",
4946
"required": true,
5047
"source": "subscription"
5148
},
5249
"security": {
5350
"description": "The subscription ID for the Security subscription where security monitoring and governance resources will be deployed",
54-
"type": "string",
55-
"format": "guid",
51+
"type": "guid",
5652
"required": true,
5753
"source": "subscription"
5854
}
@@ -61,8 +57,7 @@
6157
"bootstrap_subscription_id": {
6258
"description": "The subscription ID where bootstrap resources will be created. See Decision 8 in the planning phase.",
6359
"helpLink": "https://azure.github.io/Azure-Landing-Zones/accelerator/0_planning/#decision-8---choose-the-bootstrap-subscription",
64-
"type": "string",
65-
"format": "guid",
60+
"type": "guid",
6661
"required": true,
6762
"source": "subscription"
6863
},
@@ -190,12 +185,6 @@
190185
"type": "boolean",
191186
"required": true
192187
},
193-
"grant_permissions_to_current_user": {
194-
"description": "Whether to grant permissions for the current Azure CLI user to be able to deploy the Platform Landing Zones. Set to false if you plan to configure a third-party Version Control System.",
195-
"helpLink": "https://azure.github.io/Azure-Landing-Zones/accelerator/advancedscenarios/",
196-
"type": "boolean",
197-
"required": true
198-
},
199188
"target_directory": {
200189
"description": "The target directory for generated files. Leave empty to use the standard output directory.",
201190
"helpLink": "https://azure.github.io/Azure-Landing-Zones/accelerator/advancedscenarios/",

src/ALZ/Private/Deploy-Accelerator-Helpers/Get-AzureContext.ps1

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ function Get-AzureContext {
1414
When set, clears the cached Azure context and fetches fresh data from Azure.
1515
.OUTPUTS
1616
Returns a hashtable with the following keys:
17-
- ManagementGroups: Array of objects with id and displayName properties
18-
- Subscriptions: Array of objects with id and name properties
19-
- Regions: Array of objects with name, displayName, and hasAvailabilityZones properties
17+
- ManagementGroups: Array of label/value objects for menu selection
18+
- Subscriptions: Array of label/value objects for menu selection
19+
- Regions: Array of label/value objects for menu selection (includes [AZ] indicator)
2020
#>
2121
[CmdletBinding()]
2222
param(
@@ -35,7 +35,7 @@ function Get-AzureContext {
3535
# Clear cache if requested
3636
if ($ClearCache.IsPresent -and (Test-Path $cacheFilePath)) {
3737
Remove-Item -Path $cacheFilePath -Force
38-
Write-InformationColored "Azure context cache cleared." -ForegroundColor Yellow -InformationAction Continue
38+
Write-ToConsoleLog "Azure context cache cleared." -IsSuccess
3939
}
4040

4141
# Check if valid cache exists
@@ -45,8 +45,8 @@ function Get-AzureContext {
4545
if ($cacheAge.TotalHours -lt $cacheExpirationHours) {
4646
try {
4747
$cachedContext = Get-Content -Path $cacheFilePath -Raw | ConvertFrom-Json -AsHashtable
48-
Write-InformationColored "Using cached Azure context (cached $([math]::Round($cacheAge.TotalMinutes)) minutes ago). Use -clearCache to refresh." -ForegroundColor Gray -InformationAction Continue
49-
Write-InformationColored " Found $($cachedContext.ManagementGroups.Count) management groups, $($cachedContext.Subscriptions.Count) subscriptions, and $($cachedContext.Regions.Count) regions" -ForegroundColor Gray -InformationAction Continue
48+
Write-ToConsoleLog "Using cached Azure context (cached $([math]::Round($cacheAge.TotalMinutes)) minutes ago). Use -clearCache to refresh."
49+
Write-ToConsoleLog "Found $($cachedContext.ManagementGroups.Count) management groups, $($cachedContext.Subscriptions.Count) subscriptions, and $($cachedContext.Regions.Count) regions"
5050
return $cachedContext
5151
} catch {
5252
Write-Verbose "Failed to read cache file, will fetch fresh data."
@@ -60,7 +60,7 @@ function Get-AzureContext {
6060
Regions = @()
6161
}
6262

63-
Write-InformationColored "Querying Azure for management groups, subscriptions, and regions..." -ForegroundColor Green -InformationAction Continue
63+
Write-ToConsoleLog "Querying Azure for management groups, subscriptions, and regions..."
6464

6565
try {
6666
# Get the current tenant ID
@@ -70,7 +70,15 @@ function Get-AzureContext {
7070
# Get management groups
7171
$mgResult = az account management-group list --query "[].{id:name, displayName:displayName}" -o json 2>$null
7272
if ($LASTEXITCODE -eq 0 -and $mgResult) {
73-
$azureContext.ManagementGroups = $mgResult | ConvertFrom-Json
73+
$mgRaw = $mgResult | ConvertFrom-Json
74+
$azureContext.ManagementGroups = @($mgRaw | ForEach-Object {
75+
@{
76+
label = "$($_.displayName) ($($_.id))"
77+
value = $_.id
78+
}
79+
})
80+
} else {
81+
Write-ToConsoleLog "No management groups found or access denied." -IsWarning
7482
}
7583

7684
# Get subscriptions (filtered to current tenant only, sorted by name)
@@ -80,16 +88,33 @@ function Get-AzureContext {
8088
$subResult = az account list --query "sort_by([].{id:id, name:name}, &name)" -o json 2>$null
8189
}
8290
if ($LASTEXITCODE -eq 0 -and $subResult) {
83-
$azureContext.Subscriptions = $subResult | ConvertFrom-Json
91+
$subRaw = $subResult | ConvertFrom-Json
92+
$azureContext.Subscriptions = @($subRaw | ForEach-Object {
93+
@{
94+
label = "$($_.name) ($($_.id))"
95+
value = $_.id
96+
}
97+
})
98+
} else {
99+
Write-ToConsoleLog "No subscriptions found or access denied." -IsWarning
84100
}
85101

86102
# Get regions (sorted by displayName, include availability zone support)
87103
$regionResult = az account list-locations --query "sort_by([?metadata.regionType=='Physical'].{name:name, displayName:displayName, hasAvailabilityZones:length(availabilityZoneMappings || ``[]``) > ``0``}, &displayName)" -o json 2>$null
88104
if ($LASTEXITCODE -eq 0 -and $regionResult) {
89-
$azureContext.Regions = $regionResult | ConvertFrom-Json
105+
$regionRaw = $regionResult | ConvertFrom-Json
106+
$azureContext.Regions = @($regionRaw | ForEach-Object {
107+
$azIndicator = if ($_.hasAvailabilityZones) { " [AZ]" } else { "" }
108+
@{
109+
label = "$($_.displayName) ($($_.name))$azIndicator"
110+
value = $_.name
111+
}
112+
})
113+
} else {
114+
Write-ToConsoleLog "No regions found or access denied." -IsWarning
90115
}
91116

92-
Write-InformationColored " Found $($azureContext.ManagementGroups.Count) management groups, $($azureContext.Subscriptions.Count) subscriptions, and $($azureContext.Regions.Count) regions" -ForegroundColor Gray -InformationAction Continue
117+
Write-ToConsoleLog "Found $($azureContext.ManagementGroups.Count) management groups, $($azureContext.Subscriptions.Count) subscriptions, and $($azureContext.Regions.Count) regions"
93118

94119
# Save to cache
95120
try {
@@ -102,7 +127,7 @@ function Get-AzureContext {
102127
Write-Verbose "Failed to write cache file: $_"
103128
}
104129
} catch {
105-
Write-InformationColored " Warning: Could not query Azure resources. You will need to enter IDs manually." -ForegroundColor Yellow -InformationAction Continue
130+
Write-ToConsoleLog "Could not query Azure resources. You will need to enter IDs manually." -IsWarning
106131
}
107132

108133
return $azureContext

src/ALZ/Private/Deploy-Accelerator-Helpers/Get-BootstrapAndStarterConfig.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function Get-BootstrapAndStarterConfig {
3434
# Get the bootstrap details and validate it exists (use alias for legacy values)
3535
$bootstrapDetails = $bootstrapModules.PsObject.Properties | Where-Object { $_.Name -eq $bootstrap -or $bootstrap -in $_.Value.aliases }
3636
if($null -eq $bootstrapDetails) {
37-
Write-InformationColored "The bootstrap type '$bootstrap' that you have selected does not exist. Please try again with a valid bootstrap type..." -ForegroundColor Red -InformationAction Continue
37+
Write-ToConsoleLog "The bootstrap type '$bootstrap' that you have selected does not exist. Please try again with a valid bootstrap type..." -IsError
3838
throw
3939
}
4040

@@ -48,7 +48,7 @@ function Get-BootstrapAndStarterConfig {
4848
$starterModuleType = $bootstrapStarterModule.Value
4949
$starterModuleDetails = $starterModules.PSObject.Properties | Where-Object { $_.Name -eq $starterModuleType }
5050
if($null -eq $starterModuleDetails) {
51-
Write-InformationColored "The starter modules '$($starterModuleType)' for the bootstrap type '$bootstrap' that you have selected does not exist. This could be an issue with your custom configuration, please check and try again..." -ForegroundColor Red -InformationAction Continue
51+
Write-ToConsoleLog "The starter modules '$($starterModuleType)' for the bootstrap type '$bootstrap' that you have selected does not exist. This could be an issue with your custom configuration, please check and try again..." -IsError
5252
throw
5353
}
5454

src/ALZ/Private/Deploy-Accelerator-Helpers/Invoke-Terraform.ps1

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function Invoke-Terraform {
6161
}
6262

6363
if (!$silent) {
64-
Write-InformationColored "Terraform init has completed, now running the $action..." -ForegroundColor Green -NewLineBefore -InformationAction Continue
64+
Write-ToConsoleLog "Terraform init has completed, now running the $action..." -IsSuccess
6565
}
6666

6767
$planFileName = "tfplan"
@@ -85,7 +85,7 @@ function Invoke-Terraform {
8585
}
8686

8787
if (!$silent) {
88-
Write-InformationColored "Running Plan Command for $action : $command $arguments" -ForegroundColor Green -NewLineBefore -InformationAction Continue
88+
Write-ToConsoleLog "Running Plan Command for $action : $command $arguments" -IsSuccess
8989
& $command $arguments
9090
} else {
9191
& $command $arguments | Write-Verbose
@@ -96,23 +96,23 @@ function Invoke-Terraform {
9696
# Stop and display timer
9797
$StopWatch.Stop()
9898
if (!$silent) {
99-
Write-InformationColored "Time taken to complete Terraform plan:" -ForegroundColor Green -NewLineBefore -InformationAction Continue
99+
Write-ToConsoleLog "Time taken to complete Terraform plan:" -IsSuccess
100100
}
101101
$StopWatch.Elapsed | Format-Table
102102

103103
if ($exitCode -ne 0) {
104-
Write-InformationColored "Terraform plan for $action failed with exit code $exitCode. Please review the error and try again or raise an issue." -ForegroundColor Red -NewLineBefore -InformationAction Continue
104+
Write-ToConsoleLog "Terraform plan for $action failed with exit code $exitCode. Please review the error and try again or raise an issue." -IsError
105105
throw "Terraform plan failed with exit code $exitCode. Please review the error and try again or raise an issue."
106106
}
107107

108108
if (!$autoApprove) {
109-
Write-InformationColored "Terraform plan has completed, please review the plan and confirm you wish to continue." -ForegroundColor Yellow -NewLineBefore -InformationAction Continue
109+
Write-ToConsoleLog "Terraform plan has completed, please review the plan and confirm you wish to continue." -IsWarning
110110
$choices = [System.Management.Automation.Host.ChoiceDescription[]] @("&Yes", "&No")
111111
$message = "Please confirm you wish to apply the plan."
112112
$title = "Confirm Terraform plan"
113113
$resultIndex = $host.ui.PromptForChoice($title, $message, $choices, 0)
114114
if ($resultIndex -eq 1) {
115-
Write-InformationColored "You have chosen not to apply the plan. Exiting..." -ForegroundColor Red -NewLineBefore -InformationAction Continue
115+
Write-ToConsoleLog "You have chosen not to apply the plan. Exiting..." -IsError
116116
return
117117
}
118118
}
@@ -130,7 +130,7 @@ function Invoke-Terraform {
130130
$arguments += "$planFileName"
131131

132132
if (!$silent) {
133-
Write-InformationColored "Running Apply Command for $action : $command $arguments" -ForegroundColor Green -NewLineBefore -InformationAction Continue
133+
Write-ToConsoleLog "Running Apply Command for $action : $command $arguments"
134134
& $command $arguments
135135
} else {
136136
& $command $arguments | Write-Verbose
@@ -142,7 +142,7 @@ function Invoke-Terraform {
142142
$maxAttempts = 5
143143

144144
while ($exitCode -ne 0 -and $currentAttempt -lt $maxAttempts) {
145-
Write-InformationColored "Terraform $action failed with exit code $exitCode. This is likely a transient issue, so we are retrying..." -ForegroundColor Yellow -NewLineBefore -InformationAction Continue
145+
Write-ToConsoleLog "Terraform $action failed with exit code $exitCode. This is likely a transient issue, so we are retrying..." -IsWarning
146146
$currentAttempt++
147147
$command = "terraform"
148148
$arguments = @()
@@ -157,7 +157,7 @@ function Invoke-Terraform {
157157
$arguments += "-destroy"
158158
}
159159

160-
Write-InformationColored "Running Apply Command for $action : $command $arguments" -ForegroundColor Green -NewLineBefore -InformationAction Continue
160+
Write-ToConsoleLog "Retry Attempt $($currentAttempt) of $($maxAttempts): Running Apply Command for $action : $command $arguments"
161161
& $command $arguments
162162
$exitCode = $LASTEXITCODE
163163
}
@@ -170,12 +170,12 @@ function Invoke-Terraform {
170170
# Stop and display timer
171171
$StopWatch.Stop()
172172
if (!$silent) {
173-
Write-InformationColored "Time taken to complete Terraform apply:" -ForegroundColor Green -NewLineBefore -InformationAction Continue
173+
Write-ToConsoleLog "Time taken to complete Terraform apply:"
174174
}
175175
$StopWatch.Elapsed | Format-Table
176176

177177
if ($exitCode -ne 0) {
178-
Write-InformationColored "Terraform $action failed with exit code $exitCode after $maxAttempts attempts. Please review the error and try again or raise an issue." -ForegroundColor Red -NewLineBefore -InformationAction Continue
178+
Write-ToConsoleLog "Terraform $action failed with exit code $exitCode after $maxAttempts attempts. Please review the error and try again or raise an issue." -IsError
179179
throw "Terraform $action failed with exit code $exitCode after $maxAttempts attempts. Please review the error and try again or raise an issue."
180180
} else {
181181
if ($output -ne "") {

0 commit comments

Comments
 (0)