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

Nested user-defined templates with discriminator are not parsed correctly when using nested loading from bicep registry #13726

Closed
Adunaphel opened this issue Mar 27, 2024 · 0 comments · Fixed by #13733
Assignees
Milestone

Comments

@Adunaphel
Copy link

Bicep version
Bicep CLI version 0.26.54 (5e20b29)

Describe the bug
Resource specific user-defined types are described in their own bicep stored in a bicep registry. These are then referenced in a user-defined type for the main deployment that describes the resource group that houses these resources, as following:

resource.types.bicep:

type resourceType = {
  name: string
  <type declaration>
}

main.types.bicep:

import { resourceType } from '<resourceBicepLocation>'

type resourceGroupType = {
  name: string
  resources: resourceGroupType[]
}

main.bicep:

import { resourceGroupType } from 'main.types.bicep'

param resourceGroups = resourceGroupType[]

<deploy stuff>

Of course, several of these resources have nested sub-types that have a discriminator. When referencing the resourceType directly from a local file (resourceBicepLocation in main.types.bicep is 'resource.types.bicep') and then publishing main.bicep this all works as it should. When referencing the resourceType from the bicep in bicep registry (resourceBicepLocation in main.types.bicep is a br: address) the nested type with discriminator doesn't load, instead it loads as all properties being *: any

To Reproduce
Steps to reproduce the behavior:
test1.bicep:

@export()
type testType = {
  subType: subType[]
}

@discriminator('type')
type subType = testSub1 | testSub2 | testSub3

type testSub1 = {
  type: '1'
  subOption1: string
}

type testSub2 = {
  type: '2'
  subOption2: int
}

type testSub3 = {
  type: '3'
  subOption3: bool
}

main.types.bicep

import { testType } from 'test1.bicep'

@export()
type mainType = {
  name: string
  test: testType[]?
}

main.bicep

import { mainType } from 'main.types.bicep'

param main mainType

output mainOut object = main

when publishing main.bicep in this form to a bicep registry and referencing from a bicepparam, the subType is loaded correctly. When instead the test1.bicep is published to a private registry, main.types.bicep is edited to reference the file from the registry, and then main.bicep is published to a private registry, the subType is loaded as *: any

Additional context
I understand that this is a niche issue, but it does allow me to limit the amount of duplicate code in a registry

@jeskew jeskew added this to the v0.27 milestone Mar 28, 2024
jeskew added a commit that referenced this issue Mar 28, 2024
Resolves #13726

This PR updates the import closure compiler to take account of ARM's
`discriminator` constraint both for type declaration -> TypeExpression
conversion and for reference collecting purposes.
###### Microsoft Reviewers: [Open in
CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/13733)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants