Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: relocate bootstrap modules #105

Merged
merged 35 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
dbb6d9f
Add bootstrap modules
jaredfholgate Feb 9, 2024
79c0c01
Tidy validators
jaredfholgate Feb 9, 2024
0222319
Save changes
jaredfholgate Feb 19, 2024
b327fab
Sort folder structures
jaredfholgate Feb 19, 2024
d4de8dd
Update bicep to target starter folder
jaredfholgate Feb 19, 2024
1d5cc85
Add paths and bicep local option
jaredfholgate Feb 19, 2024
5ee7637
Skip git when bootstrapping
jaredfholgate Feb 19, 2024
dbdddf4
Get file paths working
jaredfholgate Feb 19, 2024
ae4f26c
Save changes
jaredfholgate Feb 19, 2024
1f1ab7e
Save changes
jaredfholgate Feb 20, 2024
0b3d3c5
Refactor to support interface config
jaredfholgate Feb 21, 2024
a740b2b
Save fixes
jaredfholgate Feb 21, 2024
caf7566
Save changes
jaredfholgate Feb 21, 2024
d8d4112
Add alias support.
jaredfholgate Feb 21, 2024
07b1791
Save changes
jaredfholgate Feb 22, 2024
d38859f
Save changes
jaredfholgate Feb 23, 2024
11106e7
Save fixes
jaredfholgate Feb 23, 2024
78c3bf3
Fixes and refactors
jaredfholgate Feb 24, 2024
344fd2b
Delete files
jaredfholgate Feb 24, 2024
bc35156
Enable offline mode
jaredfholgate Feb 24, 2024
8f1a7b2
display filters
jaredfholgate Feb 24, 2024
4f04b75
More refectoring
jaredfholgate Feb 24, 2024
dc7c725
Add alias
jaredfholgate Feb 24, 2024
6da9964
Fix bugs
jaredfholgate Feb 24, 2024
64bbd59
Add input usage for static inputs
jaredfholgate Feb 29, 2024
0856e3b
Add retires and comment code
jaredfholgate Mar 2, 2024
70c2a45
Fix upgrade code
jaredfholgate Mar 5, 2024
6f69067
Tidy outputs and fix cache
jaredfholgate Mar 5, 2024
1af699d
Tidy standard output
jaredfholgate Mar 5, 2024
25a0cc5
Make bicep legacy work with alz_
jaredfholgate Mar 12, 2024
c39cae3
Update read me
jaredfholgate Mar 12, 2024
eaac955
Fix read me
jaredfholgate Mar 12, 2024
d8cc75f
Improve docs
jaredfholgate Mar 12, 2024
2d82717
Update logs for Bicep
jaredfholgate Mar 12, 2024
7201d7e
Improve docs and logging
jaredfholgate Mar 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading