# You write your bicep code this script generates the currently requierd json parameter file by transforming the bicep build output # Requiers bicep CLI # Tested with Bicep CLI version 0.4.1008 (223b8d227a) # Authored by: Asbjørn Wiik param ( [string]$File, [int]$jsonDepth = 50 ) $outParameterfile = $File.Replace('.bicep', '.json') # If running on the deployment bicep file add .parameters.json to outParameterfile if (-not ($outParameterfile -match "parameters.json")) { $outParameterfile = "$(($outParameterfile.Split('.json'))[0]).parameters.json" } # Traditional bicep build file bicep build $File --outfile $outParameterfile # Pickup the file and do a simple string substitution $outParameterfileContent = (Get-Content $outParameterfile -Raw ) -replace '"defaultValue"', '"value"' # Converting form json $outParameterfileContent = ConvertFrom-Json -Depth $jsonDepth $outParameterfileContent # Leave what we want $outParameterfileContent = $outParameterfileContent | Select-Object '$schema', contentVersion, parameters $outParameterfileContent.'$schema' = "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#" # Grabbing list of the parameter names $myparams = ($outParameterfileContent.parameters | Get-Member | Where-Object { $_.MemberType -match "NoteProperty" } | Select-Object Name).Name # Filtering out other crudd and adding missing value blocks foreach ($item in $myparams) { if ($null -eq ($outParameterfileContent.parameters.$item | Select-Object value).value ) { # If run on deployment bicep file there might not be a set a default value. Adding and replacing other stuff $outParameterfileContent.parameters.$item = [pscustomobject]@{'value' = 'missing value' } } else { # Filtering out all but the value $outParameterfileContent.parameters.$item = $outParameterfileContent.parameters.$item | Select-Object value } } # Converting outParameterfileContent to json and writing parameter file $outParameterfileContent | ConvertTo-Json -Depth $jsonDepth | Set-Content $outParameterfile