GithubHelp home page GithubHelp logo

azure / psdocs.azure Goto Github PK

View Code? Open in Web Editor NEW
56.0 6.0 20.0 4.22 MB

Generate documentation from Azure infrastructure as code (IaC) artifacts.

Home Page: https://azure.github.io/PSDocs.Azure/

License: MIT License

PowerShell 55.42% C# 34.42% HTML 9.88% Dockerfile 0.29%
azure powershell infrastructure-as-code devops devops-tools documentation-generator markdown psdocs

psdocs.azure's Introduction

PSDocs for Azure

Generate markdown from Azure infrastructure as code (IaC) artifacts.

ci-badge

Features of PSDocs for Azure include:

  • Ready to go - Use pre-built templates.
  • DevOps - Generate within a continuous integration (CI) pipeline.
  • Cross-platform - Run on MacOS, Linux, and Windows.

Support

This project uses GitHub Issues to track bugs and feature requests. Please search the existing issues before filing new issues to avoid duplicates.

  • For new issues, file your bug or feature request as a new issue.
  • For help, discussion, and support questions about using this project, join or start a discussion.

If you have any problems with the PSDocs engine, please check the project GitHub issues page instead.

Support for this project/ product is limited to the resources listed above.

Getting the modules

This project requires the PSDocs PowerShell module. For details on each see install.

You can download and install these modules from the PowerShell Gallery.

Module Description Downloads / instructions
PSDocs.Azure Generate documentation from Azure infrastructure as code (IaC) artifacts. latest / instructions

Getting started

The follow example uses PSDocs for Azure to generate markdown from an Azure template. The source template and generated output are provided below.

For frequently asked questions, see the FAQ.

Annotate templates files

In its simplest structure, an Azure template has the following elements:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {  },
  "variables": {  },
  "functions": [  ],
  "resources": [  ],
  "outputs": {  }
}

Additionally a metadata property can be added in most places throughout the template. For example:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "metadata": {
        "name": "Storage Account",
        "description": "Create or update a Storage Account."
    },
    "parameters": {
        "storageAccountName": {
            "type": "string",
            "metadata": {
                "description": "The name of the Storage Account."
            }
        },
        "tags": {
            "type": "object",
            "metadata": {
                "description": "Tags to apply to the resource.",
                "example": {
                    "service": "<service_name>",
                    "env": "prod"
                }
            }
        }
    },
    "resources": [
    ],
    "outputs": {
        "resourceId": {
            "type": "string",
            "value": "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]",
            "metadata": {
                "description": "A unique resource identifier for the storage account."
            }
        }
    }
}

This metadata and the template structure itself can be used to dynamically generate documentation. Documenting templates in this way allows you to:

  • Include meaningful information with minimal effort.
  • Use DevOps culture to author infrastructure code and documentation side-by-side.
    • Review pull requests (PR) with changes and documentation together.
    • Use continuous integration and deployment to release changes.
  • Keep documentation up-to-date. No separate wiki or document to keep in sync.

PSDocs interprets the template structure and metadata to generate documentation as markdown. Generating documentation as markdown allows you to publish web-based content on a variety of platforms.

PSDocs supports the following metadata:

Field Scope Type Description
name Template string Used for markdown page title.
summary Template string Used as a short description for the markdown page.
description Template string Used as a detailed description for the markdown page.
description Parameter string Used as the description for the parameter.
example Parameter string, boolean, object, or array An example use of the parameter. The example is included in the JSON snippet. If an example is not included the default value is used instead.
ignore Parameter boolean When true the parameter is not included in the JSON snippet.
description Output string Used as the description for the output.

An example of an Azure Storage Account template with metadata included is available here.

Running locally

To run PSDocs for Azure locally use the Invoke-PSDocument cmdlet.

# Import module
Import-Module PSDocs.Azure;

# Generate markdown
Invoke-PSDocument -Module PSDocs.Azure -InputObject '<template_file_path>' -OutputPath out/docs/;

This will generate a README.md in out/docs directory with the generated markdown (also creates out/docs/ directory if it does not exist).

Scanning for templates

To scan for templates in a directory the Get-AzDocTemplateFile cmdlet can be used.

# Import module
Import-Module PSDocs.Azure;

# Scan for Azure template file recursively in the templates/ directory
Get-AzDocTemplateFile -Path templates/ | ForEach-Object {
    # Generate a standard name of the markdown file. i.e. <name>_<version>.md
    $template = Get-Item -Path $_.TemplateFile;
    $templateName = $template.Directory.Parent.Name;
    $version = $template.Directory.Name;
    $docName = "$($templateName)_$version";

    # Generate markdown
    Invoke-PSDocument -Module PSDocs.Azure -OutputPath out/docs/ -InputObject $template.FullName -InstanceName $docName;
}

In this example template files are stored in a directory structure such as templates/<name>/<version>/template.json. i.e. templates/storage/v1/template.json.

The example finds all the Azure template files and outputs a markdown file for each in out/docs/. An example of the generated markdown is available here

Using with Azure Pipelines

The following example shows how to setup Azure Pipelines to generate ARM template documentation in the markdown format. This example copies the generated markdown files to a designated blob storage.

  • Create a new YAML pipeline with the Starter pipeline template.
  • Add a PowerShell task to:
    • Install PSDocs.Azure module.
    • Scan for Azure template file recursively in the templates/ directory.
    • Generate a standard name of the markdown file. i.e. <name>_<version>.md
    • Generate the markdown to a specific directory.
  • Add an AzureFileCopy task to copy the generated markdown to an Azure Storage Blob container.

For example:

# Example: .azure-pipelines/psdocs-blobstorage.yaml

jobs:
- job: 'generate_arm_template_documentation'
  displayName: 'Generate ARM template docs'
  pool:
    vmImage: 'windows-2019'
  steps:
  # STEP 1: Generate Markdowns using PSDocs
  - powershell: | 
      Install-Module -Name 'PSDocs.Azure' -Repository PSGallery -force;
        # Scan for Azure template file recursively in the templates/ directory
        Get-AzDocTemplateFile -Path templates/ | ForEach-Object {
        # Generate a standard name of the markdown file. i.e. <name>_<version>.md
        $template = Get-Item -Path $_.TemplateFile;
        $templateName = $template.Directory.Parent.Name;
        $version = $template.Directory.Name;
        $docName = "$($templateName)_$version";
        # Generate markdown
        Invoke-PSDocument -Module PSDocs.Azure -OutputPath out/docs/ -InputObject $template.FullName -InstanceName $docName;
      }
    displayName: 'Export template data'
    
  # STEP 2: Copy files to a storage account
  - task: AzureFileCopy@4
    displayName: 'Copy files to a storage account blob container'
    inputs:
      SourcePath: 'out/docs/*'
      azureSubscription: 'psdocstest'
      Destination: 'AzureBlob'
      storage: '<storageaccountname>' 
      ContainerName: 'ps-docs'

Using with GitHub Actions

The following example shows how to setup GitHub Actions to copy generated markdown files to an Azure blob storage account.

  • See Creating a workflow file to create an empty workflow file.
  • Add a PowerShell step to:
    • Install PSDocs.Azure module.
    • Scan for Azure template file recursively in the templates/ directory.
    • Generate a standard name of the markdown file. i.e. <name>_<version>.md
    • Generate the markdown to a specific directory.
  • Set the STORAGEACCOUNTSECRET action secret.
  • Use an Azure Blob Storage Upload action to copy the generated markdown to an Azure Storage Blob container.

For example:

# Example: .github/workflows/arm-docs.yaml

name: Generate ARM templates docs
on:
  push:
    branches: [ main ]
jobs:
  arm_docs:
    name: Generate ARM template docs
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    # STEP 1: Generate Markdowns using PSDocs
    - name: Generate ARM markdowns
      run: | 
        Install-Module -Name 'PSDocs.Azure' -Repository PSGallery -force;
        # Scan for Azure template file recursively in the templates/ directory
        Get-AzDocTemplateFile -Path templates/ | ForEach-Object {
          # Generate a standard name of the markdown file. i.e. <name>_<version>.md
          $template = Get-Item -Path $_.TemplateFile;
          $templateName = $template.Directory.Parent.Name;
          $version = $template.Directory.Name;
          $docName = "$($templateName)_$version";
          # Generate markdown
          Invoke-PSDocument -Module PSDocs.Azure -OutputPath out/docs/ -InputObject $template.FullName -InstanceName $docName;
        }
      shell: pwsh

    # STEP 2: Copy files to a storage account
    - name: Copy files to a storage account
      uses: bacongobbler/[email protected]
      with:
        connection_string: ${{ secrets.STORAGEACCOUNTSECRET }}
        container_name: ps-docs
        source_dir: 'out/docs/*'

Language reference

PSDocs for Azure extends PowerShell with the following cmdlets and concepts.

Commands

The following commands exist in the PSDocs.Azure module:

Concepts

The following conceptual topics exist in the PSDocs.Azure module:

Changes and versioning

Modules in this repository will use the semantic versioning model to declare breaking changes from v1.0.0. Prior to v1.0.0, breaking changes may be introduced in minor (0.x.0) version increments. For a list of module changes please see the change log.

Pre-release module versions are created on major commits and can be installed from the PowerShell Gallery. Pre-release versions should be considered experimental. Modules and change log details for pre-releases will be removed as standard releases are made available.

Contributing

This project welcomes contributions and suggestions. If you are ready to contribute, please visit the contribution guide.

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Maintainers

License

This project is licensed under the MIT License.

psdocs.azure's People

Contributors

berniewhite avatar dependabot[bot] avatar gabriel123n avatar jtracey93 avatar vicperdana avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

psdocs.azure's Issues

Running Invoke-PSDocument doesn't generate Readme.md

Description of the issue

Rather than generating the file Readme.md as stated in the doc. It outputs the markdown.

To reproduce

Steps to reproduce the issue:

Invoke-PSDocument -Module PSDocs.Azure -InputObject .\template.json 

Expected behaviour

Generated Readme.md in the local directory.

Error output

VERBOSE: [Invoke-PSDocument]::BEGIN
VERBOSE: [New-PSDocumentOption] BEGIN::
VERBOSE: Attempting to read: C:\CodeRepo\PSDocs.Azure\templates\storage\v1
VERBOSE: [New-PSDocumentOption] END::
VERBOSE: [PSDocs][D] -- Scanning for source files in module: PSDocs.Azure
# Storage Account

Create or update a Storage Account.

## Parameters

Parameter name | Description
-------------- | -----------
storageAccountName | Required. The name of the Storage Account.
location       | Optional. The Azure region to deploy to.
sku            | Optional. Create the Storage Account as LRS or GRS.
suffixLength   | Optional. Determine how many additional characters are added to the storage account name as a suffix.
containers     | Optional. An array of storage containers to create on the storage account.
lifecycleRules | Optional. An array of lifecycle management policies for the storage account.
blobSoftDeleteDays | Optional. The number of days to retain deleted blobs. When set to 0, soft delete is disabled.
containerSoftDeleteDays | Optional. The number of days to retain deleted containers. When set to 0, soft delete is disabled.
shares         | Optional. An array of file shares to create on the storage account.
useLargeFileShares | Optional. Determines if large file shares are enabled. This can not be disabled once enabled.
shareSoftDeleteDays | Optional. The number of days to retain deleted shares. When set to 0, soft delete is disabled.
allowBlobPublicAccess | Optional. Determines if any containers can be configured with the anonymous access types of blob or container.
keyVaultPrincipalId | Optional. Set to the objectId of Azure Key Vault to delegated permission for use with Key Managed Storage Accounts.
tags           | Optional. Tags to apply to the resource.

### storageAccountName

Required. The name of the Storage Account.

### location

Optional. The Azure region to deploy to.

- Default value: `[resourceGroup().location]`

### sku

Optional. Create the Storage Account as LRS or GRS.

- Default value: `Standard_LRS`

- Allowed values: `Standard_LRS`, `Standard_GRS`

### suffixLength

Optional. Determine how many additional characters are added to the storage account name as a suffix.

- Default value: `0`

### containers

Optional. An array of storage containers to create on the storage account.

### lifecycleRules

Optional. An array of lifecycle management policies for the storage account.

### blobSoftDeleteDays

Optional. The number of days to retain deleted blobs. When set to 0, soft delete is disabled.

