Skip to content

Commit

Permalink
feat: Enabled support for * properties in UDTs (#1891)
Browse files Browse the repository at this point in the history
## 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

<!-- Insert your Pipeline Status Badge below -->

| 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

<!-- Use the check-boxes [x] on the options that are relevant. -->

- [ ] 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

<!-- Please keep up to day with the contribution guide at
https://aka.ms/avm/contribute/bicep -->

---------

Co-authored-by: Erika Gressi <[email protected]>
  • Loading branch information
AlexanderSehr and eriqua authored May 9, 2024
1 parent 898d1a9 commit cf31866
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion avm/res/network/bastion-host/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion avm/res/network/public-ip-address/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion avm/res/network/public-ip-prefix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion avm/res/resources/deployment-script/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
37 changes: 26 additions & 11 deletions avm/utilities/pipelines/sharedScripts/Set-ModuleReadMe.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
Expand Down

0 comments on commit cf31866

Please sign in to comment.