Last active
March 23, 2021 13:01
-
-
Save MarkWarneke/03e1ad7c6d70d1c26d09758c48f0dc47 to your computer and use it in GitHub Desktop.
As Markdown is very light weight we can leverage simple strings to create our documentation. To better visualize the parameters, resource and outputs of an ARM template a table might be a feasible option for display. https://markwarneke.me/2019-08-26-Gererate-Infrastructure-As-Code-Documentation/
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
| # New-Readme.ps1 | |
| param ( | |
| $Path = (Join-Path $PSScriptRoot "azuredeploy.json") | |
| ) | |
| # Test for template presence | |
| $null = Test-Path $Path -ErrorAction Stop | |
| # Test if arm template content is readable | |
| $text = Get-Content $Path -Raw -ErrorAction Stop | |
| # Convert the ARM template to an Object | |
| $json = ConvertFrom-Json $text -ErrorAction Stop | |
| # Create a Parameter List Table | |
| $parameterHeader = "| Parameter Name | Parameter Type |Parameter Description | Parameter DefaultValue |" | |
| $parameterHeaderDivider = "| --- | --- | --- | --- | " | |
| $parameterRow = " | {0}| {1} | {2} | {3} |" | |
| $StringBuilderParameter = @() | |
| $StringBuilderParameter += $parameterHeader | |
| $StringBuilderParameter += $parameterHeaderDivider | |
| $StringBuilderParameter += $json.parameters | get-member -MemberType NoteProperty | % { $parameterRow -f $_.Name , $json.parameters.($_.Name).type , $json.parameters.($_.Name).metadata.description, $json.parameters.($_.Name).defaultValue } | |
| # Create a Resource List Table | |
| $resourceHeader = "| Resource Name | Resource Type | Resource Comment |" | |
| $resourceHeaderDivider = "| --- | --- | --- | " | |
| $resourceRow = " | {0}| {1} | {2} | " | |
| $StringBuilderResource = @() | |
| $StringBuilderResource += $resourceHeader | |
| $StringBuilderResource += $resourceHeaderDivider | |
| $StringBuilderResource += $json.resources | % { $resourceRow -f $_.Name, $_.Type, $_.Comments } | |
| # Create an Output List Table | |
| $outputHeader = "| Output Name | Output Value | Output Type |" | |
| $outputHeaderDivider = "| --- | --- | --- | " | |
| $outputRow = " | {0}| {1} | {2} | " | |
| $StringBuilderOutput = @() | |
| $StringBuilderOutput += $outputHeader | |
| $StringBuilderOutput += $outputHeaderDivider | |
| $StringBuilderOutput += $json.outputs | get-member -MemberType NoteProperty | % { $outputRow -f $_.Name , $json.parameters.($_.Name).type , $json.parameters.($_.Name).metadata.description, $json.parameters.($_.Name).defaultValue } | |
| # output | |
| $StringBuilderResource | |
| <# | |
| | Resource Type | Resource Name | Resource Comment | | |
| | --- | --- | --- | | |
| | Microsoft.Storage/storageAccounts| [parameters('resourceName')] | Azure Data Lake Gen 2 Storage Account | | |
| #> | |
| $StringBuilderParameter | |
| <# | |
| | Parameter Name | Parameter Type |Parameter Description | Parameter DefaultValue | | |
| | --- | --- | --- | --- | | |
| | location| string | Azure location for deployment | [resourceGroup().location] | | |
| | networkAcls| string | Optional. Networks ACLs Object, this value contains IPs to whitelist and/or Subnet information. | | | |
| | resourceName| string | Name of the Data Lake Storage Account | | | |
| | storageAccountAccessTier| string | Optional. Storage Account Access Tier. | Hot | | |
| | storageAccountSku| string | Optional. Storage Account Sku Name. | Standard_ZRS | | |
| #> | |
| $StringBuilderOutput | |
| <# | |
| | Output Name | Output Value | Output Type | | |
| | ------------- | ------------ | ----------- | | |
| | componentName | string | | | |
| | resourceID | string | | | |
| #> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment