feat: support Terraform override files in template preview#196
Merged
Conversation
Implement Terraform's override file semantics (override.tf, *_override.tf) by merging override blocks into primary files before evaluation. Related to: coder/coder#21991
Emyrk
reviewed
Mar 5, 2026
Override merging should not be stricter than Trivy, which accepts duplicate blocks without error. Additionally, replicating Terraform's duplicate detection correctly requires per-block-type semantics — complexity that isn't justified for something that's not our responsibility. Invalid duplicates will still be caught by `terraform plan`. 'terraform' block overrides are rare and the merging semantics are not straightforward, so we just skip them for now (with a warning).
Emyrk
approved these changes
Mar 23, 2026
Member
Emyrk
left a comment
There was a problem hiding this comment.
The fallback behavior if it fails is great 👍
Comment on lines
+62
to
+68
| if ext == ".tf.json" { | ||
| if isOverrideFile(d.Name()) { | ||
| warnings = warnings.Append(&hcl.Diagnostic{ | ||
| Severity: hcl.DiagWarning, | ||
| Summary: "Unmerged .tf.json override file", | ||
| Detail: fmt.Sprintf("Not merging override file %q that uses JSON format", p), | ||
| }) |
Comment on lines
+165
to
+166
| // Override merging is best-effort; downgrade all override error | ||
| // diagnostics to warnings so they never abort the preview. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements https://developer.hashicorp.com/terraform/language/files/override (override.tf, *_override.tf) by merging override content into primary .tf files before Trivy evaluation.
Block merging
localsblocks are merged at the individual attribute level across all primary files, matching Terraform's per-attribute semanticsterraformblocks in overrides are skipped with a warning - their override semantics are too nuanced to replicate correctlyvariable "x" {}) are handled correctly by forcing multi-line formatting before attribute insertionFilesystem layer
How it works
Related to: coder/coder#21991