Azure / Azure/bicep

Direct inline usage of `tenant().tenantId` in expressions can cause failures when the module is published to and then referenced from a Bicep registry

Open
#18,054 2 comments 0 reactions 1 assignee Claimed by @majastrz View on GitHub
intermediate language QS 2026 Quality Sprint
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

**Bicep version**
Bicep CLI version 0.37.4 (27cc8db2ed)

**Describe the bug**
Directly using `tenant().tenantId` in expressions can lead to failures when the module is published to and then referenced from a Bicep registry. While importing the module from a local file works fine, uploading it to the Bicep registry and referencing it from there in VS Code highlights the import directive reference and provides a tooltip:

"The referenced ARM template has errors. Please see https://aka.ms/arm-template for information on how to diagnose and fix the template.bicep[BCP188](https://aka.ms/bicep/core-diagnostics#BCP188)"

**To Reproduce**
Add following code to the module and publish it to Bicep registry.
```bicep
var configMap = {
'key1': {
'${developmentTenantId}': 'dev value 1'
'${productionTenantId}': 'prod value 1'
}
'key2': {
'${developmentTenantId}': 'dev value 2'
'${productionTenantId}': 'prod value 2'
}

@export()
func getConfig(key string) string => '${configMap[key][tenant().tenantId]}'

```

Then create new file and try importing a module:
```bicep
import * as m from 'br:myregistry.azurecr.io/bicep/modules/my-module:v1.0'
```

**Additional context**
There is a workaround to assign `tenant().tenantId` to variable first:
```bicep
// Workaround: Extracting tenant().tenantId to a variable to ensure compatibility with Bicep registry.
// Direct inline usage of tenant().tenantId in expressions can cause failures when the module is published to and then referenced from a Bicep registry.
var tenantId = tenant().tenantId

var configMap = {
'key1': {
'${developmentTenantId}': 'dev value 1'
'${productionTenantId}': 'prod value 1'
}
'key2': {
'${developmentTenantId}': 'dev value 2'
'${productionTenantId}': 'prod value 2'
}

@export()
func getConfig(key string) string => '${configMap[key][tenantId]}'
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.