- Default value: `0`

### containerSoftDeleteDays

Optional. The number of days to retain deleted containers. When set to 0, soft delete is disabled.

- Default value: `0`

### shares

Optional. An array of file shares to create on the storage account.

### useLargeFileShares

Optional. Determines if large file shares are enabled. This can not be disabled once enabled.

- Default value: `False`

### shareSoftDeleteDays

Optional. The number of days to retain deleted shares. When set to 0, soft delete is disabled.

- Default value: `0`

### allowBlobPublicAccess

Optional. Determines if any containers can be configured with the anonymous access types of blob or container.

- Default value: `False`

### keyVaultPrincipalId

Optional. Set to the objectId of Azure Key Vault to delegated permission for use with Key Managed Storage Accounts.

### tags

Optional. Tags to apply to the resource.

## Outputs

Name | Type | Description
---- | ---- | -----------
blobEndpoint | string | A URI to the blob storage endpoint.
resourceId | string | A unique resource identifier for the storage account.

## Snippets

### Parameter file

```json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "metadata": {
        "template": "template.json"
    },
    "parameters": {
        "storageAccountName": {
            "value": ""
        },
        "sku": {
            "value": "Standard_LRS"
        },
        "containers": {
            "value": [
                {
                    "name": "logs",
                    "publicAccess": "None",
                    "metadata": {}
                }
            ]
        },
        "lifecycleRules": {
            "value": {
                "enabled": true,
                "name": "<rule_name>",
                "type": "Lifecycle",
                "definition": {
                    "actions": {
                        "baseBlob": {
                            "delete": {
                                "daysAfterModificationGreaterThan": 7
                            }
                        }
                    },
                    "filters": {
                        "blobTypes": [
                            "blockBlob"
                        ],
                        "prefixMatch": [
                            "logs/"
                        ]
                    }
                }
            }
        },
        "blobSoftDeleteDays": {
            "value": 7
        },
        "containerSoftDeleteDays": {
            "value": 7
        },
        "shares": {
            "value": [
                {
                    "name": "<share_name>",
                    "shareQuota": 5,
                    "metadata": {}
                }
            ]
        },
        "shareSoftDeleteDays": {
            "value": 7
        },
        "allowBlobPublicAccess": {
            "value": false
        },
        "tags": {
            "value": {
                "service": "<service_name>",
                "env": "prod"
            }
        }
    }
}

**Module in use and version:**

- Module: PSDocs.Azure
- Version: **0.2.0-B2102012**

Captured output from `$PSVersionTable`:

```text
Name                           Value
----                           -----
PSVersion                      5.1.19041.610
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.610
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Additional context

This is a pre-release version.

Generate documentation for Azure Policy

Currently documentation is generated for Azure templates, but documentation for Azure Policy is equally applicable.

Implementing this might be clunky until type detection is added in BernieWhite/PSDocs#133.

Correct way to work with default values when using PSDocs and PSRule

Description of the issue

Not sure should this be an issue on PSRule or PSDocs side but I'm testing out both PSRule and PSDocs but have come to an issue how to deal with parameter default values. I'm using Bicep with PSRule and before used in PSDocs it's built to JSON. I have a separate parameters file.

For an example I have parameter adminUsername which is set in the Bicep file like this:

@description('Username for the Virtual Machine.')
param adminUsername string = 'placeholder'

And in the parameters file:

      "adminUsername": {
        "value": "adminUser"
      },

This way PSRule works ok but in the PSDocs stage this parameter is set as Optional

If I remove the default value from the Bicep and set it like this:

@description('Username for the Virtual Machine.')
param adminUsername string

The PSRule fails with error

##[error]Failed to expand bicep source '/home/vsts/work/1/s/main.bicep'. Exception calling "GetBicepResources" with "3" argument(s): "Unable to expand resources because the source file '/home/vsts/work/1/s/main.bicep' was not valid. An error occurred evaluating expression '[parameters('adminUsername')]' line 448. The parameter named 'adminUsername' was not set or a defaultValue was defined."

So what would be the correct way to set these values for both PSRule and PSDocs to work?
To reproduce

Steps to reproduce the issue:

  • Remove default value from the Bicep template

