Azure / Azure/bicep

Indentation functions needed for YAML or format() to be indent aware

Open
#3,656 3 comments 5 reactions 0 assignees View on GitHub
enhancement intermediate language new function
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 2h
Merged PRs (30d)
79

Description

**Is your feature request related to a problem? Please describe.**
When formatting multiline strings which are in YAML format, there is often a need to perform indentation, especially when dealing with cloud-init, e.g.

```bicep
var containerdScript = loadTextContent('containerd.sh')

var cloudConfig = '''
#cloud-config

write_files:
- content: |
${0}
path: /root/containerd.sh
owner: root:root
'''

// Use format function as Bicep doesn't yet support interpolation on multiline strings
output cloudInit string = format(cloudConfig, containerdScript)
```

That code will not work as only the first line of the script which is injected at ${0} will have the correct indentation, the rest of the lines will be placed at column zero, and that's invalid YAML

**Describe the solution you'd like**
Terraform has a function for this providing this
https://www.terraform.io/docs/language/functions/indent.html

And Helm has several indent functions to help with this
https://helm.sh/docs/chart_template_guide/function_list/#indent

Maybe an indent function could be added to Bicep? With a parameter to supply how many spaces to ident by e.g.
```bicep
var containerdScript = indent(loadTextContent('containerd.sh'), 4)
```

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the existing format() behavior and the multiline-string example in the issue, then compare the requested indent() semantics with Terraform and Helm's documented functions. Done means a Bicep function can apply the requested indentation to every line of substituted multiline text so the resulting cloud-init YAML remains valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
cloud, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.