Common YAML Indentation Traps
Avoiding the errors that break rendered output.
Common YAML Indentation Traps is a free Helm Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Helm Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Indentation Is Structure
In YAML, spaces are not decoration. Indentation alone decides what nests under what, so a single wrong space can reshape your whole manifest. 😬
Templates Make It Trickier
When an action injects a value or a block, that text lands at whatever column the action sits. Misjudge it and the rendered YAML breaks.
Never Use Tabs
YAML forbids tabs for indentation, full stop. A stray tab gives a confusing parse error, so configure your editor to insert spaces.
Inserting a Block
When you drop a multi-line value into the tree, it does not auto-align. You must add the right leading spaces with the indent function.
{{ .Values.config | indent 4 }}indent Counts Spaces
The number after indent is how many spaces to prepend to every line of the value. Match it to the depth where the block must sit.
The Newline Trap
A common bug: indent does not add a leading newline, so the first line glues onto your YAML key. This wrecks the document silently.
data:
{{ .Values.config | indent 2 }}nindent to the Rescue
Most charts use nindent instead. It adds a leading newline first, then indents, so the block starts cleanly on its own line.
data: {{ .Values.config | nindent 2 }}Mind the Action Column
The spaces in front of {{ in your source affect the line the action prints on. Keep control actions at the depth their output should occupy.
Lists Need a Dash
When a templated value becomes a list, each item needs a hyphen at the correct indent. toYaml plus nindent usually handles this for you cleanly.
env:
{{ toYaml .Values.env | nindent 2 }}Render and Read It
Indentation bugs are invisible in source but obvious in output. Render the chart and scan the raw YAML to spot misaligned blocks fast. 👀
helm template ./mychartLet lint Help
Run helm lint to catch many YAML and indentation problems before you ever try to install the chart on a cluster.
helm lint ./mychartQuick Check
Your injected block keeps gluing onto the YAML key above it.
Recap
You can now dodge the classic traps: no tabs, use nindent for clean blocks, and always render or lint to verify your YAML. 🎯
Frequently asked questions
Is the “Common YAML Indentation Traps” lesson free?
Yes — the full text of “Common YAML Indentation Traps” is free to read here on the web, and the Helm Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Helm Academy course, upgrade to CoddyKit PRO.
What will I learn in “Common YAML Indentation Traps”?
Avoiding the errors that break rendered output. You practise Helm Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Helm Academy?
No prior experience is required. Helm Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Common YAML Indentation Traps” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Helm Academy lesson?
Yes. Every Helm Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- The Double-Brace Action Syntax
- Trimming Whitespace with Dash Markers
- Comments and Quoting in Templates
- Common YAML Indentation Traps