-
Notifications
You must be signed in to change notification settings - Fork 53
feat: improvements to inputs and region validation #182
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 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9808260
Automate regions and sort validation
jaredfholgate fe9bf11
Allow tfvars override
jaredfholgate 799bb1d
Remove test file
jaredfholgate 870dbeb
Fix contributing guid paths
jaredfholgate 81cc269
Add hidden variable functionality to input config
jaredfholgate 038dfd6
Fix array issue
jaredfholgate efa3a8a
Don't set wrong vars
jaredfholgate a29b6d5
Filter out built in variables
jaredfholgate 1286fb6
Tidy old HCL serialiser
jaredfholgate 95f655a
Update to ensure input config always uses native types
jaredfholgate 030402e
Fix linting
jaredfholgate 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,72 @@ | ||
| function Get-AzureRegionData { | ||
| param( | ||
| [Parameter(Mandatory = $false)] | ||
| [string]$toolsPath = ".\region" | ||
| ) | ||
|
|
||
| $terraformCode = @' | ||
| terraform { | ||
| required_providers { | ||
| azapi = { | ||
| source = "azure/azapi" | ||
| version = "~> 1.14" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| data "azapi_client_config" "current" {} | ||
|
|
||
| data "azapi_resource_action" "locations" { | ||
| type = "Microsoft.Resources/subscriptions@2022-12-01" | ||
| action = "locations" | ||
| method = "GET" | ||
| resource_id = "/subscriptions/${data.azapi_client_config.current.subscription_id}" | ||
| response_export_values = ["value"] | ||
| } | ||
|
|
||
| locals { | ||
| regions = { for region in jsondecode(data.azapi_resource_action.locations.output).value : region.name => { | ||
| display_name = region.displayName | ||
| zones = try([ for zone in region.availabilityZoneMappings : zone.logicalZone ], []) | ||
| } if region.metadata.regionType == "Physical" | ||
| } | ||
| } | ||
|
|
||
| output "regions_and_zones" { | ||
| value = local.regions | ||
| } | ||
| '@ | ||
|
|
||
| $regionFolder = Join-Path $toolsPath "azure-regions" | ||
| if(Test-Path $regionFolder) { | ||
| Remove-Item $regionFolder -Recurse -Force | ||
| } | ||
|
|
||
| New-Item $regionFolder -ItemType "Directory" | ||
|
|
||
| $regionCodeFileName = Join-Path $regionFolder "main.tf" | ||
| $terraformCode | Out-File $regionCodeFileName -Force | ||
|
|
||
| $outputFilePath = Join-Path $regionFolder "output.json" | ||
|
|
||
| Invoke-Terraform -moduleFolderPath $regionFolder -autoApprove -output "regions_and_zones" -outputFilePath $outputFilePath -silent | ||
|
|
||
| $json = Get-Content $outputFilePath | ||
| $regionsAndZones = ConvertFrom-Json $json | ||
|
|
||
| $zonesSupport = @() | ||
| $supportedRegions = @() | ||
|
|
||
| foreach($region in $regionsAndZones.PSObject.Properties) { | ||
| $supportedRegions += $region.Name | ||
| $zonesSupport += @{ | ||
| region = $region.Name | ||
| zones = $region.Value.zones | ||
| } | ||
| } | ||
|
|
||
| return @{ | ||
| zonesSupport = $zonesSupport | ||
| supportedRegions = $supportedRegions | ||
| } | ||
| } |
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,49 @@ | ||
| function Write-TfvarsJsonFile { | ||
| [CmdletBinding(SupportsShouldProcess = $true)] | ||
| param ( | ||
| [Parameter(Mandatory = $false)] | ||
| [string] $tfvarsFilePath, | ||
|
|
||
| [Parameter(Mandatory = $false)] | ||
| [PSObject] $configuration | ||
| ) | ||
|
|
||
| if ($PSCmdlet.ShouldProcess("Download Terraform Tools", "modify")) { | ||
|
|
||
| if(Test-Path $tfvarsFilePath) { | ||
| Remove-Item -Path $tfvarsFilePath | ||
| } | ||
|
|
||
| $jsonObject = @{} | ||
|
|
||
| foreach($configurationProperty in $configuration.PSObject.Properties) { | ||
| $configurationValue = $configurationProperty.Value.Value | ||
|
|
||
| if($configurationProperty.Value.Validator -eq "configuration_file_path") { | ||
| $configurationValue = [System.IO.Path]::GetFileName($configurationValue) | ||
| } | ||
|
|
||
| if($configurationProperty.Value.DataType -eq "list(string)" -and !($configurationValue -is [array])) { | ||
| if($configurationValue -eq "") { | ||
| $configurationValue = @() | ||
| } else { | ||
| $configurationValue = @($configurationValue -split ",") | ||
| } | ||
| } | ||
|
|
||
| if($configurationProperty.Value.DataType -eq "number") { | ||
| $configurationValue = [int]($configurationValue) | ||
| } | ||
|
|
||
| if($configurationProperty.Value.DataType -eq "bool") { | ||
| $configurationValue = [bool]($configurationValue) | ||
| } | ||
|
|
||
| $jsonObject["$($configurationProperty.Name)"] = $configurationValue | ||
| } | ||
|
|
||
| $jsonString = ConvertTo-Json $jsonObject | ||
|
|
||
| $jsonString | Out-File $tfvarsFilePath | ||
| } | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.