Skip to content

Commit 2473335

Browse files
committed
fix: prevent Prettier from formatting Tera templates
- Add .prettierignore to exclude *.tera files from Prettier formatting - Update docs/contributing/templates.md with troubleshooting section - Document VS Code Prettier issue with Tera variable syntax - Provide solution to prevent { { variable } } formatting issue
1 parent 5325eb5 commit 2473335

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ignore Tera template files - they have specific syntax that Prettier doesn't understand
2+
*.tera

docs/contributing/templates.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,34 @@ instance_name = "{{ instance_name }}"
6161
2. No spaces between braces and variable name: `{{variable}}` not `{ { variable } }`
6262
3. Variable names are case-sensitive
6363
4. Works in any file format (YAML, HCL, etc.)
64+
65+
## 🔧 Troubleshooting
66+
67+
### VS Code Prettier Extension Adding Spaces in Variables
68+
69+
**Problem**: When using VS Code with the Prettier extension, saving `.tera` files automatically adds unwanted spaces inside Tera variables:
70+
71+
- **Before saving**: `{{ username }}`
72+
- **After saving**: `{ { username } }`
73+
74+
**Cause**: Prettier doesn't understand Tera template syntax and tries to format `.tera` files incorrectly.
75+
76+
**Solution**: Create a `.prettierignore` file in your project root to exclude Tera template files:
77+
78+
```gitignore
79+
# Ignore Tera template files - they have specific syntax that Prettier doesn't understand
80+
*.tera
81+
```
82+
83+
**Alternative Solution**: Disable formatting for `.tera` files in your VS Code settings:
84+
85+
```json
86+
{
87+
"[tera]": {
88+
"editor.formatOnSave": false,
89+
"editor.defaultFormatter": null
90+
}
91+
}
92+
```
93+
94+
After applying the fix, manually correct any existing formatting issues in your `.tera` files by removing the spaces inside the curly braces.

0 commit comments

Comments
 (0)