Decompile strings with newlines to multi line strings
Is your feature request related to a problem? Please describe.
Consider a microsoft.insights/scheduledqueryrules ARM template that contains an application insights queries. These queries can get pretty long and are often on multiple lines. Json doesn't have a good way of expressing multi line strings, so this has to be expressed as a single line string with escaped new line characters.
Describe the solution you'd like Bicep doesn't have JSON's limitations of being unable to cleanly represent multi line strings. It would be nice if bicep could detect these strings, and decompile them as multi line strings.
For example, rather than decompiling to
query: 'requests\r\n | summarize status500 = countif(resultCode == 500), total = count() by operation_Name\r\n | project operation_Name, total, status500, percent500 = todecimal(status500) / todecimal(total) * 100\r\n | where total > 10 and status500 > 10 and percent500 > 25'
instead decompile to
query: '''
requests
| summarize status500 = countif(resultCode == 500), total = count() by operation_Name
| project operation_Name, total, status500, percent500 = todecimal(status500) / todecimal(total) * 100
| where total > 10 and status500 > 10 and percent500 > 25
'''
Here's a sample exported resource exported from the portal. (A few tings trimmed out to keep the sample small)
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"type": "microsoft.insights/scheduledqueryrules",
"apiVersion": "2020-05-01-preview",
"name": "Foo",
"location": "northeurope",
"properties": {
"criteria": {
"allOf": [
{
"query": "requests\r\n | summarize status500 = countif(resultCode == 500), total = count() by operation_Name\r\n | project operation_Name, total, status500, percent500 = todecimal(status500) / todecimal(total) * 100\r\n | where total > 10 and status500 > 10 and percent500 > 25",
"timeAggregation": "Count",
"operator": "GreaterThan",
"threshold": 0,
"failingPeriods": {
"numberOfEvaluationPeriods": 1,
"minFailingPeriodsToAlert": 1
}
}
]
}
}
}
]
}
That's a great suggestion!
Thanks for your patience — this was recently picked up as an outstanding open issue for the Bicep team to review.
Still a great suggestion (as @majastrz said back in April 2021). I ran your sample through bicep decompile on 0.43.8 and the query still comes out as a single-line string with escaped newlines rather than a multi-line string:
query: 'requests\r\n | summarize status500 = countif(resultCode == 500), total = count() by operation_Name\r\n | ...'
So this isn't implemented yet. One nuance worth flagging for whoever picks it up: Bicep's ''' multi-line strings are verbatim and use whatever line endings are in the file, so they can't faithfully round-trip an explicit \r (CRLF) — for \n-only content it's clean, but CRLF source like this one needs a decision on fidelity. That's likely part of why it hasn't been a quick win.
I'll leave this open as a tracked decompiler enhancement. Feel free to reopen if you'd like to add more scenarios.