Skip to content

Commit

Permalink
enhancement: relocate bootstrap modules (#105)
Browse files Browse the repository at this point in the history
# Pull Request

## Issue

Issue #, if available: N/A

## Description

This PR is a significant refactor to de-couple bootstrap and starter
modules. It moves to a configuration based approach for shared inputs
and have many other enhancements to the user experience.

## License

By submitting this pull request, I confirm that my contribution is made
under the terms of the projects associated license.
  • Loading branch information
jaredfholgate authored Mar 13, 2024
1 parent 41a7a16 commit 6728899
Show file tree
Hide file tree
Showing 29 changed files with 1,128 additions and 607 deletions.
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,42 @@ Thumbs.db
src/ALZ/Assets/alz-bicep-internal/
test_output/
hcl2json_windows_amd64.exe

# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*
**/.terraform.lock.hcl

# Crash log files
crash.log

# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
# .tfvars files are managed as part of configuration and so should be included in
# version control.
#
# example.tfvars

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
#
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*
.terraform.lock.hcl
terraform.log
*.tfvars
!terraform.tfvars
templates/basic/terraform.tfvars
templates/.test_azuredevops
templates/.test_github
.vscode/settings.json
45 changes: 20 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
# ALZ
# ALZ / Accelerator PowerShell Module

[![license](https://img.shields.io/badge/License-MIT-purple.svg)](LICENSE)

![Logo](./docs/ALZLogo.png)

## Synopsis

This is a PowerShell module that provides a set of cmdlets to create and manage Azure Landing Zones.
This is a PowerShell module that provides a set of cmdlets to create and manage Accelerators for Azure Landing Zones and other workloads.

## Description

This module provides a set of cmdlets to create and manage Azure Landing Zones.
This module provides a set of cmdlets to create and manage Accelerators for Azure Landing Zones and other workloads.

## Why

The goal of this project it is to make easy to get started with Azure Landing Zones and to speed up some basic tasks that you would need to perform whilst managing your Azure Landing Zones.
The goal of this project it is to make easy to get started with Azure Landing Zones and other workloads. It is designed to speed up some basic tasks that you would need to perform whilst managing your Azure Landing Zones.

For usage of the Azure Landing Zoners Accelerators, please refer to the detailed documentation:

- [Bicep](https://github.com/Azure/ALZ-Bicep/wiki/Accelerator)
- [Terraform](https://github.com/Azure/alz-terraform-accelerator/wiki)

## Getting Started

Expand All @@ -24,11 +29,14 @@ In order to use this module you will need PowerShell 7.1 or higher.
Download and install the latest version from the official PowerShell GitHub releases page: [PowerShell Releases](https://github.com/PowerShell/PowerShell/releases)

To make PowerShell 7 your default instead of version 5, consider setting an alias.
Open a PowerShell session and run the following command:
```powershell

Open a PowerShell session and run the following command:

```powershell
$PSVersionTable.PSVersion
Set-Alias powershell pwsh
```

### Installation

You can install this module using PowerShellGet.
Expand Down Expand Up @@ -60,7 +68,7 @@ Before you start you can utilize the functionality of the module to verify if yo
#### Bicep

```powershell
Test-ALZRequirement -IaC "bicep"
Test-ALZRequirement -i "bicep"
```

Currently this tests for:
Expand All @@ -75,7 +83,7 @@ Currently this tests for:
#### Terraform

```powershell
Test-ALZRequirement -IaC "terraform"
Test-ALZRequirement -i "terraform"
```

This currently tests for:
Expand All @@ -88,38 +96,25 @@ This currently tests for:
#### Azure Landing Zone Environment with Bicep and GitHub Actions Workflows

```powershell
New-ALZEnvironment -o <output_directory> -i "bicep" -c "github"
Deploy-Accelerator -o <output_directory> -i "bicep" -b "alz_github"
```

#### Azure Landing Zone Environment with Bicep and Azure DevOps Pipelines

```powershell
New-ALZEnvironment -o <output_directory> -i "bicep" -c "azuredevops"
Deploy-Accelerator -o <output_directory> -i "bicep" -b "alz_azuredevops"
```

> **Note**
> Azure Devops Pipelines are only supported in v0.2.6 or later.
#### Azure Landing Zone Environment with Terraform and GitHub Pipelines

```powershell
New-ALZEnvironment -o <output_directory> -i "terraform" -c "github"
Deploy-Accelerator -o <output_directory> -i "terraform" -b "alz_github"
```

#### Azure Landing Zone Environment with Terraform and Azure DevOps Pipelines

```powershell
New-ALZEnvironment -o <output_directory> -i "terraform" -c "azuredevops"
```

## Additional Cmdlets

### Update an existing Azure Landing Zone Environment

#### Downloads and pulls down the specified release version from the remote GitHub repository to a local directory

```powershell
Get-ALZGithubRelease -i "bicep" -v "v0.14.0" -o "C:\Repos\ALZ\accelerator"
Deploy-Accelerator -o <output_directory> -i "terraform" -b "alz_azuredevops"
```

## Development
Expand Down
2 changes: 1 addition & 1 deletion src/ALZ/ALZ.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@

# Functions 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 functions to export.
FunctionsToExport = @(
'Get-ALZGithubRelease'
'New-ALZEnvironment'
'Test-ALZRequirement'
'Edit-LineEnding'
Expand All @@ -85,6 +84,7 @@
# Aliases 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 aliases to export.
AliasesToExport = @(
'Edit-LineEndings'
'Deploy-Accelerator'
)

# DSC resources to export from this module
Expand Down
2 changes: 1 addition & 1 deletion src/ALZ/Private/Build-ALZDeploymentEnvFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function Build-ALZDeploymentEnvFile {
foreach ($configurationValue in $configuration.PsObject.Properties) {
foreach ($target in $configurationValue.Value.Targets) {
if ($target.Destination -eq "Environment") {
Write-InformationColored $configurationValue.Name -ForegroundColor Green -InformationAction Continue
Write-Verbose "Creating environment files for: $($configurationValue.Name)"

if($configurationValue.Name -eq "UpstreamReleaseVersion") {
Add-Content -Path $envFile -Value "$($($target.Name))=`"$version`"" | Out-String | Write-Verbose
Expand Down
11 changes: 5 additions & 6 deletions src/ALZ/Private/Convert-HCLVariablesToUserInputConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ function Convert-HCLVariablesToUserInputConfig {
[PSCustomObject]$validators,

[Parameter(Mandatory = $false)]
[PSCustomObject]$appendToObject = $null
[PSCustomObject]$appendToObject = $null,

[Parameter(Mandatory = $false)]
[switch]$allComputedInputs
)

if ($PSCmdlet.ShouldProcess("Parse HCL Variables into Config", "modify")) {
Expand Down Expand Up @@ -49,12 +52,8 @@ function Convert-HCLVariablesToUserInputConfig {
$hasValidation = $true
}

if($hasValidation -and $validationType -eq "hidden") {
continue
}

$inputType = "UserInput"
if($hasValidation -and $validationType -like "hidden_*") {
if($allComputedInputs) {
$inputType = "ComputedInput"
}

Expand Down
72 changes: 72 additions & 0 deletions src/ALZ/Private/Convert-InterfaceInputToUserInputConfig.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
function Convert-InterfaceInputToUserInputConfig {
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[Parameter(Mandatory = $false)]
[PSCustomObject]$inputConfig,

[Parameter(Mandatory = $false)]
[PSCustomObject]$validators,

[Parameter(Mandatory = $false)]
[PSCustomObject]$appendToObject = $null
)

if ($PSCmdlet.ShouldProcess("Parse Interface Variables into Config", "modify")) {

$starterModuleConfiguration = [PSCustomObject]@{}
if($appendToObject -ne $null) {
$starterModuleConfiguration = $appendToObject
}

Write-Verbose $validators

foreach($variable in $inputConfig.inputs.PSObject.Properties) {
Write-Verbose "Parsing variable $($variable.Name)"
$description = $variable.Value.description

$order = 0
if($variable.PSObject.Properties.Name -contains "display_order") {
$order = $variable.Value.display_order
}

$inputType = $variable.Value.source -eq "input" ? "UserInput" : "ComputedInput"
$dataType = $variable.Value.type

$sensitive = $false
if($variable.Value.PSObject.Properties.Name -contains "sensitive") {
$sensitive = $variable.Value.sensitive
}

$starterModuleConfigurationInstance = [PSCustomObject]@{}
$starterModuleConfigurationInstance | Add-Member -NotePropertyName "Order" -NotePropertyValue $order
$starterModuleConfigurationInstance | Add-Member -NotePropertyName "Type" -NotePropertyValue $inputType
$starterModuleConfigurationInstance | Add-Member -NotePropertyName "Value" -NotePropertyValue ""
$starterModuleConfigurationInstance | Add-Member -NotePropertyName "DataType" -NotePropertyValue $dataType
$starterModuleConfigurationInstance | Add-Member -NotePropertyName "Sensitive" -NotePropertyValue $sensitive

if($variable.Value.PSObject.Properties.Name -contains "default") {
$defaultValue = $variable.Value.default
$starterModuleConfigurationInstance | Add-Member -NotePropertyName "DefaultValue" -NotePropertyValue $defaultValue
}

if($variable.Value.PSObject.Properties.Name -contains "validation") {
$validationType = $variable.Value.validation
$validator = $validators.PSObject.Properties[$validationType].Value
$description = "$description ($($validator.Description))"
Write-Verbose "Adding $($variable.Value.validation) validation for $($variable.Name). Validation type: $($validator.Type)"
if($validator.Type -eq "AllowedValues"){
$starterModuleConfigurationInstance | Add-Member -NotePropertyName "AllowedValues" -NotePropertyValue $validator.AllowedValues
}
if($validator.Type -eq "Valid"){
$starterModuleConfigurationInstance | Add-Member -NotePropertyName "Valid" -NotePropertyValue $validator.Valid
}
$starterModuleConfigurationInstance | Add-Member -NotePropertyName "Validator" -NotePropertyValue $validationType
}

$starterModuleConfigurationInstance | Add-Member -NotePropertyName "Description" -NotePropertyValue $description
$starterModuleConfiguration | Add-Member -NotePropertyName $variable.Name -NotePropertyValue $starterModuleConfigurationInstance
}
}

return $starterModuleConfiguration
}
2 changes: 1 addition & 1 deletion src/ALZ/Private/Edit-ALZConfigurationFilesInPlace.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function Edit-ALZConfigurationFilesInPlace {
}

if ($true -eq $modified) {
Write-InformationColored $file.FullName -ForegroundColor Yellow -InformationAction Continue
Write-Verbose $file.FullName
$bicepConfiguration | ConvertTo-Json -Depth 10 | Out-File $file.FullName
}
}
Expand Down
1 change: 1 addition & 0 deletions src/ALZ/Private/Get-ALZConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ function Get-ALZConfig {
throw "The config file must be a json or yaml/yml file"
}

Write-Verbose "Config file loaded from $configFilePath with $($config.PSObject.Properties.Count) properties."
return $config
}
29 changes: 29 additions & 0 deletions src/ALZ/Private/Get-ExistingLocalRelease.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function Get-ExistingLocalRelease {
param(
[Parameter(Mandatory = $false)]
[string] $targetDirectory,

[Parameter(Mandatory = $false)]
[string] $targetFolder
)

$releaseTag = ""
$path = ""
$checkPath = Join-Path $targetDirectory $targetFolder
$checkFolders = Get-ChildItem -Path $checkPath -Directory
if($null -ne $checkFolders) {
$checkFolders = $checkFolders | Sort-Object { $_.Name } -Descending
$mostRecentCheckFolder = $checkFolders[0]

$releaseTag = $mostRecentCheckFolder.Name
$path = $mostRecentCheckFolder.FullName
} else {
Write-InformationColored "You have passed the skipInternetChecks parameter, but there is no existing version in the $targetFolder module, so we can't continue."
throw
}

return @{
releaseTag = $releaseTag
path = $path
}
}
Loading

0 comments on commit 6728899

Please sign in to comment.