You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Learn about the commands that you can use in the Bicep CLI. These commands include building JSON Azure Resource Manager templates from Bicep.
@@ -16,14 +16,14 @@ This guidance shows how to run the commands in the Azure CLI. When running comma
16
16
17
17
The `build` command converts a Bicep file to a JSON Azure Resource Manager template (ARM template). Typically, you don't need to run this command because it runs automatically when you deploy a Bicep file. Run it manually when you want to see the JSON ARM template that's created from your Bicep file.
18
18
19
-
Using any of following Bicep features automatically enables language version 2.0 code generation:
19
+
Using any of the following Bicep features automatically enables language version 2.0 code generation:
The following example converts a Bicep file named _main.bicep_ to an ARM template named _main.json_. The new file is created in the same directory as the Bicep file:
26
+
The following example converts a Bicep file named *main.bicep* to an ARM template named *main.json*. The new file is created in the same directory as the Bicep file:
27
27
28
28
# [Bicep CLI](#tab/bicep-cli)
29
29
@@ -39,7 +39,7 @@ az bicep build --file main.bicep
39
39
40
40
---
41
41
42
-
The next example saves _main.json_ to a different directory:
42
+
The next example saves *main.json* to a different directory:
The next example specifies the name and location of the file to be created:
58
+
The following example specifies the name and location of the file to create:
59
59
60
60
# [Bicep CLI](#tab/bicep-cli)
61
61
@@ -92,7 +92,7 @@ If your Bicep file includes a module that references an external registry, the `
92
92
> [!NOTE]
93
93
> The `restore` command doesn't refresh the cache. For more information, see [restore](#restore).
94
94
95
-
To not call restore automatically, use the `--no-restore` switch:
95
+
To prevent automatic restore, use the `--no-restore` switch:
96
96
97
97
# [Bicep CLI](#tab/bicep-cli)
98
98
@@ -156,7 +156,7 @@ az bicep decompile --file main.json
156
156
157
157
---
158
158
159
-
This command creates a file named _main.bicep_ in the same directory as _main.json_. If _main.bicep_ exists in the same directory, use the **--force** switch to overwrite the existing Bicep file.
159
+
This command creates a file named _main.bicep_ in the same directory as _main.json_. If _main.bicep_ exists in the same directory, use the `--force` switch to overwrite the existing Bicep file.
160
160
161
161
For more information about using this command, see [Decompile JSON ARM template to Bicep](decompile.md).
This command decompiles an _azuredeploy.parameters.json_ parameters file into an _azuredeploy.parameters.bicepparam_ file. `--bicep-file`specifies the path to the Bicep file (relative to the `.bicepparam` file) that's referenced in the `using` declaration.
181
+
This command decompiles an _azuredeploy.parameters.json_ parameters file into an _azuredeploy.parameters.bicepparam_ file. Use `--bicep-file`to specify the path to the Bicep file (relative to the `.bicepparam` file) that's referenced in the `using` declaration.
182
182
183
183
## format
184
184
185
-
The `format` command formats a Bicep file so that it follows the recommended style conventions. Think of it like a "code formatter" or "prettier" for your Bicep files. It has the same function as the `SHIFT+ALT+F` shortcut in Visual Studio Code.
185
+
The `format` command formats a Bicep file so that it follows the recommended style conventions. Think of it as a code formatter or "prettier" for your Bicep files. It has the same function as the `SHIFT+ALT+F` shortcut in Visual Studio Code.
186
186
187
187
# [Bicep CLI](#tab/bicep-cli)
188
188
@@ -200,7 +200,7 @@ az bicep format --file main.bicep
200
200
201
201
## generate-params
202
202
203
-
The `generate-params` command builds a parameters file from the given Bicep file, updates if there's an existing parameters file.
203
+
The `generate-params` command builds a parameters file from the given Bicep file and updates it if there's an existing parameters file.
204
204
205
205
# [Bicep CLI](#tab/bicep-cli)
206
206
@@ -252,7 +252,7 @@ az bicep install
252
252
253
253
---
254
254
255
-
To install a specific version:
255
+
To install a specific version, use the following command:
256
256
257
257
# [Bicep CLI](#tab/bicep-cli)
258
258
@@ -268,9 +268,9 @@ az bicep install --version v0.37.4
268
268
269
269
## jsonrpc
270
270
271
-
The `jsonrpc` command enables running the Bicep CLI with a JSON-RPC interface, allowing for programmatic interaction with structured output and avoiding cold-start delays when compiling multiple files. This setup also supports building libraries to interact with Bicep files programmatically in non-.NET languages.
271
+
The `jsonrpc` command runs the Bicep CLI with a JSON-RPC interface. By using this interface, you can interact programmatically with structured output. You also avoid cold-start delays when compiling multiple files. This setup supports building libraries to interact with Bicep files programmatically in non-.NET languages.
272
272
273
-
The wire format for sending and receiving input/output is header-delimited, using the following structure, where `\r` and `\n` represent carriage return and line feed characters:
273
+
The wire format for sending and receiving input and output is header-delimited. It uses the following structure, where `\r` and `\n` represent carriage return and line feed characters:
274
274
275
275
```
276
276
Content-Length: <length>\r\n\r\n<message>\r\n\r\n
@@ -347,8 +347,8 @@ The following methods are available through the JSON-RPC interface:
347
347
}
348
348
```
349
349
350
-
For the available methods & request/response bodies, see [`ICliJsonRpcProtocol.cs`](https://github.com/Azure/bicep/blob/main/src/Bicep.Cli/Rpc/ICliJsonRpcProtocol.cs).
351
-
For an example establishing a JSONRPC connection and interacting with Bicep files programmatically using Node, see [`jsonrpc.test.ts`](https://github.com/Azure/bicep/blob/main/src/Bicep.Cli.E2eTests/src/local/jsonrpc.test.ts).
350
+
For the available methods and request and response bodies, see [`ICliJsonRpcProtocol.cs`](https://github.com/Azure/bicep/blob/main/src/Bicep.Cli/Rpc/ICliJsonRpcProtocol.cs).
351
+
For an example establishing a JSONRPC connection and interacting with Bicep files programmatically by using Node, see [`jsonrpc.test.ts`](https://github.com/Azure/bicep/blob/main/src/Bicep.Cli.E2eTests/src/local/jsonrpc.test.ts).
352
352
353
353
### Usage for named pipe
354
354
@@ -368,7 +368,7 @@ N/A
368
368
369
369
---
370
370
371
-
To connect to a named pipe on OSX/Linux:
371
+
To connect to a named pipe on macOS or Linux:
372
372
373
373
# [Bicep CLI](#tab/bicep-cli)
374
374
@@ -432,7 +432,7 @@ N/A
432
432
433
433
### Usage for stdin and stdout
434
434
435
-
Use the following syntax and`stdin` and `stdout` for messages to run the JSONRPC interface:
435
+
To run the JSONRPC interface, use the following syntax. Use`stdin` and `stdout` for messages:
436
436
437
437
# [Bicep CLI](#tab/bicep-cli)
438
438
@@ -469,7 +469,7 @@ If your Bicep file includes a module that references an external registry, the `
469
469
> [!NOTE]
470
470
> The `restore` command doesn't refresh the cache. For more information, see [restore](#restore).
471
471
472
-
To not call restore automatically, use the `--no-restore` switch:
472
+
To prevent automatic restore, use the `--no-restore` switch:
473
473
474
474
# [Bicep CLI](#tab/bicep-cli)
475
475
@@ -548,7 +548,7 @@ The command returns an array of available versions:
548
548
549
549
## publish
550
550
551
-
The `publish` command adds a module to a registry. The Azure container registry must exist and the account publishing to the registry must have the correct permissions. For more information about setting up a module registry, see [Use private registry for Bicep modules](private-module-registry.md). To publish a module, the account must have the correct profile and permissions to access the registry. You can configure the profile and credential precedence for authenticating to the registry in the [Bicep config file](./bicep-config-modules.md#configure-profiles-and-credentials).
551
+
The `publish` command adds a module to a registry. The Azure container registry must exist, and the account publishing to the registry must have the correct permissions. For more information about setting up a module registry, see [Use private registry for Bicep modules](private-module-registry.md). To publish a module, the account must have the correct profile and permissions to access the registry. You can configure the profile and credential precedence for authenticating to the registry in the [Bicep config file](./bicep-config-modules.md#configure-profiles-and-credentials).
552
552
553
553
After publishing the file to the registry, you can [reference it in a module](modules.md#file-in-registry).
The `publish` command doesn't recognize aliases specified in a [_bicepconfig.json_ file](bicep-config-modules.md). Provide the full module path.
591
591
592
592
> [!WARNING]
593
-
> Publishing to the same target overwrites the old module. We recommend that you increment the version when updating.
593
+
> Publishing to the same target overwrites the old module. Increment the version when updating.
594
594
595
595
## restore
596
596
597
-
When your Bicep file uses modules that are published to a registry, the `restore` command gets copies of all the required modules from the registry. It stores those copies in a local cache. A Bicep file can only be built when the external files are available in the local cache. Normally, running restore isn't necessary as it's automatically triggered by the build process.
597
+
When your Bicep file uses modules that you publish to a registry, the `restore` command gets copies of all the required modules from the registry. It stores those copies in a local cache. A Bicep file can only be built when the external files are available in the local cache. Normally, running restore isn't necessary as it's automatically triggered by the build process.
598
598
599
599
To restore external modules to the local cache, the account must have the correct profile and permissions to access the registry. You can configure the [profile and credential precedence](./bicep-config-modules.md#configure-profiles-and-credentials) for authenticating to the registry in the Bicep config file.
600
600
@@ -616,7 +616,7 @@ az bicep restore --file <bicep-file> [--force]
616
616
617
617
---
618
618
619
-
The Bicep file you provide is the file you wish to deploy. It must contain a module that links to a registry. For example, you can restore the following file:
619
+
The Bicep file you provide is the file you want to deploy. It must contain a module that links to a registry. For example, you can restore the following file:
@@ -649,6 +649,123 @@ The local cache is found in:
649
649
650
650
The `restore` command doesn't refresh the cache if a module is already cached. To refresh the cache, you can either delete the module path from the cache or use the `--force` switch with the `restore` command.
651
651
652
+
## snapshot
653
+
654
+
By using Bicep CLI v0.41.2 or newer, you can use the `snapshot` command to create a normalized, deterministic representation of a Bicep deployment from a `.bicepparam` file. You can compare this snapshot with later snapshots to understand what changes a refactor would cause, without deploying anything to Azure. This command is particularly useful for:
655
+
656
+
* **Visual Diffs**: Seeing exactly how a refactor (like moving code into a module) changes the underlying resource definitions.
657
+
* **Complex Expressions**: Understanding what a complex string or variable actually evaluates to before deployment.
658
+
* **CI/CD Validation**: Automatically catching unintended changes in infrastructure logic during pull requests.
659
+
660
+
### Create a snapshot
661
+
662
+
This command generates a `.snapshot.json` file. This file is "normalized," meaning it removes noise like module boundaries so you can focus on the resources themselves.
After creating a snapshot, run the command in validate mode. It compares your current Bicep code against the saved snapshot and shows a visual diff, much like the [what-if](./deploy-what-if.md) command but entirely local.
700
+
701
+
#### [Bicep CLI](#tab/bicep-cli)
702
+
703
+
```bicepcli
704
+
bicep snapshot --mode validate <bicep-param-file>
705
+
```
706
+
707
+
#### [Azure CLI](#tab/azure-cli)
708
+
709
+
`az bicep snapshot` doesn't exist. You must run `bicep snapshot` directly.
|**Comparison**| Compares code vs. a saved file | Compares code vs. live Azure state |
734
+
|**Speed**| Extremely fast | Slower (requires API calls) |
735
+
|**Use Case**| Refactoring and logic testing | Final pre-deployment check |
736
+
737
+
### Provide context
738
+
739
+
When running bicep snapshot, the CLI performs a local evaluation of your code. Since it doesn't talk to Azure, it cannot "ask" the cloud for your Subscription ID or the current Resource Group name.
740
+
741
+
If your code uses environment functions (like `subscription().id`), the snapshot will fail or return placeholders unless you provide specific context via CLI arguments.
742
+
743
+
To simulate a real deployment environment, you can pass the following flags:
744
+
745
+
| Argument | Purpose | Example Value |
746
+
| :--- | :--- | :--- |
747
+
|`--subscription-id`| Replaces the value returned by `subscription().subscriptionId`|`00000000-1111-2222-3333-444444444444`|
748
+
|`--resource-group`| Replaces the value returned by `resourceGroup().name`|`my-production-rg`|
749
+
|`--location`| Sets the default location for `deployment().location`|`westeurope`|
750
+
|`--tenant-id`| Replaces the value returned by `tenant().tenantId`|`72f988bf-86f1-41af-91ab-2d7cd011db47`|
751
+
|`--management-group`| Replaces the value returned by `managementGroup().name`|`my-corp-mg`|
Before deploying a Bicep file, you can preview the changes that will happen. Azure Resource Manager provides the what-if operation to let you see how resources will change if you deploy the Bicep file. The what-if operation doesn't make any changes to existing resources. Instead, it predicts the changes if the specified Bicep file is deployed.
17
17
18
+
Similar to what-if, the [`bicep snapshot`](./bicep-cli.md#snapshot) command performs local-only testing by generating and comparing a normalized JSON representation of your infrastructure to catch unintended logic changes without requiring an Azure connection. For a comparison, see [Comparison snapshot vs what-if](./bicep-cli.md#validate-changes).
19
+
18
20
You can use the what-if operation with [Visual Studio Code](./deploy-visual-studio-code.md#deployment-pane), Azure PowerShell, Azure CLI, or REST API operations. What-if is supported for resource group, subscription, management group, and tenant level deployments.
19
21
20
22
During What-If operations, the evaluation and expansion of `templateLink` aren't supported. As a result, any resources deployed using template links within nested deployments, including template spec references, won't be visible in the What-If operation results.
@@ -125,7 +127,7 @@ For REST API, use:
125
127
126
128
You can use the what-if operation through the Azure SDKs.
127
129
128
-
- For Python, use [what-if](/python/api/azure-mgmt-resource/azure.mgmt.resource.resources.v2019_10_01.operations.deploymentsoperations#what-if-resource-group-name--deployment-name--properties--location-none--custom-headers-none--raw-false--polling-true----operation-config-).
130
+
- For Python, use [what-if](/python/api/azure-mgmt-resource-deployments/azure.mgmt.resource.deployments.models.whatifchange).
129
131
- For Java, use [DeploymentWhatIf Class](/java/api/com.azure.resourcemanager.resources.models.deploymentwhatif).
130
132
- For .NET, use [DeploymentWhatIf Class](/dotnet/api/microsoft.azure.management.resourcemanager.models.deploymentwhatif).
0 commit comments