fix(terraform): support Terraform 1.15+ module source interpolation - #2915
fix(terraform): support Terraform 1.15+ module source interpolation#2915Erik Osterman (Cloud Posse) (osterman) wants to merge 6 commits into
Conversation
…enTofu Atmos's terraform-config-inspect-based component validation already tolerated the "Variables not allowed" HCL diagnostic produced by a module's `source` attribute referencing a variable, but only when the configured command was detected as OpenTofu. Since Terraform 1.15 added the equivalent capability via `const = true` variables, plain Terraform users hit the same diagnostic as a hard failure. Decouple the skip from tool detection so it applies regardless of terraform vs tofu, since the diagnostic is a static-parser limitation rather than an OpenTofu-specific feature gate. Closes #2913 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Bump the pnpm override for the nanoid@3.3.3 resolution range from ^3.3.15 to ^3.3.17, resolving the transitive website/pnpm-lock.yaml dependency to nanoid@3.3.18 and picking up the fix for GHSA-2v37-7h3g-55p8 (CVE-2026-67213), an infinite loop in customAlphabet/customRandom when size is 0. The other two open Dependabot alerts on image-size (#275, #276) have no first_patched_version published upstream yet, so they are not auto-fixable at this time. Also fixes pre-existing EditorConfig violations (tabs instead of the required 2-space indent, and a mis-sized list-continuation indent) in docs/prd/opentofu-module-source-interpolation.md, surfaced by the atmos-validate-editorconfig pre-commit hook once that file entered this branch's diff against origin/main. Whitespace-only, no content altered. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…nown module-source diagnostic terraform-config-inspect's Diagnostics.Error() only renders the first diagnostic's text, collapsing any others to "(and N other messages)". The previous fix pattern-matched that collapsed string, so a genuine, unrelated HCL error co-occurring in the same module -- sorting after the known-safe "Variables not allowed" diagnostic -- was silently discarded instead of failing. Inspect every error-severity diagnostic individually and group them by source position (allDiagnosticsAreModuleSourceInterpolation), since terraform-config-inspect emits a companion "Unsuitable value" diagnostic at the same position as the module-source one as a side effect of the same nil-hcl.EvalContext decode failure. A position's group is known-safe if any diagnostic in it matches; diagnostics at other positions must independently match, so a real error is never absorbed into the known-safe group just by sharing the diagnostics list. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe change generalizes Terraform and OpenTofu module-source interpolation handling. It evaluates diagnostics by source position, preserves unrelated errors, adds Terraform and SBOM regression coverage, updates documentation, and changes the website nanoid override. ChangesModule source diagnostic handling
Website dependency update
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related issues
Possibly related PRs
Sequence Diagram(s)sequenceDiagram
participant TerraformConfigInspect
participant TerraformDetection
participant ProcessStacks
TerraformConfigInspect->>TerraformDetection: Return configuration diagnostics
TerraformDetection->>TerraformDetection: Group errors by source position
TerraformDetection->>ProcessStacks: Allow skip only for known interpolation groups
ProcessStacks->>ProcessStacks: Record skipped-validation metadata
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Dependency Review✅ No vulnerabilities or license issues found.Scanned FilesNone |
Durable fix-log entry for b44359d per this repo's bug-fixing convention, including validation performed and the known, intentionally-untracked follow-up (module.source/version scoping). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/exec/opentofu_module_source_interpolation_test.go`:
- Around line 115-118: Update the validation marker assertion in the
module-source interpolation test to require that componentInfo contains
validation_skipped_module_source_interpolation, then verify its value is true.
Remove the conditional existence guard so the test fails when the marker is
absent.
In `@internal/exec/terraform_detection.go`:
- Around line 142-144: Update matchesModuleSourceInterpolationPattern to
re-parse the affected Terraform file and suppress only diagnostics whose ranges
fall within a module block’s source or version attribute; do not treat generic
“Variables not allowed” text as sufficient. Add a regression case proving an
invalid non-module attribute such as output.description remains rejected.
In `@pkg/sbom/terraform_test.go`:
- Around line 191-206: Remove t.Parallel() from this test because it replaces
the package-global runTerraformModules hook. Keep the test serialized with
TestAppendTerraformMarksModulesIncompleteWhenLocalModuleUnresolvable and
preserve the existing setup and cleanup.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 70c50828-57fe-4185-983f-8137445679e6
⛔ Files ignored due to path filters (1)
website/pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (19)
docs/fixes/2026-08-10-module-source-interpolation-diagnostic-swallow.mddocs/fixes/2026-08-10-terraform-module-source-interpolation.mddocs/prd/opentofu-module-source-interpolation.mdinternal/exec/opentofu_module_source_interpolation_test.gointernal/exec/terraform_detection.gointernal/exec/terraform_detection_test.gointernal/exec/terraform_module_source_interpolation_test.gointernal/exec/utils.gopkg/sbom/terraform_test.gotests/fixtures/scenarios/terraform-module-source-interpolation-mixed-diagnostics/atmos.yamltests/fixtures/scenarios/terraform-module-source-interpolation-mixed-diagnostics/components/terraform/test-component/main.tftests/fixtures/scenarios/terraform-module-source-interpolation-mixed-diagnostics/components/terraform/test-component/mods/acme/main.tftests/fixtures/scenarios/terraform-module-source-interpolation-mixed-diagnostics/stacks/test-stack.yamltests/fixtures/scenarios/terraform-module-source-interpolation/README.mdtests/fixtures/scenarios/terraform-module-source-interpolation/atmos.yamltests/fixtures/scenarios/terraform-module-source-interpolation/components/terraform/test-component/main.tftests/fixtures/scenarios/terraform-module-source-interpolation/components/terraform/test-component/mods/acme/main.tftests/fixtures/scenarios/terraform-module-source-interpolation/stacks/test-stack.yamlwebsite/package.json
- opentofu_module_source_interpolation_test.go: require the validation_skipped_module_source_interpolation key to be present instead of silently passing when it's absent. - pkg/sbom/terraform_test.go: drop t.Parallel() from TestAppendModulesForDirectoryRecordsResolvedDynamicModuleSource -- it mutates the package-global runTerraformModules hook, same as TestAppendTerraformMarksModulesIncompleteWhenLocalModuleUnresolvable, risking a race between the two. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
# Conflicts: # website/pnpm-lock.yaml
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2915 +/- ##
==========================================
- Coverage 82.79% 82.77% -0.02%
==========================================
Files 1866 1866
Lines 181025 181045 +20
==========================================
- Hits 149882 149864 -18
- Misses 23331 23362 +31
- Partials 7812 7819 +7
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
what
moduleblock uses variable interpolation insource(e.g.source = "./mods/${var.org}") when the variable is declaredconst = true— valid syntax under Terraform 1.15+, not just OpenTofu 1.8+.internal/exec/utils.go/internal/exec/terraform_detection.goso it no longer depends on detecting OpenTofu — renamedisKnownOpenTofuFeature→isKnownModuleSourceInterpolationDiagnostic, and thecomponent_infoflagvalidation_skipped_opentofu→validation_skipped_module_source_interpolation.allDiagnosticsAreModuleSourceInterpolation), instead of pattern-matching the collapsedDiagnostics.Error()string, which only renders the first diagnostic's text.terraform(nocommand:override), plus a fixture/test proving a real unrelated error is still surfaced when it co-occurs with the known-safe diagnostic.terraform modules -json, never the static parser), and added a permanent guard test (pkg/sbom/terraform_test.go) for that invariant.nanoidpnpm override inwebsite/package.jsonto resolve the transitivewebsite/pnpm-lock.yamldependency tonanoid@3.3.18, fixing an open Dependabot alert (infinite loop on zero-size input). The two openimage-sizealerts have no upstream patch yet and are not auto-fixable.docs/prd/opentofu-module-source-interpolation.md, surfaced once that file entered the branch's diff.why
terraform-config-inspectbefore running any Terraform/OpenTofu command. That library decodes a module'ssourceattribute with anilhcl.EvalContext, so any variable reference there always produces the "Variables not allowed" diagnostic — regardless of whether the configured tool/version actually supports it.const = truevariables, so plain-Terraform users hit the same diagnostic as a hard failure even though their syntax is valid.references
docs/prd/opentofu-module-source-interpolation.md(updated with a 2026-08-10 addendum)docs/fixes/2026-08-10-terraform-module-source-interpolation.mdSummary by CodeRabbit
Bug Fixes
Documentation