From cf31866b12a7fa62ae6e406118bc66ebf0ecf49b Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Thu, 9 May 2024 16:22:05 +0200 Subject: [PATCH] feat: Enabled support for `*` properties in UDTs (#1891) ## Description > Note: Required for #1257 Enabled support for `*` properties in UDTs ([ref](https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/user-defined-data-types#:~:text=Decorators%20may%20be,10%20characters%20long.)) Used `>Any_other_property<` as a stand-in property name (as `*` seemed a bit unintuitive). We can change it to something else, but the Parameter name must be distinct enough & may not contain whitespaces. Tested for pattern module [Hub Networking](https://github.com/hundredacres/bicep-registry-modules/tree/hubspoke/avm/ptn/network/hub-networking) by @hundredacres Regenerated all docs for testing to ensure everything still works as intended. ## Tests ### Case 1: UDT is object ```bicep @description('Optional. A map of the hub virtual networks to create.') param hubVirtualNetworks hubVirtualNetworkObject type hubVirtualNetworkObject = { @description('Optional. Array of hub virtual networks to create.') *: hubVirtualNetworkType? }? ``` Result ![image](https://github.com/Azure/bicep-registry-modules/assets/5365358/f72a53ea-1e1f-4794-adf6-557e8b71943f) ### Case 2: UDT is array ```bicep @description('Optional. Type test') param testObject testObjectType type testObjectType = { @description('Optional. Array of hub virtual networks to create.') *: hubVirtualNetworkType? }[]? ``` Result ![image](https://github.com/Azure/bicep-registry-modules/assets/5365358/ac5c890d-bc76-448b-b9b8-9c627a2dd09b) ## Pipeline Reference | Pipeline | | -------- | | [![avm.res.key-vault.vault](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.key-vault.vault.yml/badge.svg?branch=users%2Falsehr%2FreadmeScriptAstrixSupport&event=workflow_dispatch)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.key-vault.vault.yml) | ## Type of Change - [ ] Update to CI Environment or utlities (Non-module effecting changes) - [ ] Azure Verified Module updates: - [ ] Bugfix containing backwards compatible bug fixes, and I have NOT bumped the MAJOR or MINOR version in `version.json`: - [ ] Someone has opened a bug report issue, and I have included "Closes #{bug_report_issue_number}" in the PR description. - [ ] The bug was found by the module author, and no one has opened an issue to report it yet. - [ ] Feature update backwards compatible feature updates, and I have bumped the MINOR version in `version.json`. - [ ] Breaking changes and I have bumped the MAJOR version in `version.json`. - [ ] Update to documentation ## Checklist - [ ] I'm sure there are no other open Pull Requests for the same update/change - [ ] I have run `Set-AVMModule` locally to generate the supporting module files. - [ ] My corresponding pipelines / checks run clean and green without any errors or warnings --------- Co-authored-by: Erika Gressi <56914614+eriqua@users.noreply.github.com> --- avm/res/network/bastion-host/README.md | 2 +- avm/res/network/public-ip-address/README.md | 2 +- avm/res/network/public-ip-prefix/README.md | 2 +- avm/res/resources/deployment-script/README.md | 2 +- .../sharedScripts/Set-ModuleReadMe.ps1 | 37 +++++++++++++------ 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/avm/res/network/bastion-host/README.md b/avm/res/network/bastion-host/README.md index 098db0b7a9..c3134f3fbe 100644 --- a/avm/res/network/bastion-host/README.md +++ b/avm/res/network/bastion-host/README.md @@ -19,7 +19,7 @@ This module deploys a Bastion Host. | `Microsoft.Authorization/roleAssignments` | [2022-04-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2022-04-01/roleAssignments) | | `Microsoft.Insights/diagnosticSettings` | [2021-05-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Insights/2021-05-01-preview/diagnosticSettings) | | `Microsoft.Network/bastionHosts` | [2022-11-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/2022-11-01/bastionHosts) | -| `Microsoft.Network/publicIPAddresses` | [2023-09-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/publicIPAddresses) | +| `Microsoft.Network/publicIPAddresses` | [2023-09-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/2023-09-01/publicIPAddresses) | ## Usage examples diff --git a/avm/res/network/public-ip-address/README.md b/avm/res/network/public-ip-address/README.md index 68b5ff6ceb..7e00e44faa 100644 --- a/avm/res/network/public-ip-address/README.md +++ b/avm/res/network/public-ip-address/README.md @@ -18,7 +18,7 @@ This module deploys a Public IP Address. | `Microsoft.Authorization/locks` | [2020-05-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2020-05-01/locks) | | `Microsoft.Authorization/roleAssignments` | [2022-04-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2022-04-01/roleAssignments) | | `Microsoft.Insights/diagnosticSettings` | [2021-05-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Insights/2021-05-01-preview/diagnosticSettings) | -| `Microsoft.Network/publicIPAddresses` | [2023-09-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/publicIPAddresses) | +| `Microsoft.Network/publicIPAddresses` | [2023-09-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/2023-09-01/publicIPAddresses) | ## Usage examples diff --git a/avm/res/network/public-ip-prefix/README.md b/avm/res/network/public-ip-prefix/README.md index 9dd7e7ea69..70e67da18f 100644 --- a/avm/res/network/public-ip-prefix/README.md +++ b/avm/res/network/public-ip-prefix/README.md @@ -17,7 +17,7 @@ This module deploys a Public IP Prefix. | :-- | :-- | | `Microsoft.Authorization/locks` | [2020-05-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2020-05-01/locks) | | `Microsoft.Authorization/roleAssignments` | [2022-04-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2022-04-01/roleAssignments) | -| `Microsoft.Network/publicIPPrefixes` | [2023-09-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/publicIPPrefixes) | +| `Microsoft.Network/publicIPPrefixes` | [2023-09-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/2023-09-01/publicIPPrefixes) | ## Usage examples diff --git a/avm/res/resources/deployment-script/README.md b/avm/res/resources/deployment-script/README.md index 1432d407c5..ca8ccda147 100644 --- a/avm/res/resources/deployment-script/README.md +++ b/avm/res/resources/deployment-script/README.md @@ -17,7 +17,7 @@ This module deploys Deployment Scripts. | :-- | :-- | | `Microsoft.Authorization/locks` | [2020-05-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2020-05-01/locks) | | `Microsoft.Authorization/roleAssignments` | [2022-04-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2022-04-01/roleAssignments) | -| `Microsoft.Resources/deploymentScripts` | [2023-08-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Resources/deploymentScripts) | +| `Microsoft.Resources/deploymentScripts` | [2023-08-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Resources/2023-08-01/deploymentScripts) | ## Usage examples diff --git a/avm/utilities/pipelines/sharedScripts/Set-ModuleReadMe.ps1 b/avm/utilities/pipelines/sharedScripts/Set-ModuleReadMe.ps1 index 0cb4f68bd5..43ee7b2dd7 100644 --- a/avm/utilities/pipelines/sharedScripts/Set-ModuleReadMe.ps1 +++ b/avm/utilities/pipelines/sharedScripts/Set-ModuleReadMe.ps1 @@ -416,17 +416,32 @@ function Set-DefinitionSection { #recursive call for children if ($definition) { - if ($definition.ContainsKey('items') -and $definition['items'].ContainsKey('properties')) { - $childProperties = $definition['items']['properties'] - $sectionContent = Set-DefinitionSection -TemplateFileContent $TemplateFileContent -Properties $childProperties -ParentName $paramIdentifier -ParentIdentifierLink $paramIdentifierLink -ColumnsInOrder $ColumnsInOrder - - $listSectionContent += $sectionContent - - } elseif ($definition.type -eq 'object' -and $definition['properties']) { - $childProperties = $definition['properties'] - $sectionContent = Set-DefinitionSection -TemplateFileContent $TemplateFileContent -Properties $childProperties -ParentName $paramIdentifier -ParentIdentifierLink $paramIdentifierLink -ColumnsInOrder $ColumnsInOrder - - $listSectionContent += $sectionContent + # 'items' refers to an array + # 'properties' is the default for UDTs, 'additionalProperties' represents a used '*' identifier + if ($definition.Keys -contains 'items' -and ($definition.items.properties.Keys -or $definition.items.additionalProperties.Keys)) { + if ($definition.items.properties.Keys) { + $childProperties = $definition.items.properties + $sectionContent = Set-DefinitionSection -TemplateFileContent $TemplateFileContent -Properties $childProperties -ParentName $paramIdentifier -ParentIdentifierLink $paramIdentifierLink -ColumnsInOrder $ColumnsInOrder + $listSectionContent += $sectionContent + } + if ($definition.items.additionalProperties.Keys) { + $childProperties = $definition.items.additionalProperties + $formattedProperties = @{ '>Any_other_property<' = $childProperties } + $sectionContent = Set-DefinitionSection -TemplateFileContent $TemplateFileContent -Properties $formattedProperties -ParentName $paramIdentifier -ParentIdentifierLink $paramIdentifierLink -ColumnsInOrder $ColumnsInOrder + $listSectionContent += $sectionContent + } + } elseif ($definition.type -eq 'object' -and ($definition.properties.Keys -or $definition.additionalProperties.Keys)) { + if ($definition.properties.Keys) { + $childProperties = $definition.properties + $sectionContent = Set-DefinitionSection -TemplateFileContent $TemplateFileContent -Properties $childProperties -ParentName $paramIdentifier -ParentIdentifierLink $paramIdentifierLink -ColumnsInOrder $ColumnsInOrder + $listSectionContent += $sectionContent + } + if ($definition.additionalProperties.Keys) { + $childProperties = $definition.additionalProperties + $formattedProperties = @{ '>Any_other_property<' = $childProperties } + $sectionContent = Set-DefinitionSection -TemplateFileContent $TemplateFileContent -Properties $formattedProperties -ParentName $paramIdentifier -ParentIdentifierLink $paramIdentifierLink -ColumnsInOrder $ColumnsInOrder + $listSectionContent += $sectionContent + } } } }