-
Notifications
You must be signed in to change notification settings - Fork 43
Improve ALZ Module CLI #2
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ee571c1
Stowing this to test something else
f2bbe2e
Now with working
0dbc375
String replacement done
7d7d640
Adding tests
1a0952f
Adding more tests
c430582
Something is breaking trying this to see if something gives me an err…
132854e
Fix the import
4f4bbee
Tidy ups
7de8a03
Adding in tokenised strings as per discussion with Gabe
8b4781b
Unwinding a partial change to validation
075b2fe
Committing this with improved CLI and token replacement
ac288ab
Committing this with a json based configuration object
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
{ | ||
"Prefix": { | ||
"Type": "UserInput", | ||
"Description": "The prefix that will be added to all resources created by this deployment. (e.g. 'alz')", | ||
"Targets": [ | ||
{ | ||
"Name": "parTopLevelManagementGroupPrefix", | ||
"Destination": "Parameters" | ||
}, | ||
{ | ||
"Name": "parCompanyPrefix", | ||
"Destination": "Parameters" | ||
}, | ||
{ | ||
"Name": "parTargetManagementGroupId", | ||
"Destination": "Parameters" | ||
}, | ||
{ | ||
"Name": "parAssignableScopeManagementGroupId", | ||
"Destination": "Parameters" | ||
} | ||
], | ||
"Value": "", | ||
"DefaultValue": "alz", | ||
"Valid": "^[a-zA-Z]{3,5}$" | ||
}, | ||
"Suffix": { | ||
"Type": "UserInput", | ||
"Description": "The suffix that will be added to all resources created by this deployment. (e.g. 'test')", | ||
"Targets": [ | ||
{ | ||
"Name": "parTopLevelManagementGroupSuffix", | ||
"Destination": "Parameters" | ||
} | ||
], | ||
"Value": "", | ||
"DefaultValue": "", | ||
"Valid": "^[a-zA-Z]{0,5}$" | ||
}, | ||
"Location": { | ||
"Type": "UserInput", | ||
"Description": "Deployment location.", | ||
"Value": "", | ||
"Targets": [ | ||
{ | ||
"Name": "parLocation", | ||
"Destination": "Parameters" | ||
}, | ||
{ | ||
"Name": "parAutomationAccountLocation", | ||
"Destination": "Parameters" | ||
}, | ||
{ | ||
"Name": "parLogAnalyticsWorkspaceLocation", | ||
"Destination": "Parameters" | ||
} | ||
], | ||
"AllowedValues": [ | ||
"asia", | ||
"asiapacific", | ||
"australia", | ||
"australiacentral", | ||
"australiacentral2", | ||
"australiaeast", | ||
"australiasoutheast", | ||
"brazil", | ||
"brazilsouth", | ||
"brazilsoutheast", | ||
"canada", | ||
"canadacentral", | ||
"canadaeast", | ||
"centralindia", | ||
"centralus", | ||
"centraluseuap", | ||
"centralusstage", | ||
"eastasia", | ||
"eastasiastage", | ||
"eastus", | ||
"eastus2", | ||
"eastus2euap", | ||
"eastus2stage", | ||
"eastusstg", | ||
"europe", | ||
"france", | ||
"francecentral", | ||
"francesouth", | ||
"germany", | ||
"germanynorth", | ||
"germanywestcentral", | ||
"global", | ||
"india", | ||
"japan", | ||
"japaneast", | ||
"japanwest", | ||
"jioindiacentral", | ||
"jioindiawest", | ||
"korea", | ||
"koreacentral", | ||
"koreasouth", | ||
"northcentralus", | ||
"northcentralusstage", | ||
"northeurope", | ||
"norway", | ||
"norwayeast", | ||
"norwaywest", | ||
"qatarcentral", | ||
"singapore", | ||
"southafrica", | ||
"southafricanorth", | ||
"southafricawest", | ||
"southcentralus", | ||
"southcentralusstage", | ||
"southeastasia", | ||
"southindia", | ||
"swedencentral", | ||
"switzerland", | ||
"switzerlandnorth", | ||
"switzerlandwest", | ||
"uaecentral", | ||
"uaenorth", | ||
"uksouth", | ||
"ukwest", | ||
"unitedstates", | ||
"westcentralus", | ||
"westeurope", | ||
"westindia", | ||
"westus", | ||
"westus2", | ||
"westus2stage", | ||
"westus3", | ||
"westusstage" | ||
] | ||
}, | ||
"Environment": { | ||
"Type": "UserInput", | ||
"Description": "The Type of environment that will be created. (e.g. 'dev', 'test', 'qa', 'staging', 'prod')", | ||
"Targets": [ | ||
{ | ||
"Name": "parEnvironment", | ||
"Destination": "Parameters" | ||
} | ||
], | ||
"Value": "", | ||
"DefaultValue": "prod", | ||
"Valid": "^[a-zA-Z0-9]{2,10}$" | ||
}, | ||
"IdentitySubscriptionId": { | ||
"Type": "UserInput", | ||
"Description": "The identifier of the Identity Subscription. (e.g '00000000-0000-0000-0000-000000000000')", | ||
"Valid": "^( {){0,1}[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}(}){0,1}$", | ||
"Targets": [ | ||
{ | ||
"Name": "IdentitySubscriptionId", | ||
"Destination": "Environment" | ||
} | ||
], | ||
"Value": "" | ||
}, | ||
"ConnectivitySubscriptionId": { | ||
"Type": "UserInput", | ||
"Description": "The identifier of the Connectivity Subscription. (e.g '00000000-0000-0000-0000-000000000000')", | ||
"Valid": "^( {){0,1}[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}(}){0,1}$", | ||
"Targets": [ | ||
{ | ||
"Name": "ConnectivitySubscriptionId", | ||
"Destination": "Environment" | ||
} | ||
], | ||
"Value": "" | ||
}, | ||
"ManagementSubscriptionId": { | ||
"Type": "UserInput", | ||
"Description": "The identifier of the Management Subscription. (e.g 00000000-0000-0000-0000-000000000000)", | ||
"Valid": "^( {){0,1}[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}(}){0,1}$", | ||
"Targets": [ | ||
{ | ||
"Name": "ManagementSubscriptionId", | ||
"Destination": "Environment" | ||
} | ||
], | ||
"Value": "" | ||
}, | ||
"BillingAccountId": { | ||
"Type": "UserInput", | ||
"Description": "The identifier of the Billing Account. (e.g 00000000-0000-0000-0000-000000000000)", | ||
"Valid": "^( {){0,1}[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}(}){0,1}$", | ||
"Value": "" | ||
}, | ||
"EnrollmentAccountId": { | ||
"Type": "UserInput", | ||
"Description": "The identifier of the Enrollment Account. (e.g 00000000-0000-0000-0000-000000000000)", | ||
"Valid": "^( {){0,1}[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}(}){0,1}$", | ||
"Value": "" | ||
}, | ||
"LogAnalyticsResourceId": { | ||
"Type": "Computed", | ||
"Value": "/subscriptions/{%ManagementSubscriptionId%}/resourcegroups/alz-logging/providers/microsoft.operationalinsights/workspaces/alz-log-analytics", | ||
"Targets": [ | ||
{ | ||
"Name": "parLogAnalyticsWorkspaceResourceId", | ||
"Destination": "Parameters" | ||
} | ||
] | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
function Build-ALZDeploymentEnvFile { | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[PSCustomObject] $configuration, | ||
|
||
[Parameter(Mandatory = $false)] | ||
[string] $destination = "." | ||
) | ||
<# | ||
.SYNOPSIS | ||
This function uses configuration to build a .env file for use in the deployment pipeline. | ||
.EXAMPLE | ||
Build-ALZDeploymentEnvFile -configuration configuration | ||
.EXAMPLE | ||
Build-ALZDeploymentEnvFile -configuration configuration -destination "." | ||
.OUTPUTS | ||
N/A | ||
#> | ||
|
||
$envFile = Join-Path $destination ".env" | ||
|
||
New-Item -Path $envFile -ItemType file -Force | Out-Null | ||
|
||
foreach ($configurationValue in $configuration.PsObject.Properties) { | ||
foreach ($target in $configurationValue.Value.Targets) { | ||
if ($target.Destination -eq "Environment") { | ||
Add-Content -Path $envFile -Value "$($($target.Name))=`"$($configurationValue.Value.Value)`"" | Out-Null | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
function Format-TokenizedConfigurationString { | ||
param( | ||
[Parameter(Mandatory = $true)] | ||
[string] $tokenizedString, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[object] $configuration | ||
) | ||
$values = $tokenizedString -split "\{\%|\%\}" | ||
|
||
$returnValue = "" | ||
foreach ($value in $values) { | ||
$isToken = $tokenizedString -contains "{%$value%}" | ||
if ($null -ne $configuration.$value) { | ||
$returnValue += $configuration.$value.Value | ||
} elseif (($null -eq $configuration.$value) -and $isToken) { | ||
Write-InformationColored "Specified replacement token '${value}' not found in configuration." -ForegroundColor Yellow -InformationAction Continue | ||
$returnValue += "{%$value%}" | ||
} else { | ||
$returnValue += $value | ||
} | ||
} | ||
|
||
return $returnValue | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
function Get-Configuration { | ||
param( | ||
[Parameter(Mandatory = $false)] | ||
[ValidateSet("bicep", "terraform")] | ||
[string] $alzIacProvider = "bicep", | ||
|
||
[Parameter(Mandatory = $false)] | ||
[string] $alzEnvironmentDestination = ".", | ||
|
||
[Parameter(Mandatory = $false)] | ||
[string] $alzBicepVersion = "v0.13.0" | ||
) | ||
<# | ||
.SYNOPSIS | ||
This function uses a template configuration to prompt for and return a user specified/modified configuration object. | ||
.EXAMPLE | ||
Get-Configuration | ||
.EXAMPLE | ||
Get-Configuration -alzIacProvider "bicep" | ||
.OUTPUTS | ||
System.Object. The resultant configuration values. | ||
#> | ||
|
||
if ($alzIacProvider -eq "terraform") { | ||
throw "Terraform is not yet supported." | ||
} | ||
|
||
$uxConfigurationFile = Join-Path $alzEnvironmentDestination "alz-bicep-config" "$alzBicepVersion.ux.config.json" | ||
return Get-Content -Path $uxConfigurationFile -Raw | ConvertFrom-Json | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to find a nice way to do this dynamically - I could embed PS script in here I suppose...