Azure / Azure/bicep

Support `@export()` while importing a type via `import (...)`

Open
#17,338 8 comments 4 reactions 0 assignees View on GitHub
enhancement Needs: Upvote type system
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

I'd like to expand the feature of exporting Bicep types to not only exporting types declared in the current template, but also those it itself imports.

For example:
```Bicep
@export()
import { keyType } from 'br/public:avm/res/key-vault/vault:1.0.0'

@export()
import {
appSettingsConfigType
authSettingsConfigType
authSettingsV2ConfigType
azureStorageAccountConfigType
backupConfigType
connectionStringsConfigType
logsConfigType
metadataConfigType
pushSettingsConfigType
webConfigType
} from 'slot/main.bicep'
```

This would be very useful to enable 2 scenarios
1. Enable modules to maintain a `types.bicep` file to declare all custom types which they import for usage. Further, enable users of these modules to also import set types directly from these modules without needing to 'guess' which ones may have been used from the `types.bicep` file. Considering the scenario of a private or the Public Bicep Registry, this is almost a necessaty, as 'if' the `types.bicep` file is not itself published to a registry, there's not way of importing those types as a consumer from set registry.
2. A more current scenario is a module like BRMs Web-Site and it's child module Web-Site-Slot [ref](https://github.com/Azure/bicep-registry-modules/blob/f347dbb56648b25c73a91aa0744e026e71db1a40/avm/res/web/site/main.bicep#L328). Both the parent and the child module share the same types - which are defined in the child via a wooping ~1.400 lines of code. The problem: While all types are defined with the `export()` annotation so that the parent module can re-use them, the parent itself cannot also export them without duplicating all types in its own template. Because only the parent is published as of today, this means again that users of this module have no way of re-useing the types.

We currently have this issue with the Web-Site module ([ref](https://github.com/Azure/bicep-registry-modules/issues/5335#issuecomment-2972676633)) but also had it before. In BRM we aspire to make all types available as consumers of the modules may want to expose the same parameters in their own solution templates.
The case of a module like `Web-Site` is just especially interesting, as the types defined in the templates are not available as Resource-Derived-Types as they are dependent on a discriminator. So actually being able to re-use the types is especially valuable.

Contributor guide

Open the contributing guide

Research direction

Begin with the import examples in this issue and compare the current @export() behavior for locally declared types with imported types. Use the referenced main.bicep files as behavioral examples; done means an imported type can be re-exported by a module and consumed from the published parent without duplicating its declaration.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.