Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added support for Discrimintor-based variants to readme utility #4146

Open
wants to merge 52 commits into
base: main
Choose a base branch
from

Conversation

AlexanderSehr
Copy link
Contributor

@AlexanderSehr AlexanderSehr commented Jan 12, 2025

Description

  • Variants of a type are listed below the property with the discriminator and are recurisvely resolved just as classic parameter - just with the discriminator in the header
  • Also, because it surfaced in this PR for two modules, I implemented a fix for the ReadMe test that previously (if failed) could under specific cirmustances also fail the GitHub Output. The circmustance was that the Set-ModuleReadMe script would throw an exception during the generation, returning the error that would hit the Pester-Output which in turn would pollute the test results the GitHub-Output function then failed to interpret and publish. The fix essentially catches this exception and fails the test with a proper error message, pointing to the actual cause of the error (e.g., a parameter not having a description category specified). See screenshots at the buttom for a before-after comparison.
  • Finally, I implemented a fix for the parameter-resolving function used by out pester tests that was unable to resolve types using a discriminator

Required module fixes

  • Updated the Virtual-Network-Gateway itself as its incorrect UDT(s) would make running the readme generation and passing the tests impossible. Changes include
    • Added missing property descriptions
    • Fixed an incorrect category for a parameter
    • Added a UDT for the NAT Rules child module
    • Updated tests
  • Updated the Insights-Metric-Alert itself as its incorrect UDT(s) would make running the readme generation and passing the tests impossible. Changes include
    • Added missing property descriptions
    • Updated tests
  • Fixed a major bug of the script handling minValues & maxValues: Essentially, the Set-ModuleReadMe script lacked 2 lines of code that would reset the two values to $null in incase no min or max value would be available for the parameter. Without this reset, the logic re-used the values of the pervious parameter. The effect: As soon as one parameter defined a min & max value - all subsequent parameters would show the same too (which is obviously very very wrong).

Closes #4128

  • TODO: Test with more recursive test templates
  • TODO: Regenerate all readmes
  • TODO: Run tests via workflows

image

Pipeline Reference

Pipeline
avm.ptn.ai-platform.baseline
avm.ptn.dev-ops.cicd-agents-and-runners
avm.ptn.lz.sub-vending
avm.res.dev-ops-infrastructure.pool
avm.res.insights.data-collection-rule
avm.res.insights.metric-alert
avm.res.machine-learning-services.workspace
avm.res.network.virtual-network-gateway
avm.res.virtual-machine-images.image-template
Modules without discriminator
avm.res.storage.storage-account

Type of Change

  • Update to CI Environment or utilities (Non-module affecting 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

Appendix

Error before the fix

image

image

Error after the fix

image

image

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: Triage 🔍 Maintainers need to triage still label Jan 12, 2025
@AlexanderSehr AlexanderSehr self-assigned this Jan 12, 2025
@AlexanderSehr AlexanderSehr added Needs: Core Team 🧞 This item needs the AVM Core Team to review it Type: CI 🚀 This issue is related to the AVM CI and removed Needs: Triage 🔍 Maintainers need to triage still labels Jan 12, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot added the Type: AVM 🅰️ ✌️ Ⓜ️ This is an AVM related issue label Jan 12, 2025
@AlexanderSehr AlexanderSehr requested review from a team as code owners March 7, 2025 19:20
arnoldna
arnoldna previously approved these changes Mar 7, 2025
@ChrisSidebotham
Copy link
Contributor

@AlexanderSehr This looks good to me is there anything we should do to prepare for this change?

@@ -1608,6 +1608,249 @@ The outbound rule. The name of the rule is the object key.

- Required: Yes
- Type: object
- Type-deciding property: type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

| :-- | :-- | :-- |
| [`category`](#parameter-workspaceconfigurationnetworkoutboundrules>any_other_property<type-fqdncategory) | string | Category of a managed network Outbound Rule of the workspace hub. |

### Parameter: `workspaceConfiguration.networkOutboundRules.>Any_other_property<.type-FQDN.destination`
Copy link
Contributor

@eriqua eriqua Mar 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it intended to have variant parameters with the same header level 3 (###)? Shouldn't they be level 4 (####)?
Not blocking if complex to achieve, as I understand they may be multiple levels of nesting (e.g. variants in parameters containing variants as well). Just wanted to bring this up

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a great question and it took me a while to understand why it's implemented in the way it is. If you collapse all sections in a readme (like this one) you'll see that the Parameters section is on nesting level 2 (##) and all parameters below it are on level 3 (###). This may seem odd a first, but the hierachy is actually not expressed via the # but the title which gets continuously appended the further 'in' you go.
image

I can't recall why this was done for the parameters originally - but - my best guess is that we'd run the hazard of having parameters being nested like ############### storageAccount.blobService.container.blob.immatbilitypolicy.somethingelse.and.so.on.lastItem. The alternative would be just to have the headers and end on ############### lastItem - but that would not be unique (so it cannot be referenced).
The other thing is that something like ################### title can look super odd in Markdown. I can't recall in which Wiki I've seen it, but I've seen these titles being rendered smaller and smaller the deeper you go. Naturally with the text below it, that's not a header, being at normal size 😄.
Anyways, these are just some guesses.

| [`useExisting`](#variant-networkingconfigurationnetworktype-useexisting) | |

### Variant: `networkingConfiguration.networkType-createNew`

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably miss a @description on the discriminator every time we have 2 empty lines after the variant header. Should we have this checked? Not for this PR, just again wanted to bring it up (maybe it's already producing a warning)

Copy link
Contributor Author

@AlexanderSehr AlexanderSehr Mar 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They do miss it, yes. So the function works as expected.

That being said we certainly do have a spec that say it's a MUST (ref) to implement certain metadata.
I don't think we have a test for it yet though - so I agree it should not be part of this PR, but be implemented. The question, as with the nullable etc. will be whether the test should be enforced or not 😄 But maybe that's something we can decide after the test was implemented and run across the modules to see how many would need fixing. But I guess it's a lot.

@AlexanderSehr AlexanderSehr requested a review from a team as a code owner March 14, 2025 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Core Team 🧞 This item needs the AVM Core Team to review it Type: AVM 🅰️ ✌️ Ⓜ️ This is an AVM related issue Type: Bug 🐛 Something isn't working Type: CI 🚀 This issue is related to the AVM CI
Projects
None yet
4 participants