Expected behaviour

  • Value should be coming from the parameters file and set as required in the PSDocs.

Error output

##[error]Failed to expand bicep source '/home/vsts/work/1/s/main.bicep'. Exception calling "GetBicepResources" with "3" argument(s): "Unable to expand resources because the source file '/home/vsts/work/1/s/main.bicep' was not valid. An error occurred evaluating expression '[parameters('adminUsername')]' line 448. The parameter named 'adminUsername' was not set or a defaultValue was defined."

Module in use and version:

  • Module: PSDocs.Azure
  • Version: 0.3.0]

Captured output from $PSVersionTable:

Name                           Value
----                           -----
PSVersion                      7.2.7
PSEdition                      Core
GitCommitId                    7.2.7
OS                             Linux 5.15.0-1024-azure #30-Ubuntu SMP Wed Nov …
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Additional context

Creating convention for Azure templates based on directory structure

PSDocs conventions are a feature added to PSDocs v0.8.0.

Conventions allow automatic naming of output documents.

Currently we have a manual sample (below) to name documents based on their directory structure.

# Generate a standard name of the markdown file. i.e. <name>_<version>.md
$template = Get-Item -Path $_.TemplateFile;
$templateName = $template.Directory.Parent.Name;
$version = $template.Directory.Name;
$docName = "$($templateName)_$version";

This can now be converted to a convention to avoid using extra code for common scenarios.

When trying to create document for an ARM template with user defined typed outputs and resource deployed, error `Invoke-PSDocument: Object reference not set to an instance of an object.` is triggered

Description of the issue

We have some bicep/ARM templates that use outputs with a user defined type as the output type.

When trying to create documentation on the compiled ARM file using PSDocs, the command fails with the error Invoke-PSDocument: Object reference not set to an instance of an object..

This only happens if the template both:

  • Have an output with a user defined type as the type
  • A resource/module is also deployed in the same file

If I either replace the user defined type with object or remove all the resources/modules from the template, PSDocs successfully run

To reproduce

Have a bicep file with the following content:

type test = {
  str: string
}


param text test

resource res 'Microsoft.Compute/virtualMachines@2024-03-01'= {
  name: 'myVM'
  location: ''
}


// si custom type + resource => instance of object
output out test = {str: 'test'}

Compile that file with the bicep cli and run the following command

Invoke-PSDocument -Module PSDocs.Azure -InputObject .\main.json -OutputPath $pwd -InstanceName .\main.md -Culture en-GB

The command will fail.

If you either replace the output line with output out object = {str: 'test'} or command the res resource, no error is triggered

Expected behaviour

The command succeed in creating the documentation.

Error output


Module in use and version:

  • Module: PSDocs.Azure
  • Version: 0.3.0

Captured output from $PSVersionTable:

VERBOSE: [Invoke-PSDocument]::BEGIN
VERBOSE: [New-PSDocumentOption] BEGIN::
VERBOSE: Attempting to read: D:\Users\GNGANDUB\OneDrive - TUC RAIL\Documents\test\test-json\psdoc
VERBOSE: [New-PSDocumentOption] END::
VERBOSE: [PSDocs][D] -- Scanning for source files in module: PSDocs.Azure
Invoke-PSDocument: Object reference not set to an instance of an object.
VERBOSE: [Invoke-PSDocument]::END

Additional context

Provide a better key vault reference

Currently when templates use a secret string a key vault reference is added to the snippet for the parameter. An empty string is used for the key vault resource id.

"administratorLoginPassword": {
    "reference": {
        "keyVault": {
            "id": ""
        },
        "secretName": ""
    }
}

Key Vaults have a standard resource id that can be provided instead with placeholders that will make populating it eaiser.

"administratorLoginPassword": {
    "reference": {
        "keyVault": {
            "id": "/subscriptions/__SUBSCRIPTION_ID__/resourceGroups/__RESOURCE_GROUP__/providers/Microsoft.KeyVault/vaults/__VAULT__"
        },
        "secretName": "__SECRET_NAME__"
    }
}

Add support for parameter strongType

Azure Policy supports the concept of a parameter strong type, while this isn't directly applicable for ARM template the same uses of strongType in policy would help with document generation to provide more meaningful references.

