forked from microsoft/PSDocs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharm-template.Doc.ps1
64 lines (53 loc) · 1.77 KB
/
arm-template.Doc.ps1
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
#
# Azure Resource Manager documentation definitions
#
# A function to break out parameters from an ARM template
function GetTemplateParameter {
param (
[Parameter(Mandatory = $True)]
[String]$Path
)
process {
$template = Get-Content $Path | ConvertFrom-Json;
foreach ($property in $template.parameters.PSObject.Properties) {
[PSCustomObject]@{
Name = $property.Name
Description = $property.Value.metadata.description
}
}
}
}
# A function to import metadata
function GetTemplateMetadata {
param (
[Parameter(Mandatory = $True)]
[String]$Path
)
process {
$metadata = Get-Content $Path | ConvertFrom-Json;
return $metadata;
}
}
# Synopsis: A definition to generate markdown for an ARM template
document 'arm-template' {
# Read JSON files
$metadata = GetTemplateMetadata -Path $PSScriptRoot/metadata.json;
$parameters = GetTemplateParameter -Path $PSScriptRoot/template.json;
# Set document title
Title $metadata.itemDisplayName
# Write opening line
$metadata.Description
# Add each parameter to a table
Section 'Parameters' {
$parameters | Table -Property @{ Name = 'Parameter name'; Expression = { $_.Name }},Description
}
# Generate example command line
Section 'Use the template' {
Section 'PowerShell' {
'New-AzResourceGroupDeployment -Name <deployment-name> -ResourceGroupName <resource-group-name> -TemplateFile <path-to-template>' | Code powershell
}
Section 'Azure CLI' {
'az group deployment create --name <deployment-name> --resource-group <resource-group-name> --template-file <path-to-template>' | Code text
}
}
}