Skip to content

Commit

Permalink
Brief document on decompile command (#998)
Browse files Browse the repository at this point in the history
* Create decompiling.md

* Update decompiling.md

* Update README.md
  • Loading branch information
anthony-c-martin authored Nov 25, 2020
1 parent 7e07f45 commit 5c94339
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Once the tooling is installed, you can start the [bicep tutorial](./docs/tutoria

Alternatively, you can try the [Bicep Playground](https://aka.ms/bicepdemo).

If you have an existing ARM Template or set of resources that you would like to convert to `.bicep` format, see [Decompiling an ARM Template](./docs/decompiling.md).

## How does Bicep work?

First, author your Bicep code using the Bicep language service as part of the [Bicep VS Code extension](./docs/installing.md#bicep-vs-code-extension), then compile that code into an ARM template using the [Bicep CLI](./docs/installing.md#bicep-cli):
Expand Down
36 changes: 36 additions & 0 deletions docs/decompiling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Decompiling an ARM Template

> Requires Bicep CLI v0.2.59 or later
The Bicep CLI provides the ability to decompile any existing ARM Template to a `.bicep` file, using the `decompile` command:
```sh
bicep decompile "path/to/file.json"
```

You can use this command to get to a starting point for Bicep authoring. Note that because there is no guaranteed conversion from JSON to Bicep, decompilation may fail, or you may be left with errors/warnings in the generated Bicep file to fix up. See [Limitations](#limiations) for some details of what is not currently possible.

## Exporting a resource group
You can pass an exported template directly to the `bicep decompile` command to effectively export a resource group to a `.bicep` file.

### Azure CLI
The following will create a file named 'main.bicep' in the current directory:
```sh
az group export --name "your_resource_group_name" > main.json
bicep decompile main.json
```
### Azure PowerShell
The following will create a file named 'main.bicep' in the current directory:
```powershell
Export-AzResourceGroup -ResourceGroupName "your_resource_group_name" -Path ./main.json
bicep decompile main.json
```

### Azure Portal
See [Export Template](https://aka.ms/armexport) for guidance. Use `bicep decompile <filename>` on the downloaded file.


## Current Limitations
The following are temporary limiations on the `bicep decompile` command:
* Templates using copy loops or conditionals cannot be decompiled
* Nested templates cannot be decompiled
* Cross-scope linked templates cannot be decompiled

0 comments on commit 5c94339

Please sign in to comment.