Skip to content

Commit e5d6766

Browse files
authored
Merge pull request #264808 from mumian/0131-bicepconfig
Resolve bicepconfig.json
2 parents 3619374 + 0a29587 commit e5d6766

File tree

4 files changed

+104
-7
lines changed

4 files changed

+104
-7
lines changed

articles/azure-resource-manager/bicep/bicep-config.md

Lines changed: 102 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ title: Bicep config file
33
description: Describes the configuration file for your Bicep deployments
44
ms.topic: conceptual
55
ms.custom: devx-track-bicep
6-
ms.date: 09/27/2023
6+
ms.date: 02/02/2024
77
---
88

99
# Configure your Bicep environment
1010

11-
Bicep supports an optional configuration file named `bicepconfig.json`. Within this file, you can add values that customize your Bicep development experience.
12-
13-
To customize configuration, create this file in the same directory, or a parent directory of your Bicep files. If multiple parent directories contain `bicepconfig.json` files, Bicep uses configuration from the nearest one. If a configuration file is not found, Bicep uses default values.
11+
Bicep supports an optional configuration file named `bicepconfig.json`. Within this file, you can add values that customize your Bicep development experience. This file is merged with the [default configuration file](https://github.com/Azure/bicep/blob/main/src/Bicep.Core/Configuration/bicepconfig.json). For more information, see [Understand the merge process](#understand-the-merge-process). To customize configuration, create a configuration file in the same directory or a parent directory of your Bicep files. If there are multiple parent directories containing `bicepconfig.json` files, Bicep uses the configuration from the nearest one. For more information, see [Understand the file resolution process](#understand-the-file-resolution-process).
1412

1513
To configure Bicep extension settings, see [VS Code and Bicep extension](./install.md#visual-studio-code-and-bicep-extension).
1614

@@ -26,6 +24,105 @@ The Bicep extension for Visual Studio Code supports intellisense for your `bicep
2624

2725
:::image type="content" source="./media/bicep-config/bicep-linter-configure-intellisense.png" alt-text="Screenshot of the intellisense support in configuring bicepconfig.json.":::
2826

27+
## Understand the merge process
28+
29+
The `bicepconfig.json` file undergoes a recursive bottom-up merging process with the default configuration file. During the merging process, Bicep examines each path in both configurations. If a path isn't present in the default configuration, the path and its associated value are added in the final result. Conversely, if a path exists in the default configuration with a different value, the value from `bicepconfig.json` takes precedence in the merged result.
30+
31+
Consider a scenario where the default configuration is defined as follows:
32+
33+
```json
34+
{
35+
"cloud": {
36+
...
37+
"credentialPrecedence": [
38+
"AzureCLI",
39+
"AzurePowerShell"
40+
]
41+
},
42+
"moduleAliases": {
43+
"ts": {},
44+
"br": {
45+
"public": {
46+
"registry": "mcr.microsoft.com",
47+
"modulePath": "bicep"
48+
}
49+
}
50+
},
51+
...
52+
}
53+
```
54+
55+
And the `bicepconfig.json` is defined as follows:
56+
57+
```json
58+
{
59+
"cloud": {
60+
"credentialPrecedence": [
61+
"AzurePowerShell",
62+
"AzureCLI"
63+
]
64+
},
65+
"moduleAliases": {
66+
"br": {
67+
"ContosoRegistry": {
68+
"registry": "contosoregistry.azurecr.io"
69+
},
70+
"CoreModules": {
71+
"registry": "contosoregistry.azurecr.io",
72+
"modulePath": "bicep/modules/core"
73+
}
74+
}
75+
}
76+
}
77+
```
78+
79+
The resulting merged configuration would be:
80+
81+
```json
82+
{
83+
"cloud": {
84+
...
85+
"credentialPrecedence": [
86+
"AzurePowerShell",
87+
"AzureCLI"
88+
]
89+
},
90+
"moduleAliases": {
91+
"ts": {},
92+
"br": {
93+
"public": {
94+
"registry": "mcr.microsoft.com",
95+
"modulePath": "bicep"
96+
},
97+
"ContosoRegistry": {
98+
"registry": "contosoregistry.azurecr.io"
99+
},
100+
"CoreModules": {
101+
"registry": "contosoregistry.azurecr.io",
102+
"modulePath": "bicep/modules/core"
103+
}
104+
}
105+
},
106+
...
107+
}
108+
```
109+
110+
In the preceding example, the value of `cloud.credentialPrecedence` is replaced, while the value of `cloud.moduleAliases.ContosoRegistry` and `cloud.moduleAliases.CoreModules` are appended in the merged configuration.
111+
112+
## Understand the file resolution process
113+
114+
The `bicepconfig.json` file can be placed in the same directory or a parent directory of your Bicep files. If there are multiple parent directories containing `bicepconfig.json` files, Bicep uses the configuration file from the nearest one. For instance, in the given folder structure where each folder has a `bicepconfig.json` file:
115+
116+
:::image type="content" source="./media/bicep-config/bicep-config-file-resolve.png" alt-text="A diagram showing resolving `bicepconfig.json` found in multiple parent folders.":::
117+
118+
If you compile `main.bicep` in the `child` folder, the `bicepconfig.json` file in the `child` folder is used. The configuration files in the `parent` folder and the `root` folder are ignored. If the `child` folder doesn't contain a configuration file, Bicep searches for a configuration in the `parent` folder and then the `root` folder. If no configuration file is found in any of the folders, Bicep defaults to using the [default values](https://github.com/Azure/bicep/blob/main/src/Bicep.Core/Configuration/bicepconfig.json).
119+
120+
In the context of a Bicep file invoking multiple modules, each module undergoes compilation using the nearest `bicepconfig.json`. Then, the main Bicep file is compiled with its corresponding `bicepconfig.json`. In the following scenario, `modA.bicep` is compiled using the `bicepconfig.json` located in the `A` folder, `modB.bicep` is compiled with the `bicepconfig.json` in the `B` folder, and finally, `main.bicep` is compiled using the `bicepconfig.json` in the `root` folder.
121+
122+
:::image type="content" source="./media/bicep-config/bicep-config-file-resolve-module.png" alt-text="A diagram showing resolving `bicepconfig.json` found in multiple parent folders with the module scenario.":::
123+
124+
In the absence of a `bicepconfig.json` file in the `A` and `B` folders, all three Bicep files are compiled using the `bicepconfig.json` found in the `root` folder. If `bicepconfig.json` isn't present in any of the folders, the compilation process defaults to using the [default values](https://github.com/Azure/bicep/blob/main/src/Bicep.Core/Configuration/bicepconfig.json).
125+
29126
## Configure Bicep modules
30127

31128
When working with [modules](modules.md), you can add aliases for module paths. These aliases simplify your Bicep file because you don't have to repeat complicated paths. You can also configure cloud profile and credential precedence for authenticating to Azure from Bicep CLI and Visual Studio Code. The credentials are used to publish modules to registries and to restore external modules to the local cache when using the insert resource function. For more information, see [Add module settings to Bicep config](bicep-config-modules.md).
@@ -38,7 +135,7 @@ The [Bicep linter](linter.md) checks Bicep files for syntax errors and best prac
38135

39136
You can enable experimental features by adding the following section to your `bicepconfig.json` file.
40137

41-
Here is an example of enabling features 'compileTimeImports' and 'userDefinedFunctions`.
138+
Here's an example of enabling features 'compileTimeImports' and 'userDefinedFunctions`.
42139

43140
```json
44141
{
6.08 KB
Loading
4.52 KB
Loading

articles/azure-resource-manager/bicep/modules.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Bicep modules
33
description: Describes how to define a module in a Bicep file, and how to use module scopes.
44
ms.topic: conceptual
55
ms.custom: devx-track-bicep
6-
ms.date: 10/13/2023
6+
ms.date: 02/02/2024
77
---
88

99
# Bicep modules
@@ -19,7 +19,7 @@ To share modules with other people in your organization, create a [template spec
1919
> - Content in the Bicep module registry can only be deployed from another Bicep file. Template specs can be deployed directly from the API, Azure PowerShell, Azure CLI, and the Azure portal. You can even use [`UiFormDefinition`](../templates/template-specs-create-portal-forms.md) to customize the portal deployment experience.
2020
> - Bicep has some limited capabilities for embedding other project artifacts (including non-Bicep and non-ARM-template files. For example, PowerShell scripts, CLI scripts and other binaries) by using the [`loadTextContent`](./bicep-functions-files.md#loadtextcontent) and [`loadFileAsBase64`](./bicep-functions-files.md#loadfileasbase64) functions. Template specs can't package these artifacts.
2121
22-
Bicep modules are converted into a single Azure Resource Manager template with [nested templates](../templates/linked-templates.md#nested-template).
22+
Bicep modules are converted into a single Azure Resource Manager template with [nested templates](../templates/linked-templates.md#nested-template). For more information about how Bicep resolves configuration files and how Bicep merge user-defined configuration file with the default configuration file, see [Configuration file resolution process](./bicep-config.md#understand-the-file-resolution-process) and [Configuration file merge process](./bicep-config.md#understand-the-merge-process).
2323

2424
### Training resources
2525

0 commit comments

Comments
 (0)