-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathGet-AzureRegionData.ps1
More file actions
70 lines (57 loc) · 1.74 KB
/
Get-AzureRegionData.ps1
File metadata and controls
70 lines (57 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function Get-AzureRegionData {
param(
[Parameter(Mandatory = $false)]
[string]$toolsPath = ".\region"
)
$terraformCode = @'
terraform {
required_providers {
azapi = {
source = "azure/azapi"
version = "~> 2.0"
}
}
}
module "regions" {
source = "Azure/avm-utl-regions/azurerm"
version = "0.3.0"
use_cached_data = false
availability_zones_filter = false
recommended_filter = false
}
locals {
regions = { for region in module.regions.regions_by_name : region.name => {
display_name = region.display_name
zones = region.zones == null ? [] : [for zone in region.zones : tostring(zone)]
}
}
}
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
}
}