Azure / Azure/bicep

Support tagged unions in type property access

Open
#14,481 2 comments 4 reactions 0 assignees View on GitHub
design approved enhancement good first issue Needs: Upvote type system
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

Template can use the properties of types as types via type property access syntax. Type property access syntax currently supports object types (`foo.bar`), tuple types (`foo[1]`), dictionary types (`foo.*`), and array types (`foo[*]`), but there is no way to refer to a specific variant of a tagged union.

Strawman syntax that was briefly discussed at a team meeting uses a parameterized type: `variant, 'authsettingsV2'>.properties.login`. This might be easier to read as an "instance" parameterized type, i.e., `resource<'Microsoft.Web/sites/config@2023-12-01'>.variant<'authsettingsV2'>.properties.login`. In either case, the name needs work.

### Discussed in https://github.com/Azure/bicep/discussions/14480

Originally posted by **TomBarten** July 5, 2024
I am aware of the [documentation ](https://learn.microsoft.com/en-us/azure/templates/microsoft.web/sites/config-authsettingsv2?pivots=deployment-language-bicep#options-for-name-property )which states that the resource accepts different properties based on the value of the name property, but how can I refer to that specific type which changes based on the name property?

Or is this something which was already a known missing feature of this experimental feature?

What I am trying to achieve (with some comments on what happens):
```bicep
@export()
@secure()
type authSettings = {
// resource<'Microsoft.Web/sites/config@2023-12-01'>.properties type = object
identityProviders: resource<'Microsoft.Web/sites/config@2023-12-01'>.properties.identityProviders // The type "object" does not contain property "identityProviders".
login: resource<'Microsoft.Web/sites/config@2023-12-01'>.properties.login // The type "object" does not contain property "login"
validation: resource<'Microsoft.Web/sites/config@2023-12-01'>.properties.globalValidation // The type "object" does not contain property "globalValidation".
}

resource someWebApp 'Microsoft.Web/sites@2023-12-01' = {
name: 'webAppsz'
location: resourceGroup().location
}

resource someAuthsettingsConfig 'Microsoft.Web/sites/config@2023-12-01' = {
name: 'authsettingsV2'
parent: someWebApp
properties: {
// type = SiteAuthSettingsV2Properties
login: {
// type = Login
}
identityProviders: {
// type = IdentityProviders
}
globalValidation: {
// type = GlobalValidation
}
}
}

```

Contributor guide

Open the contributing guide

Research direction

No implementation files, tests, or entry points are named in the issue. Start with the examples in this issue and the linked discussion 14480, then define and document an agreed syntax for selecting a tagged-union variant before implementing it; done means the relevant variant properties can be accessed through type property access.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.