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

Resource Derived Types -> Add support for User Defined Types in referenced modules #13677

Open
schaijkw opened this issue Mar 22, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@schaijkw
Copy link

schaijkw commented Mar 22, 2024

Is your feature request related to a problem? Please describe.
When you declare a user defined type as a parameter of a module, you now cannot reference this type dynamically.

param myUDTValue string
param myUDTValue2 int

module myModule 'br/recipe:api:v1.0.4' = {
  name: 'myModule-${deploymentDate}'
  scope: resourceGroup
  params: {
    location: location
    myUDT: { 
     value: myUDTValue 
     secondValue: myUDTValue2 
    }
  }
}

Describe the solution you'd like
A way to reference myUDT so we can provide the values via bicepparam, like:

param myUDTParam resource<myModule.myUDT>

module myModule 'br/recipe:api:v1.0.4' = {
  name: 'myModule-${deploymentDate}'
  scope: resourceGroup
  params: {
    location: location
    myUDT: myUDTParam
  }
}
@marsontret
Copy link

marsontret commented Mar 27, 2024

In this scenario what would the custom type declaration look like? And what does your existing bicepparam file that doesn't work look like (did you try creating and importing a custom types module)?

@schaijkw
Copy link
Author

In this example, the UDT definition will look like:

type myUDT = {
     value: string
     secondValue: int
}

And the thing is that when I create a module with some parameters, including this type; I would like to pass the UDT without exporting the UDT but instead use a reference. Because I publish my modules to a registry and use only modules from that registry. So, I would like to re-use the resource derived type way of referencing for my container registry published modules.

@jeskew
Copy link
Contributor

jeskew commented Mar 27, 2024

@schaijkw Why don't you want to export the UDT?

@stephaniezyen stephaniezyen added Needs: Author Feedback Awaiting feedback from the author of the issue and removed Needs: Triage 🔍 labels Mar 27, 2024
@schaijkw
Copy link
Author

The UDT can evolve over time. And when you use a UDT as a parameter for a module, you want a specific version of that UDT, the version at time of writing your module.
You can also define your UDT in a seperate file and import the UDT in your module, but when you expose your module via a Container Registry, you don't want the consumer think of what version of UDT was used for that module.
I will work out an example later, to share my concern more clear.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Triage 🔍 and removed Needs: Author Feedback Awaiting feedback from the author of the issue labels Mar 28, 2024
@jeskew
Copy link
Contributor

jeskew commented Mar 28, 2024

I'm still not following. The module and import keywords both need to point to a concrete template, either a path on disk or a module in a registry. If the UDT evolves, that would require publishing a new version of the module, right?

Let's say you have the following template published as br/recipe:api:v1.0.4:

@export()
type myUDT = {
     value: string
     secondValue: int
}

param myUdtParam myUDT

You can consume this template as both an import source and as a module:

import {myUDT} from 'br/recipe:api:v1.0.4'

param myUDTParam myUDT

module myModule 'br/recipe:api:v1.0.4' = {
  name: 'myModule-${deploymentDate}'
  scope: resourceGroup
  params: {
    location: location
    myUdtParam: myUDTParam
  }
}

@stephaniezyen stephaniezyen added Needs: Author Feedback Awaiting feedback from the author of the issue and removed Needs: Triage 🔍 labels Apr 2, 2024
@schaijkw
Copy link
Author

schaijkw commented Apr 3, 2024

Hi Jonny, thanks for providing your example and it will work in the most straight-forward situations. I think the way how resource derived types are referenced, is easier to use, strongly-typed/more type-safe and is abstracting underlying resource references.

For example, we crafted module D in the image below. I believe that we don't have to know about the versions that are used by the modules we imported:
Module references drawio

At this moment I can reference an older version of module A without the IDE or bicep complaining.

Code example:
biceptemp.zip

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Triage 🔍 and removed Needs: Author Feedback Awaiting feedback from the author of the issue labels Apr 3, 2024
@stephaniezyen stephaniezyen modified the milestones: v1.1, Committed Backlog Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

4 participants