Azure / Azure/bicep

Decompile strings with newlines to multi line strings

Open
#2,475 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

**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

```bicep
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

```bicep
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)

```json
{
"$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
}
}
]
}
}
}
]
}
```

Contributor guide

Open the contributing guide

Research direction

Start by locating the ARM-template decompiler path that handles string values, then inspect how escaped newline characters are represented in the generated Bicep. Use the sample scheduled query rule as the reproduction case; done means multiline strings are emitted for suitable values without changing their contents.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
cloud, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.