Commit 40c4c0f
fix: prevent invalid empty backend.tf.json generation (#1833)
* fix: prevent invalid empty backend.tf.json from being generated
- Add validation in generateComponentBackendConfig() to reject empty backend_type
- Add ErrBackendTypeRequired sentinel error for proper error handling
- Log warnings when skipping backend generation due to missing backend or backend_type
- Include auto_generate_backend_file setting hint in warning messages
- Add comprehensive tests to verify no backend files are generated when config is incomplete
- Tests validate both warning messages and file non-existence
This prevents the issue where an empty backend type would result in invalid Terraform config like `{"terraform": {"backend": {"": {}}}}`, which causes "Duplicate backend configuration" errors.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* test: improve test comment accuracy for backend_type warning path
Clarify that the YAML processor sets empty backend_type strings, so tests
hit the "empty after template processing" path rather than the "not configured" path.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* [autofix.ci] apply automated fixes
* refactor: extract backend validation into pure testable functions
- Add validateBackendConfig() pure function with 100% test coverage
- Add checkBackendTypeAfterProcessing() pure function with 100% test coverage
- Add comprehensive unit tests for all validation scenarios
- Refactor ExecuteTerraformGenerateBackends to use extracted functions
This improves testability by separating validation logic from side effects,
allowing direct unit testing of all validation paths without requiring
complex integration test setups.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* refactor: rename backendConfigValidationResult to backendValidation
Simplify the type name and remove verbose field comments.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* refactor: rename to backendConfig and extractBackendConfig
The struct holds the backend configuration, so backendConfig is clearer.
The function extracts config from the component section, so extractBackendConfig
better describes what it does.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* refactor: use error type instead of string for skip reasons
Replace SkipReason string with Err error field in backendConfig.
Add sentinel errors: ErrBackendSectionMissing, ErrBackendTypeMissing,
ErrBackendTypeEmptyAfterRender.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: reject empty backend config for remote backends
When backend_type is set to s3, gcs, azurerm, or cloud but the backend
section is empty, skip backend generation with a warning instead of
generating invalid Terraform configuration like {"terraform":{"backend":{"s3":{}}}}.
The local backend is still allowed to have empty configuration since
Terraform supports it without any required fields.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* docs: add blog post for empty backend config validation fix
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Andriy Knysh <aknysh@users.noreply.github.com>1 parent ed4c02b commit 40c4c0f
File tree
6 files changed
+520
-15
lines changed- errors
- internal/exec
- website/blog
6 files changed
+520
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
122 | 127 | | |
123 | 128 | | |
124 | 129 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
20 | 60 | | |
21 | 61 | | |
22 | 62 | | |
| |||
132 | 172 | | |
133 | 173 | | |
134 | 174 | | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
142 | 181 | | |
143 | 182 | | |
| 183 | + | |
| 184 | + | |
144 | 185 | | |
145 | 186 | | |
146 | 187 | | |
| |||
295 | 336 | | |
296 | 337 | | |
297 | 338 | | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
298 | 347 | | |
299 | 348 | | |
300 | 349 | | |
| |||
0 commit comments