Suggestion that strongType can be added to metadata.

location

When location is used, a reference link to Azure locations can be added to parameter details.

For example:

{
  "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
          "description": "The Azure region to deploy to.",
          "strongType": "location"
      }
  }
}

resource type

When a resource type is used for a strong type a resource Id for that resource can be used in parameter file snippet.

{
    "workspaceId": {
        "type": "string",
        "defaultValue": "",
        "metadata": {
            "description": "The workspace to store audit logs.",
            "strongType": "Microsoft.OperationalInsights/workspaces"
        }
    }
}
/subscriptions/<subscription_id>/resourcegroups/<resource_group_name>/providers/microsoft.operationalinsights/workspaces/<name>

Reference

Snippet with short relative template causes exception

Description of the issue

When generating a snippet the relative path to the template is used as metadata in the parameter file.

When calculating the relative path an exception can be caused the path to the template is already a relative file path. Even if there was no exception the resulting snippet would be incorrect.

To Reproduce

Steps to reproduce the issue:

Invoke-PSDocument  -Module 'PSDocs.Azure' -InputObject './template.json';

Expected behaviour

-InputPath should access either a relative path or full path to the template file.

Error output

Capture any error messages and or verbose messages with -Verbose.

Exception calling "Substring" with "1" argument(s): "startIndex cannot be larger than length of string. (Parameter 'startIndex')"

Module in use and version:

  • Module: PSDocs.Azure
  • Version: 0.1.0

Captured output from $PSVersionTable:

Name                           Value
----                           -----
PSVersion                      7.1.0
PSEdition                      Core
GitCommitId                    7.1.0
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Tests fail on WSL

Description of the issue

Tests fail in WSL because path references are windows based. No handling for WSL/Linux.

To reproduce

Steps to reproduce the issue:

Invoke pester tests in root

Invoke-Pester .

Expected behaviour

Tests passs

Error output

Import-Module: /home/sebwisz/ado/PSBicep/Tests/Clear-BicepModuleCache.Tests.ps1:3:1
Line |
3 | Import-Module $PSScriptRoot..\Source\Bicep
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| The specified module '/home/sebwisz/ado/PSBicep/Tests..\Source\Bicep' was not loaded because no valid module file was found in any module directory.
[-] Discovery in /home/sebwisz/ado/PSBicep/Tests/Clear-BicepModuleCache.Tests.ps1 failed with:

and so on


Module in use and version:

  • Module: PSDocs.Azure
  • Version: main branch

Captured output from $PSVersionTable:

Name                           Value
----                           -----
PSVersion                      7.3.3
PSEdition                      Core
GitCommitId                    7.3.3
OS                             Linux 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Additional context

Will create a PR shortly

Allow optional parameters to be skipped in snippet

Currently optional parameters are included in the parameter file snippet with their default values.

Since these parameters are not actually required using a more simplified snippet is useful in some scenarios.

Ignore function default values in snippets

Description of the issue

Azure template functions are not valid in parameter files.

When Azure templates has a default value such as [resourceGroup.location] this should not be included in the parameter file snippet since it is not valid.

Expected behaviour

Exclude parameters with a default value of a function in parameter file snippet.

Module in use and version:

  • Module: PSDocs.Azure
  • Version: 0.4.0-B2107004

Captured output from $PSVersionTable:

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19043
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Use clear placeholders for required parameters in snippets

Currently required parameters unless an example is provided will default to an empty value, however they are required.

Similar to the Azure quick start gallery, it would be better to provide a placeholder value instead of an empty value.

KeywordOutsideEngine Issue

Hello,

Not sure this is the right place for this but I am using PSDocs along inside a powershell script to create a wiki page for azure devops.

It had been working fine but now out of nowhere it breaks when I run:

#region Create WIKI MarkDown Content
Write-Output "Creating mark down table for wiki"
Document 'Create-MarkdownTable' {
$date = Get-Date -UFormat "%d/%m/%Y %R"
Section Summary {
"This is the work item list for the build created: $date"
}
Section 'Work items'{
if ($InputObject.Count -lt 1)
{
"No work items are associated"
}
foreach($item in $InputObject)
{
"#$item"
}
}
}

Specifically:

Document 'Create-MarkdownTable' {

Has anything changed to PSDocs that may have caused this.

It throws an error of:

The property 'KeywordOutsideEngine' cannot be found on this object. Verify that the property exists.
At C:\Users\tom.gorton\Documents\WindowsPowerShell\Modules\PSDocs\0.7.0\PSDocs.psm1:389 char:10

  •      Write-Error -Message $LocalizedHelp.KeywordOutsideEngine -Ca ...
    
  •      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [], PropertyNotFoundException
    • FullyQualifiedErrorId : PropertyNotFoundStrict

Error importing the PSDocs.Azure module

Description of the issue

Received this error after installing.

Import-Module : Errors occurred while loading the format data file:
C:\Program Files\WindowsPowerShell\Modules\PSDocs\0.7.0\PSDocs.Format.ps1xml, Error at XPath
/Configuration/ViewDefinitions/View[1] in file C:\Program
Files\WindowsPowerShell\Modules\PSDocs\0.7.0\PSDocs.Format.ps1xml: A node is missing from TableControl, ListControl,
WideControl, CustomControl.
C:\Program Files\WindowsPowerShell\Modules\PSDocs\0.7.0\PSDocs.Format.ps1xml, Error at XPath
/Configuration/ViewDefinitions/View[1]/TableControl/TableHeaders in file C:\Program
Files\WindowsPowerShell\Modules\PSDocs\0.7.0\PSDocs.Format.ps1xml: The column header definition is not valid; all
headers are discarded.

C:\Program Files\WindowsPowerShell\Modules\PSDocs\0.7.0\PSDocs.Format.ps1xml, Error at XPath
/Configuration/ViewDefinitions/View[1]/TableControl/TableHeaders/TableColumnHeader[1]/Label in file C:\Program
Files\WindowsPowerShell\Modules\PSDocs\0.7.0\PSDocs.Format.ps1xml: The resource PSDocs.Resources.ViewStrings in
assembly C:\PSDocs is not found.
At line:1 char:1
+ Import-Module PSDocs.Azure
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], RuntimeException
    + FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand

To Reproduce

Steps to reproduce the issue:

Install-Module -Name 'PSDocs.Azure' -Repository PSGallery;
Import-Module PSDocs.Azure

Expected behaviour

Imported successfully without any error.

Error output

Capture any error messages and or verbose messages with -Verbose.

VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\PSDocs.Azure\0.1.0\PSDocs.Azure.psd1'.
VERBOSE: Cannot verify the Microsoft .NET Framework version 4.7.2 because it is not included in the list of permitted
versions.
Import-Module : Errors occurred while loading the format data file:
C:\Program Files\WindowsPowerShell\Modules\PSDocs\0.7.0\PSDocs.Format.ps1xml, Error at XPath
/Configuration/ViewDefinitions/View[1] in file C:\Program
Files\WindowsPowerShell\Modules\PSDocs\0.7.0\PSDocs.Format.ps1xml: A node is missing from TableControl, ListControl,
WideControl, CustomControl.
C:\Program Files\WindowsPowerShell\Modules\PSDocs\0.7.0\PSDocs.Format.ps1xml, Error at XPath
/Configuration/ViewDefinitions/View[1]/TableControl/TableHeaders in file C:\Program
Files\WindowsPowerShell\Modules\PSDocs\0.7.0\PSDocs.Format.ps1xml: The column header definition is not valid; all
headers are discarded.
C:\Program Files\WindowsPowerShell\Modules\PSDocs\0.7.0\PSDocs.Format.ps1xml, Error at XPath
/Configuration/ViewDefinitions/View[1]/TableControl/TableHeaders/TableColumnHeader[1]/Label in file C:\Program
Files\WindowsPowerShell\Modules\PSDocs\0.7.0\PSDocs.Format.ps1xml: The resource PSDocs.Resources.ViewStrings in
assembly C:\PSDocs is not found.
At line:1 char:1
+ Import-Module PSDocs.Azure -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], RuntimeException
    + FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand

Module in use and version:

  • Module: PSDocs.Azure
  • Version: 0.7.0

Captured output from $PSVersionTable:

