Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARM Parameter file decompilation - fatal error #1603

Closed
lukeuhren opened this issue Feb 23, 2021 · 9 comments · Fixed by #1640
Closed

ARM Parameter file decompilation - fatal error #1603

lukeuhren opened this issue Feb 23, 2021 · 9 comments · Fixed by #1640
Labels
Needs: Author Feedback Awaiting feedback from the author of the issue

Comments

@lukeuhren
Copy link

lukeuhren commented Feb 23, 2021

Bicep version
Bicep CLI version 0.2.328 (a13b032)

Describe the bug

I use separate parameter files in all my json templates in the repo in devops. Running this from vscode.

This is simply an issue where I can't decompile a .json parameter file to .bicep. I can't see where if it's unsupported right now reading.

Example take a simple parameter file like

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "test": {
      "value": "test"
    },
    "test2": {
      "value": "test2"
    }
  }
}

try to decompile with .... bicep decompile .\param.json

errors out with ... "Decompilation failed with fatal error "[5:13]: Unable to locate 'type' for parameter 'test'"

Fails on the first parameter on all the files I have tried.

To Reproduce

  1. Create .json file like below as a test parameter file
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "test": {
      "value": "test"
    },
    "test2": {
      "value": "test2"
    }
  }
}
  1. run the following:
    bicep decompile filename

it will error out like so ... Decompilation failed with fatal error "[5:13]: Unable to locate 'type' for parameter 'test'"

Additional context
If it's in the works and not supported yet all good :)

@ghost ghost added the Needs: Triage 🔍 label Feb 23, 2021
@miqm
Copy link
Collaborator

miqm commented Feb 24, 2021

Bicep does not have own parameters values file to be used in deployments and therefore decompiler tries to interpret this file as it was a template file, hence the missing type.

Perhaps we could check the schema and warn/block decompilation, but that field is not required.

@alex-frankel
Copy link
Collaborator

The other thing I would add is once #858 is done, you will be able to pass the parameters json file with a .bicep file for your deployment. We also have #1278 which will let you link the parameters JSON file while authoring to get deeper validation.

@anthony-c-martin
Copy link
Member

One option is to tighten up the validation we do on the JSON $schema property, and simply fail decompilation with a better error message if it doesn't match one of the expected template root schemas (e.g. https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#, https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json# etc).

@lukeuhren
Copy link
Author

lukeuhren commented Mar 1, 2021

Thanks for the replies everyone. This clears it up for me as to why it doesn't work. Cheers!

@Siorhi
Copy link

Siorhi commented Apr 20, 2022

I am also facing same error , can you also please suggest the another approach can be taken for the parameter. json

@lukeuhren
Copy link
Author

lukeuhren commented Apr 20, 2022

Well, you can create a bicep param file if you want. I have... here is an example

//this would be C:\temp\biceptemplate-params.bicep
//C:\temp\biceptemplate.bicep would be a template for the resource
//you do need to set-location usually and then use ../ in the module location

//for example below
//../../biceptemplate.bicep

//keyvault params to associate keyvault if needed
param kvName string = 'name of keyvault'
param subscriptionId string = 'sub id where keyvault resides'
param kvResourceGroup string = 'resource group where it resides'

resource kv 'Microsoft.KeyVault/vaults@2019-09-01' existing = {
name: kvName
scope: resourceGroup(subscriptionId, kvResourceGroup)
}

//module for test
//module test is the location of the actual bicep template. This is feeding its parameters
module test '../../biceptemplate.bicep' = {
name: 'test'
params: {
user: 'testest'
diskPassword: kv.getSecret('StorageAccountKey')
}
}

@lukeuhren
Copy link
Author

lukeuhren commented Apr 20, 2022

Then you need to deploy it with something like...

New-AzResourceGroupDeployment -ResourceGroupName "RG" -TemplateFile 'C:\temp\biceptemplate-params.bicep' -Verbose

This will tie both together ....

if you don't have a coding background and this is not easy to understand I am sorry :(

I can try and help if needed

@lukeuhren
Copy link
Author

I deployed multiple infrastructures now in BICEP with those param files I mentioned. So I can try and help if needed. Maybe will give Microsoft some ideas.

@Siorhi
Copy link

Siorhi commented Apr 21, 2022

Thanks @lukeuhren I will try it update if you how it goes, then we surely give idea to the Microsoft :)

@ghost ghost locked as resolved and limited conversation to collaborators May 28, 2023
@StephenWeatherford StephenWeatherford added Needs: Author Feedback Awaiting feedback from the author of the issue and removed awaiting response labels Oct 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs: Author Feedback Awaiting feedback from the author of the issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants