Skip to content

Fix const variable interpolation in Terraform module sources - #2914

Merged
Andriy Knysh (aknysh) merged 9 commits into
cloudposse:mainfrom
gitbluf:main
Aug 13, 2026
Merged

Andriy Knysh (aknysh) merged 9 commits into
cloudposse:mainfrom
gitbluf:main

Conversation

@gitbluf

@gitbluf Marko Petrovic (gitbluf) commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

What

Updates terraform-config-inspect to support static (const = true) variable
interpolation in Terraform module.source values.

Adds regression coverage for:

  • Successfully describing a component with source = "./mods/${var.org}".
  • Preserving real HCL syntax failures when loading Terraform components.
  • Returning parsed Terraform configuration as *tfconfig.Module in the OpenTofu
    interpolation test.

Why

Atmos previously failed while parsing valid Terraform 1.15+
configurations that interpolate a static variable in module.source:

variable "org" {
  const   = true
  type    = string
  default = "myorg"
}

module "greeting" {
  source = "./mods/${var.org}"
}

The previous terraform-config-inspect version evaluated module.source without an HCL
evaluation context and returned Variables not allowed before Terraform or OpenTofu was
invoked.

Fixes: #2913

@atmos-pro

atmos-pro Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Tip

Atmos Pro  

No affected stacks workflow was detected for this pull request.
If this is expected, no action is needed.
Learn More. Ask AI.

@github-actions github-actions Bot added the size/m Medium size PR label Aug 10, 2026
@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds regression fixtures and execution tests for static const interpolation in local Terraform module sources. Updates configuration inspection compatibility, dependency license metadata, and fix documentation.

Changes

Const module source support

Layer / File(s) Summary
Interpolation regression fixtures
tests/fixtures/scenarios/const-module-source/...
Adds valid and malformed Terraform components, a local module, stack metadata, and Atmos configuration.
Execution and compatibility validation
go.mod, internal/exec/*module_source*_test.go, NOTICE, docs/fixes/...
Updates terraform-config-inspect, validates interpolated module loading and syntax errors, adjusts OpenTofu type assertions, updates the license reference, and records the fix.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • cloudposse/atmos#2783: Updates terraform-config-inspect and overlaps with module metadata type handling.
  • cloudposse/atmos#2915: Addresses const variable interpolation in module sources with related diagnostic handling and regression coverage.

Suggested reviewers: osterman

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the primary fix for const variable interpolation in Terraform module sources.
Linked Issues check ✅ Passed The dependency update, regression fixtures, and tests address the parsing failure and preserve syntax-error handling described in issue #2913.
Out of Scope Changes check ✅ Passed The documentation, dependency metadata, fixtures, and tests directly support the linked issue objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 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/const_module_source_test.go`:
- Around line 59-60: Add an assertion in the test around the existing
require.Error and assert.ErrorIs calls to verify the returned error includes the
malformed HCL block diagnostic text, following the assertion pattern used in
hcl_syntax_error_test.go. Keep the wrapper error assertion and ensure the test
still distinguishes genuine syntax errors.
🪄 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: 88fe6858-4bcb-418e-892b-2dd92c5dcb00

📥 Commits

Reviewing files that changed from the base of the PR and between 1107de3 and b99c642.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (9)
  • docs/fixes/2026-08-10-const-module-source-interpolation.md
  • go.mod
  • internal/exec/const_module_source_test.go
  • internal/exec/opentofu_module_source_interpolation_test.go
  • tests/fixtures/scenarios/const-module-source/atmos.yaml
  • tests/fixtures/scenarios/const-module-source/components/terraform/broken-variable/main.tf
  • tests/fixtures/scenarios/const-module-source/components/terraform/testme/main.tf
  • tests/fixtures/scenarios/const-module-source/components/terraform/testme/mods/acme/main.tf
  • tests/fixtures/scenarios/const-module-source/stacks/test-stack.yaml

coderabbitai[bot]
coderabbitai Bot previously approved these changes Aug 10, 2026
@codecov

codecov Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.97%. Comparing base (a25bfb5) to head (8ebd315).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2914      +/-   ##
==========================================
- Coverage   82.99%   82.97%   -0.02%     
==========================================
  Files        1881     1881              
  Lines      183067   183067              
==========================================
- Hits       151937   151906      -31     
- Misses      23308    23335      +27     
- Partials     7822     7826       +4     
Flag Coverage Δ
unittests 82.97% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 11 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

auto-merge was automatically disabled August 11, 2026 17:29

Head branch was pushed to by a user without write access

coderabbitai[bot]
coderabbitai Bot previously approved these changes Aug 11, 2026
auto-merge was automatically disabled August 12, 2026 21:12

Head branch was pushed to by a user without write access

@atmos-pro

atmos-pro Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Tip

Atmos Pro  

No affected stacks workflow was detected for this pull request.
If this is expected, no action is needed.
Learn More. Ask AI.

Merged via the queue into cloudposse:main with commit 6c44717 Aug 13, 2026
198 of 202 checks passed
@atmos-pro

atmos-pro Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Tip

Atmos Pro  

No affected stacks workflow was detected for this pull request.
If this is expected, no action is needed.
Learn More. Ask AI.

@github-actions

Copy link
Copy Markdown

These changes were released in v1.226.0-rc.7.

This branch was previously deployed

1 inactive deployment
screengrabs — 8ebd315c Deployed Aug 12, 2026 by gitbluf via build #1364
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch A minor, backward compatible change size/m Medium size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Atmos fails to load any Terraform component that uses variable interpolation

3 participants