|
| 1 | +--- |
| 2 | +title: Module setting for Bicep config |
| 3 | +description: Describes how to customize configuration values for modules in Bicep deployments. |
| 4 | +ms.topic: conceptual |
| 5 | +ms.date: 11/16/2021 |
| 6 | +--- |
| 7 | + |
| 8 | +# Add module settings in the Bicep config file |
| 9 | + |
| 10 | +In a **bicepconfig.json** file, you can create aliases for module paths and configure credential precedence for restoring a module. |
| 11 | + |
| 12 | +This article describes the settings that are available for working with [modules](modules.md). |
| 13 | + |
| 14 | +## Aliases for modules |
| 15 | + |
| 16 | +To simplify the path for linking to modules, create aliases in the config file. An alias refers to either a module registry or a resource group that contains template specs. |
| 17 | + |
| 18 | +The config file has a property for `moduleAliases`. This property contains all of the aliases you define. Under this property, the aliases are divided based on whether they refer to a registry or a template spec. |
| 19 | + |
| 20 | +To create an alias for a **Bicep registry**, add a `br` property. To add an alias for a **template spec**, use the `ts` property. |
| 21 | + |
| 22 | +```json |
| 23 | +{ |
| 24 | + "moduleAliases": { |
| 25 | + "br": { |
| 26 | + <add-registry-aliases> |
| 27 | + }, |
| 28 | + "ts": { |
| 29 | + <add-template-specs-aliases> |
| 30 | + } |
| 31 | + } |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +Within the `br` property, add as many aliases as you need. For each alias, give it a name and the following properties: |
| 36 | + |
| 37 | +- **registry** (required): registry login server name |
| 38 | +- **modulePath** (optional): registry repository where the modules are stored |
| 39 | + |
| 40 | +Within the `ts` property, add as many aliases as you need. For each alias, give it a name and the following properties: |
| 41 | + |
| 42 | +- **subscription** (required): the subscription ID that hosts the template specs |
| 43 | +- **resourceGroup** (required): the name of the resource group that contains the template specs |
| 44 | + |
| 45 | +The following example shows a config file that defines two aliases for a module registry, and one alias for a resource group that contains template specs. |
| 46 | + |
| 47 | +```json |
| 48 | +{ |
| 49 | + "moduleAliases": { |
| 50 | + "br": { |
| 51 | + "ContosoRegistry": { |
| 52 | + "registry": "contosoregistry.azurecr.io" |
| 53 | + }, |
| 54 | + "CoreModules": { |
| 55 | + "registry": "contosoregistry.azurecr.io", |
| 56 | + "modulePath": "bicep/modules/core" |
| 57 | + } |
| 58 | + }, |
| 59 | + "ts": { |
| 60 | + "CoreSpecs": { |
| 61 | + "subscription": "00000000-0000-0000-0000-000000000000", |
| 62 | + "resourceGroup": "CoreSpecsRG" |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | +When using an alias in the module reference, you must use the formats: |
| 70 | + |
| 71 | +```bicep |
| 72 | +br/<alias>:<file>:<tag> |
| 73 | +ts/<alias>:<file>:<tag> |
| 74 | +``` |
| 75 | + |
| 76 | +Define your aliases to the folder or resource group that contains modules, not the file itself. The file name must be included in the reference to the module. |
| 77 | + |
| 78 | +**Without the aliases**, you would link to a module in a registry with the full path. |
| 79 | + |
| 80 | +```bicep |
| 81 | +module stgModule 'br:contosoregistry.azurecr.io/bicep/modules/core/storage:v1' = { |
| 82 | +``` |
| 83 | + |
| 84 | +**With the aliases**, you can simplify the link by using the alias for the registry. |
| 85 | + |
| 86 | +```bicep |
| 87 | +module stgModule 'br/ContosoRegistry:bicep/modules/core/storage:v1' = { |
| 88 | +``` |
| 89 | + |
| 90 | +Or, you can simplify the link by using the alias that specifies the registry and module path. |
| 91 | + |
| 92 | +```bicep |
| 93 | +module stgModule 'br/CoreModules:storage:v1' = { |
| 94 | +``` |
| 95 | + |
| 96 | +For a template spec, use: |
| 97 | + |
| 98 | +```bicep |
| 99 | +module stgModule 'ts/CoreSpecs:storage:v1' = { |
| 100 | +``` |
| 101 | + |
| 102 | +## Credentials for restoring modules |
| 103 | + |
| 104 | +To [restore](bicep-cli.md#restore) external modules to the local cache, the account must have the correct permissions to access the registry. You can configure the credential precedence for authenticating to the registry. By default, Bicep uses the credentials from the user authenticated in Azure CLI or Azure PowerShell. To customize the credential precedence, add `cloud` and `credentialPrecedence` elements to the config file. |
| 105 | + |
| 106 | +```json |
| 107 | +{ |
| 108 | + "cloud": { |
| 109 | + "credentialPrecedence": [ |
| 110 | + "AzureCLI", |
| 111 | + "AzurePowerShell" |
| 112 | + ] |
| 113 | + } |
| 114 | +} |
| 115 | +``` |
| 116 | + |
| 117 | +The available credentials are: |
| 118 | + |
| 119 | +* AzureCLI |
| 120 | +* AzurePowerShell |
| 121 | +* Environment |
| 122 | +* ManagedIdentity |
| 123 | +* VisualStudio |
| 124 | +* VisualStudioCode |
| 125 | + |
| 126 | +## Next steps |
| 127 | + |
| 128 | +* [Configure your Bicep environment](bicep-config.md) |
| 129 | +* [Add linter settings to Bicep config](bicep-config-linter.md) |
| 130 | +* Learn about [modules](modules.md) |
0 commit comments