Azure / bicep

Bicep is a declarative language for describing and deploying Azure resources
MIT License
3.17k stars 730 forks source link

Any type for user defined types #13399

Open slavizh opened 4 months ago

slavizh commented 4 months ago

Is your feature request related to a problem? Please describe. This API seems to have type of any. Should such type be available in user defined types? image

Describe the solution you'd like Should such type be available in user defined types?

jeskew commented 4 months ago

Tagging as "intermediate language" because there's currently no way to represent any in ARM's parameter typing system, and that would need to be in place before any could be added to Bicep. The closest you can get right now is object (which corresponds to { *: any }) or array (which corresponds to any[]).

slavizh commented 4 months ago

any is flagged as invalid type if you add it to parameter

slavizh commented 4 months ago

Another example coming from the same resource: image

It makes it hard to create schemas for these. Cannot be overcome even with any() put in the Bicep parameters file for the value.

slavizh commented 4 months ago

Additionally to the first example there is a Float type that also uses any

image

jefedeltodos commented 4 months ago

I could use this too. I am trying to setup some user defined types for a module I'm creating to setup parameter types that match the expected values for an apim operation templateParamteres, responses, etc: image

but there is no way for met to define:

@export()
type ParameterExampleContract = {
  @description('Long description for the example')
  description: string?
  @description('A URL that points to the literal example')
  externalValue: string?
  @description('Short Description for the example')
  summary: string?
  @description('Examle value. May be a primative value, or an object')
  value: any
}

Although what would be cool is if I could just import ParameterContract[] from Microsoft.ApiManagement/service/apis/operations.

So I could do something like:

import {ParameterContract} from 'Microsoft.ApiManagement/service/apis/operations'

param operationTemplateParameters: ParameterContract[]

Then I don't have to try and recreate these contracts in my bicep files and can reuse the contracts already defined by the resource definitions. (Maybe I'll make a feature request for this)

jeskew commented 4 months ago

@jefedeltodos You could try the experimental resource-derived types feature. This would require a bicepconfig.json file like the following:

{
  "experimentalFeaturesEnabled": {
    "resourceDerivedTypes": true
  }
}

With that in place, you could define your parameter as the following:

param operationTemplateParameters resource<'Microsoft.ApiManagement/service/apis/operations@2022-08-01'>.properties.templateParameters

image

slavizh commented 4 months ago

Another example from policy assignments image

This time I cannot make workaround by using discriminator type as I would have to make breaking change to existing template.

jan-delaet commented 4 months ago

We are also running into this, not sure how to implement user-defined types for resources such as an Azure Policy assignment that has properties that can accept arbitrary types. Having the "any" type available would make this scenario a lot easier to deal with.

Adunaphel commented 3 months ago

Running into this issue as well, policy assignments are the most egregious ones.

slavizh commented 4 weeks ago

another example of any: image