-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathUpdateSamples.ps1
More file actions
executable file
·118 lines (94 loc) · 3.87 KB
/
UpdateSamples.ps1
File metadata and controls
executable file
·118 lines (94 loc) · 3.87 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env pwsh
Param (
[parameter(Mandatory=$true)][string] $QuickStartsRepoPath
)
$ErrorActionPreference = "Stop"
$QuickStartsRepoPath = Resolve-Path $QuickStartsRepoPath
$OutputPath = Join-Path $PSScriptRoot "../settings/samples/samples.json"
function GetQuickstartLinks {
function GetResourceTypes {
param([PSCustomObject] $template)
$resourceTypes = @()
foreach ($resource in $template.resources) {
if ($resource.type -ieq "Microsoft.Resources/deployments") {
foreach ($resourceType in GetResourceTypes($resource.properties.template)) {
$resourceTypes += $resourceType
}
} else {
$resourceTypes += $resource.type
}
}
return $resourceTypes | Sort-Object -Unique
}
$links = @()
$metadataPaths = Get-ChildItem $QuickStartsRepoPath -File -Recurse -Include "metadata.json" | Sort-Object FullName
foreach ($metadataPath in $metadataPaths) {
Write-Host "Processing $metadataPath"
$templatePath = Join-Path $metadataPath.DirectoryName "azuredeploy.json"
if (-not (Test-Path $templatePath -PathType Leaf)) {
Write-Host "No template found for $metadataPath"
continue
}
$bicepPath = Join-Path $metadataPath.DirectoryName "main.bicep"
$hasBicep = (Test-Path $bicepPath -PathType Leaf)
$metadataContent = Get-Content $metadataPath.FullName | ConvertFrom-Json
$description = $metadataContent.description
$displayName = $metadataContent.itemDisplayName
$templateContent = Get-Content $templatePath | ConvertFrom-Json
$resourceTypes = GetResourceTypes($templateContent)
$links += [ordered]@{
Title = $displayName;
Description = $description;
Path = [System.IO.Path]::GetRelativePath($QuickStartsRepoPath, "$templatePath/..").Replace("\", "/")
ResourceTypes = @($resourceTypes);
HasBicep = $hasBicep;
}
}
return $links
}
function GetAvmLinks {
$bicepLinks = "https://raw.githubusercontent.com/Azure/Azure-Verified-Modules/refs/heads/main/docs/static/module-indexes/BicepResourceModules.csv"
$tfLinks = "https://raw.githubusercontent.com/Azure/Azure-Verified-Modules/refs/heads/main/docs/static/module-indexes/TerraformResourceModules.csv"
$bicepModules = ConvertFrom-Csv (Invoke-WebRequest -Uri $bicepLinks).Content
$tfModules = ConvertFrom-Csv (Invoke-WebRequest -Uri $tfLinks).Content
$availableStatuses = @(
"Available",
"Orphaned"
)
$links = @()
foreach ($bicepModule in $bicepModules) {
Write-Host "Processing $($bicepModule.RepoURL)"
if ($bicepModule.ModuleStatus -notin $availableStatuses) {
continue
}
$links += [ordered]@{
Type = "Bicep";
Title = $bicepModule.ModuleDisplayName;
Description = $bicepModule.Description;
ResourceType = "$($bicepModule.ProviderNamespace)/$($bicepModule.ResourceType)";
RepoUrl = $bicepModule.RepoURL;
}
}
foreach ($tfModule in $tfModules) {
Write-Host "Processing $($tfModule.RepoURL)"
if ($tfModule.ModuleStatus -notin $availableStatuses) {
continue
}
$links += [ordered]@{
Type = "Terraform";
Title = $tfModule.ModuleDisplayName;
Description = $tfModule.Description;
ResourceType = "$($tfModule.ProviderNamespace)/$($tfModule.ResourceType)";
RepoUrl = $tfModule.RepoURL;
}
}
return $links
}
$quickstartLinks = GetQuickstartLinks
$avmLinks = GetAvmLinks
$samples = [ordered]@{
"`$schema" = "../schemas/samples.schema.json";
QuickstartLinks = $quickstartLinks;
AvmLinks = $avmLinks;
}
$samples | ConvertTo-Json -depth 100 | Out-File $OutputPath