Name                           Value
----                           -----
PSVersion                      5.1.19041.610
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.610
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Additional context

Add any other context about the problem here.

Improve output of parameter default values for object types

Template parameters can be different types including object. When a default value for an object parameter is specified the default value is serialized as a string instead of an object.

For example

{
    "type": "object",
    "defaultValue": {
        "defaultAction": "Allow",
        "bypass": "AzureServices",
        "ipRules": [],
        "virtualNetworkRules": []
    }
}

Which is outputted as:

@{defaultAction=Allow; bypass=AzureServices; ipRules=System.Object[]; virtualNetworkRules=System.Object[]}

This formatting is not ideal and hard to understand, we can do better.

BUG - Parameter required on nullable types

Description of the issue

Nullable datatypes in bicep compiles to json with the nullable-property as true, but the docs will say the parameter is required and not optional. The module should be report optional if property defaultValue is not empty or if this property nullable is true.

To reproduce

Bicep code like this:

@description('Optional. List of application security groups to deploy.')
param applicationSecurityGroups string[]?

Builds to json like this:

"applicationSecurityGroups": {
  "type": "array",
  "items": {
    "type": "string"
  },
  "nullable": true,
  "metadata": {
    "description": "Optional. List of application security groups to deploy."
  }
}

Results in doc like this:

applicationSecurityGroups

Parameter Setting

Optional. List of application security groups to deploy.

Expected behaviour

![Parameter Setting] should be set as optional if the parameter-property nullable is true.

Module in use and version:

  • Module: PSDocs.Azure
  • Version: [0.3.0]

Captured output from $PSVersionTable:

Name                           Value
----                           -----
PSVersion                      7.4.1
PSEdition                      Core
GitCommitId                    7.4.1
OS                             Darwin 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:25 PDT 2024; root:xnu-100…
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Additional context
none

Automatically detect templates in a scan path

With PSDocs v0.9.0 we can scan a sub-directory and generate documentation for templates based on a schema with selectors.

Instead of integration code like this:

# Scan for Azure template file recursively in the templates/ directory
Get-AzDocTemplateFile -Path templates/ | ForEach-Object {
    # Generate a standard name of the markdown file. i.e. <name>_<version>.md
    $template = Get-Item -Path $_.TemplateFile;
    $templateName = $template.Directory.Parent.Name;
    $version = $template.Directory.Name;
    $docName = "$($templateName)_$version";

    # Generate markdown
    Invoke-PSDocument -Module PSDocs.Azure -OutputPath out/docs/ -InputObject $template.FullName -InstanceName $docName;
}

or

Get-AzDocTemplateFile -Path templates/ | ForEach-Object {
    Invoke-PSDocument -Module PSDocs.Azure -OutputPath out/docs/ -InputObject $_.TemplateFile -Convention 'Azure.NameByParentPath';
}

we want this:

Invoke-PSDocument -Module PSDocs.Azure -InputPath . -Convention 'Azure.NameByParentPath' -OutputPath 'out/docs/'

Add template summary

Azure Quickstart templates include an additional summary within metadata.json, however currently we don't support this metadata property.

Supporting an additional summary property would allow separation between a short synopsis and a longer description.

Add command for template discovery

To build documentation based on template we first need to scan for and discover them.

To determine if the files are valid the schema must also be checked as there could be other unrelated JSON files with in the search path.

Documentation for templates

Build out documentation for additional metadata that can be added to template. For example:

"metadata": {
"name": "Storage Account",
"description": "Create or update a Storage Account."
},

"metadata": {
"description": "Optional. The Azure region to deploy to.",
"example": "EastUS",
"ignore": true
}

Documentation needs to be published under MicrosoftDocs.

Cannot bind argument when metadata name is not set

Description of the issue

An exception occurs when template metadata name is not set.

Expected behaviour

If the metadata name is not set the document should still be generated with a default title.

Error output

Invoke-PSDocument: Cannot bind argument to parameter 'Text' because it is null.

Module in use and version:

  • Module: PSDocs.Azure
  • Version: 0.1.0

Captured output from $PSVersionTable:

Name                           Value
----                           -----
PSVersion                      7.1.1
PSEdition                      Core
GitCommitId                    7.1.1
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.