Search code examples
azurevisual-studio-codeazure-bicep

Unable to decompile ARM template to bicep file using either PowerShell or CLI Command


Folder/Files Structure:

enter image description here

arm-storage-account.json

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "resources": [
      {
        "type": "Microsoft.Storage/storageAccounts",
        "apiVersion": "2022-09-01",
        "name": "testsa08",
        "location": "eastus",
        "sku": {
          "name": "Standard_LRS"
        },
        "kind": "StorageV2"
      }
    ]
  }

Variables.ps1:

$RG="bicepRG"
$subscription="<Subsricption_Id>"
$location="eastus"

For decompiling ARM to Bicep, below commands I have tried:

02-02 Authoring, Deploying.ps1:

Built-in command

az bicep decompile --file .\arm-storage-account.json

Stand-alone CLI:

bicep decompile .\arm-storage-account.json

Result:

**

WARNING: Decompilation is a best-effort process, as there is no guaranteed mapping from ARM JSON to Bicep.
You may need to fix warnings and errors in the generated bicep file(s), or decompilation may fail entirely if an accurate conversion is not possible.
If you would like to report any issues or inaccurate conversions, please see https://github.com/Azure/bicep/issues.

**

Error:

C:\Users\hasher\source\repos\arm-storage-account.json: Decompilation failed with fatal error "Failed to read file:///C:/Users/hasher/source/repos/arm-storage-account.json"

I know the result is same for every time of decompilation but last line came as error. How to resolve this issue?


Solution

  • The issue is the folder the command is attempting to run in.

    Failed to read file:///C:/Users/hasher/source/repos/arm-storage-account.json
    

    Your bicep file is in repos/bicep/arm-storage-account.json

    Can either run cd bicep before running your command or bicep decompile bicep\arm-storage-account.json