Skip to content

fix: resolve stack context for locals enabling !terraform.state and other YAML functions#2207

Merged
aknysh merged 9 commits intomainfrom
aknysh/improve-locals-5
Mar 16, 2026
Merged

fix: resolve stack context for locals enabling !terraform.state and other YAML functions#2207
aknysh merged 9 commits intomainfrom
aknysh/improve-locals-5

Conversation

@aknysh
Copy link
Copy Markdown
Member

@aknysh aknysh commented Mar 16, 2026

what

  • Bug fix: !terraform.state (2-arg form) in locals now correctly derives the stack name from the file path, fixing the "stack is required" error reported in !terraform.state in catalog file locals fails with "stack is required" error #2080
  • New unit tests: 7 new unit tests in stack_processor_utils_test.go covering computeStackFileName, deriveStackNameForLocals, !env + Go template conditionals, and !terraform.state mock-based tests (2-arg and 3-arg forms)
  • New integration tests: 3 new CLI integration tests in cli_locals_test.go for Go template conditionals with !env (set/empty) and the worker component example
  • New test fixture: tests/fixtures/scenarios/locals-conditional/ with isolated stack files and unique env var names to avoid stack cache interference
  • Updated example: examples/locals/ updated to showcase all locals features concisely — basic locals, dependency resolution, settings/vars access, Sprig pipe functions, complex maps, and multiple components (myapp + myapp-worker)
  • Updated docs: website/docs/stacks/locals.mdx rewritten with processing pipeline details, cross-component references (!terraform.state 2-arg and 3-arg forms), environment variable conditionals (!env + Go template if), Gomplate/Atmos template function support, and updated best practices
  • Fix documentation: comprehensive fix doc at docs/fixes/2026-03-15-locals-terraform-state-missing-stack-context.md with root cause analysis, architecture details, and test results

why

  • Root cause: extractLocalsFromRawYAML() in stack_processor_utils.go passed "" as currentStack to ProcessStackLocals. The 2-arg form of !terraform.state (e.g., !terraform.state vpc .vpc_id) uses currentStack as the stack name, so it failed with "stack is required" when used inside locals
  • Fix: Added deriveStackNameForLocals() and computeStackFileName() functions that derive the stack name from the file path using the same logic as describe locals, making the 2-arg form work correctly in locals
  • The example and documentation were outdated and didn't cover the full feature set of locals (YAML functions, conditionals, cross-component references)

references

Summary by CodeRabbit

  • Bug Fixes

    • Fixed 2-argument !terraform.state in file-scoped locals so stack-aware lookups resolve correctly.
  • Documentation

    • Major locals doc overhaul: processing pipeline, YAML functions, dependency ordering, and clearer examples for conditionals.
  • New Features / Examples

    • Expanded examples: worker component, new vars/outputs, Sprig and Gomplate usage, and environment-driven conditional flows.
  • Tests

    • Added fixtures and extensive unit/integration tests covering locals, stack derivation, and template conditionals.
  • Chores

    • Bumped many dependencies, updated license references, and updated example tooling version.

aknysh and others added 5 commits March 15, 2026 15:32
The 2-arg form of !terraform.state in locals failed with "stack is
required" because extractLocalsFromRawYAML passed an empty string as
the current stack. Add deriveStackNameForLocals() and
computeStackFileName() to derive the stack name from the file path,
vars, and atmos config before processing locals.

Includes unit tests with mock StateGetter, integration tests for Go
template conditionals with !env, a new locals-conditional fixture,
and comprehensive architecture documentation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add Sprig functions (pipe upper), multiple components (myapp-worker
with suffixed full_name), and file-scoped isolation commentary.
Update README with feature sections and try-it commands.
Add TestExampleLocalsWorkerComponent test.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…n details

Add comprehensive documentation for locals processing pipeline, cross-component
references with !terraform.state, environment variable conditionals with !env,
and updated best practices.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@aknysh aknysh requested a review from a team as a code owner March 16, 2026 04:10
@aknysh aknysh added the patch A minor, backward compatible change label Mar 16, 2026
@aknysh aknysh requested a review from a team as a code owner March 16, 2026 04:10
@aknysh aknysh added the patch A minor, backward compatible change label Mar 16, 2026
@aknysh aknysh self-assigned this Mar 16, 2026
@github-actions github-actions bot added the size/l Large size PR label Mar 16, 2026
@mergify
Copy link
Copy Markdown

mergify bot commented Mar 16, 2026

Important

Cloud Posse Engineering Team Review Required

This pull request modifies files that require Cloud Posse's review. Please be patient, and a core maintainer will review your changes.

To expedite this process, reach out to us on Slack in the #pr-reviews channel.

@mergify mergify bot added the needs-cloudposse Needs Cloud Posse assistance label Mar 16, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 16, 2026

Dependency Review

The following issues were found:
  • ✅ 0 vulnerable package(s)
  • ✅ 0 package(s) with incompatible licenses
  • ✅ 0 package(s) with invalid SPDX license definitions
  • ⚠️ 39 package(s) with unknown licenses.
See the Details below.

License Issues

go.mod

PackageVersionLicenseIssue Type
cuelang.org/go0.16.0NullUnknown License
github.com/AzureAD/microsoft-authentication-library-for-go1.7.0NullUnknown License
github.com/CycloneDX/cyclonedx-go0.10.0NullUnknown License
github.com/ProtonMail/go-crypto1.4.0NullUnknown License
github.com/PuerkitoBio/goquery1.12.0NullUnknown License
github.com/andybalholm/brotli1.2.0NullUnknown License
github.com/aws/aws-sdk-go-v21.41.4NullUnknown License
github.com/aws/aws-sdk-go-v2/credentials1.19.12NullUnknown License
github.com/aws/aws-sdk-go-v2/service/s31.97.1NullUnknown License
github.com/aws/aws-sdk-go-v2/service/ssooidc1.35.17NullUnknown License
github.com/charmbracelet/log1.0.0NullUnknown License
github.com/decred/dcrd/dcrec/secp256k1/v44.4.1NullUnknown License
github.com/docker/cli29.3.0+incompatibleNullUnknown License
github.com/docker/docker-credential-helpers0.9.5NullUnknown License
github.com/envoyproxy/protoc-gen-validate1.3.3NullUnknown License
github.com/golang/snappy1.0.0NullUnknown License
github.com/google/go-containerregistry0.21.2NullUnknown License
github.com/google/go-querystring1.2.0NullUnknown License
github.com/googleapis/enterprise-certificate-proxy0.3.14NullUnknown License
github.com/hashicorp/consul/api1.33.4NullUnknown License
github.com/hashicorp/go-getter1.8.5NullUnknown License
github.com/mattn/go-runewidth0.0.21NullUnknown License
github.com/open-policy-agent/opa1.14.1NullUnknown License
github.com/petermattis/goid0.0.0-20260226131333-17d1149c6ac6NullUnknown License
github.com/posthog/posthog-go1.11.1NullUnknown License
github.com/prometheus/procfs0.20.1NullUnknown License
github.com/samber/lo1.53.0NullUnknown License
github.com/sasha-s/go-deadlock0.3.7NullUnknown License
github.com/segmentio/encoding0.5.4NullUnknown License
github.com/valyala/fastjson1.6.10NullUnknown License
golang.org/x/crypto0.49.0NullUnknown License
golang.org/x/exp0.0.0-20260312153236-7ab1446f8b90NullUnknown License
golang.org/x/mod0.34.0NullUnknown License
golang.org/x/net0.52.0NullUnknown License
golang.org/x/term0.41.0NullUnknown License
golang.org/x/text0.35.0NullUnknown License
golang.org/x/tools0.43.0NullUnknown License
k8s.io/client-go0.35.2NullUnknown License
github.com/modelcontextprotocol/go-sdk1.4.1NullUnknown License
Allowed Licenses: MIT, MIT-0, Apache-2.0, BSD-2-Clause, BSD-2-Clause-Views, BSD-3-Clause, ISC, MPL-2.0, 0BSD, Unlicense, CC0-1.0, CC-BY-3.0, CC-BY-4.0, CC-BY-SA-3.0, Python-2.0, OFL-1.1, LicenseRef-scancode-generic-cla, LicenseRef-scancode-unknown-license-reference, LicenseRef-scancode-unicode, LicenseRef-scancode-google-patent-license-golang
Excluded from license check: pkg:golang/modernc.org/libc

Scanned Files

  • go.mod

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 16, 2026

📝 Walkthrough

Walkthrough

Derives and propagates a stack name when processing file-scoped locals so YAML functions that require a stack (e.g., 2-arg !terraform.state) can resolve. Adds deriveStackNameForLocals and computeStackFileName helpers, wires derived stack into ProcessStackLocals, adds tests, fixtures, docs, example updates, dependency bumps, and a small import cleanup.

Changes

Cohort / File(s) Summary
Stack Processor & Tests
internal/exec/stack_processor_utils.go, internal/exec/stack_processor_utils_test.go
Add deriveStackNameForLocals and computeStackFileName; compute and pass derived currentStack into ProcessStackLocals; many unit/integration tests covering filename stripping, name pattern derivation, and YAML/template locals resolution (including !terraform.state scenarios).
Docs: Fix Report
docs/fixes/2026-03-15-locals-terraform-state-missing-stack-context.md
New design-and-fix article documenting root cause, implementation, tests, fixtures, and backward-compatibility notes.
Website Docs
website/docs/stacks/locals.mdx
Expanded locals documentation: processing pipeline, YAML functions, topological resolution, scope/isolation, and examples (conditionals, two- and three-arg !terraform.state).
Examples & Stacks
examples/locals/..., examples/locals/components/terraform/myapp/main.tf, examples/locals/stacks/deploy/*.yaml, examples/locals/README.md
Add/adjust example locals and README; add worker component; introduce new vars/outputs (deploy_target, managed_by, namespace_upper), and update examples to exercise derived-stack behavior.
Test Fixtures & CLI Tests
tests/fixtures/scenarios/locals-conditional/*, tests/cli_locals_test.go
New locals-conditional fixture and mock Terraform component; new CLI tests validating Go-template conditionals, env-driven locals, and worker component behavior.
Dependency & Version Updates
go.mod, go.sum, examples/quick-start-advanced/Dockerfile, pkg/*/*_test.go
Numerous dependency bumps across modules; ATMOS_VERSION updated from 1.209.01.210.0 in examples/tests.
Cleanup
internal/terraform_backend/terraform_backend_s3.go
Removed unused import github.com/aws/aws-sdk-go-v2/feature/s3/manager.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant File as Stack file (catalog/stack)
participant Processor as StackProcessor (deriveStackNameForLocals)
participant Locals as ProcessStackLocals
participant TF as TerraformStateResolver
participant Backend as RemoteStateBackend

File->>Processor: provide raw YAML + filePath
Processor->>Processor: computeStackFileName(filePath)
Processor->>Processor: deriveStackNameForLocals(config, rawYAML)
Processor->>Locals: ProcessStackLocals(locals, currentStack)
Locals->>TF: !terraform.state lookup (component, key, currentStack)
TF->>Backend: fetch remote state for resolved stack/component
Backend-->>TF: return state value
TF-->>Locals: resolved value
Locals-->>Processor: resolved locals

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

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.
Linked Issues check ✅ Passed The PR successfully implements the fix for issue #2080 by deriving stack context in locals, adding new helper functions, comprehensive tests, fixtures, and documentation.
Out of Scope Changes check ✅ Passed All changes are directly related to the stated objective of fixing !terraform.state in locals. Version bumps, example updates, and documentation enhancements all support the core fix.
Docstring Coverage ✅ Passed Docstring coverage is 85.00% which is sufficient. The required threshold is 80.00%.
Title check ✅ Passed The title clearly and concisely summarizes the main fix: resolving stack context to enable YAML functions like !terraform.state in locals, which directly addresses the core problem in issue #2080.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch aknysh/improve-locals-5
📝 Coding Plan
  • Generate coding plan for human review comments

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 and usage tips.

Tip

You can enable review details to help with troubleshooting, context usage and more.

Enable the reviews.review_details setting to include review details such as the model used, the time taken for each step and more in the review comments.

…n locals docs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@aknysh aknysh changed the title fix: derive stack name for locals so !terraform.state works fix: resolve stack context for locals enabling !terraform.state and YAML functions Mar 16, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
NOTICE (1)

1-1757: ⚠️ Potential issue | 🟠 Major

Regenerate NOTICE before merge.

The dependency review workflow is failing because this file is still out of sync with the generator output. Please run ./scripts/generate-notice.sh and commit the regenerated file.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@NOTICE` around lines 1 - 1757, The NOTICE file is out of sync with the
generator; run the provided generator script (./scripts/generate-notice.sh) to
regenerate the NOTICE contents, verify the updated NOTICE matches the generator
output, add the regenerated NOTICE to the commit, and push the change so the
dependency review workflow passes.
🧹 Nitpick comments (1)
website/docs/stacks/locals.mdx (1)

43-43: Fix component type typo: absibleansible.

Line 43 and Line 58 contain a misspelling that can mislead users.

✏️ Suggested doc fix
-1. Parse raw YAML → extract locals sections (global, terraform, helmfile, packer, absible, etc.)
+1. Parse raw YAML → extract locals sections (global, terraform, helmfile, packer, ansible, etc.)

-Global locals → Component-type locals (terraform/helmfile/packer/absible) → Component-level locals
+Global locals → Component-type locals (terraform/helmfile/packer/ansible) → Component-level locals

Also applies to: 58-58

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@website/docs/stacks/locals.mdx` at line 43, Replace the misspelled component
type "absible" with the correct "ansible" in the locals list occurrences (e.g.,
the line containing "Parse raw YAML → extract locals sections (global,
terraform, helmfile, packer, absible, etc.)" and the second occurrence around
the later locals list); update both instances so the list reads "...packer,
ansible, etc." to correct the documentation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/fixes/2026-03-15-locals-terraform-state-missing-stack-context.md`:
- Around line 122-132: The two bullets under "File-Scoped Locals (Global +
Section)" and "Component-Level Locals" contradict each other about precedence;
standardize on component-level locals overriding file-scoped locals by changing
the file-scoped statement "Cannot be overridden by individual components." to
"Can be overridden by component-level locals." and ensure the "Component-Level
Locals" block keeps "Override file-scoped locals." and any surrounding
explanatory text or examples consistently reflect that precedence for
File-Scoped Locals and Component-Level Locals.

In `@examples/locals/README.md`:
- Line 15: Update the bullet "File-scoped isolation — dev.yaml and prod.yaml
have independent locals" by adding a terminal period at the end so it reads
"File-scoped isolation — dev.yaml and prod.yaml have independent locals." to
match punctuation consistency in the README.

In `@examples/locals/stacks/deploy/dev.yaml`:
- Around line 49-50: The comment claiming "Section-level locals (under
terraform:) inherit from global locals. This shows that you can also define
locals here." is misleading because there is no actual locals: block; either
update the comment to accurately describe that this section adds another
component rather than demonstrating locals, or add a real locals: block under
terraform: to match the comment; locate the terraform: section in the file and
either change the comment text to reflect adding a component or insert a locals:
mapping (e.g., example variable definitions) under terraform: so the example and
comment align.

In `@internal/exec/stack_processor_utils_test.go`:
- Around line 2621-2644: Replace hardcoded Unix-style test paths with
OS-agnostic paths by building them with filepath.Join where the test cases set
the filePath field; e.g., update test entries that set filePath:
"/project/stacks/..." (including cases named "nested org path", "yml extension"
and others around those ranges) to construct the same path using
filepath.Join("projectRoot", "stacks", ...) or filepath.Join("/project")
equivalents and join the filename with the extension using filepath.Join so
tests don't assume forward slashes; ensure expected values remain computed with
filepath.Join as in the test and only modify the filePath test inputs.

In `@internal/exec/stack_processor_utils.go`:
- Around line 146-152: computeStackFileName currently only strips the final file
extension so names like "deploy/dev.yaml.tmpl" become "deploy/dev.yaml"; change
the logic in computeStackFileName to iteratively remove known extensions (e.g.,
".tmpl", ".yaml", ".yml", ".json", etc.) by looping with filepath.Ext on rel and
trimming the extension while the ext is in the allowed removable set, ensuring
rel ends up with the base stack name; reference the rel and ext variables in
computeStackFileName and preserve use of filepath functions (no hardcoded
separators) when handling paths.

---

Outside diff comments:
In `@NOTICE`:
- Around line 1-1757: The NOTICE file is out of sync with the generator; run the
provided generator script (./scripts/generate-notice.sh) to regenerate the
NOTICE contents, verify the updated NOTICE matches the generator output, add the
regenerated NOTICE to the commit, and push the change so the dependency review
workflow passes.

---

Nitpick comments:
In `@website/docs/stacks/locals.mdx`:
- Line 43: Replace the misspelled component type "absible" with the correct
"ansible" in the locals list occurrences (e.g., the line containing "Parse raw
YAML → extract locals sections (global, terraform, helmfile, packer, absible,
etc.)" and the second occurrence around the later locals list); update both
instances so the list reads "...packer, ansible, etc." to correct the
documentation.
🪄 Autofix (Beta)

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

Run ID: 253dd494-e3ce-4198-b086-4d978a23b98c

📥 Commits

Reviewing files that changed from the base of the PR and between 1f4ac96 and 5d17db7.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (19)
  • NOTICE
  • docs/fixes/2026-03-15-locals-terraform-state-missing-stack-context.md
  • examples/locals/README.md
  • examples/locals/components/terraform/myapp/main.tf
  • examples/locals/stacks/deploy/dev.yaml
  • examples/locals/stacks/deploy/prod.yaml
  • examples/quick-start-advanced/Dockerfile
  • go.mod
  • internal/exec/stack_processor_utils.go
  • internal/exec/stack_processor_utils_test.go
  • internal/terraform_backend/terraform_backend_s3.go
  • pkg/ai/analyze/analyze_test.go
  • pkg/devcontainer/lifecycle_rebuild_test.go
  • tests/cli_locals_test.go
  • tests/fixtures/scenarios/locals-conditional/atmos.yaml
  • tests/fixtures/scenarios/locals-conditional/components/terraform/mock/main.tf
  • tests/fixtures/scenarios/locals-conditional/stacks/deploy/pr-empty.yaml
  • tests/fixtures/scenarios/locals-conditional/stacks/deploy/pr-set.yaml
  • website/docs/stacks/locals.mdx
💤 Files with no reviewable changes (1)
  • internal/terraform_backend/terraform_backend_s3.go

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 16, 2026

Codecov Report

❌ Patch coverage is 77.14286% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.40%. Comparing base (1f4ac96) to head (a5a10d3).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/exec/stack_processor_utils.go 77.14% 4 Missing and 4 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2207   +/-   ##
=======================================
  Coverage   77.40%   77.40%           
=======================================
  Files         962      962           
  Lines       91284    91318   +34     
=======================================
+ Hits        70657    70685   +28     
+ Misses      16550    16549    -1     
- Partials     4077     4084    +7     
Flag Coverage Δ
unittests 77.40% <77.14%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
internal/terraform_backend/terraform_backend_s3.go 91.26% <ø> (ø)
internal/exec/stack_processor_utils.go 81.00% <77.14%> (-0.16%) ⬇️

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Handle .yaml.tmpl/.yml.tmpl extensions in computeStackFileName (longest suffix first)
- Add test cases for .yaml.tmpl, .yml.tmpl, no extension, and unknown extension
- Use filepath.Join() for all test paths (cross-platform compliance)
- Fix absible → ansible typo in locals docs
- Fix misleading comment in dev.yaml example
- Fix override semantics contradiction in fix doc

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/fixes/2026-03-15-locals-terraform-state-missing-stack-context.md`:
- Around line 488-503: The test summary counts in the docs are stale: update the
listed counts for TestComputeStackFileName, TestDeriveStackNameForLocals, and
the integration tests (TestLocalsGoTemplateConditionalWithEnvSet,
TestLocalsGoTemplateConditionalWithEnvEmpty) to match the actual test
definitions or replace numeric counts with non-numeric wording (e.g., "several
cases" or "multiple scenarios") so they won't drift; specifically ensure the
entries for TestComputeStackFileName, TestDeriveStackNameForLocals,
TestExtractLocalsFromRawYAML_* and the two TestLocalsGoTemplateConditional*
integration tests reflect current case counts or use the non-numeric phrasing.

In `@website/docs/stacks/locals.mdx`:
- Around line 42-59: The docs currently list "ansible" as part of the locals
resolution pipeline and scope chain but the implementation only resolves global
+ terraform + helmfile + packer; update the text in the locals.mdx content to
either remove "ansible" from the pipeline list and the scope chain example (the
lines showing "global, terraform, helmfile, packer, ansible, etc." and "Global
locals → Component-type locals (terraform/helmfile/packer/ansible) →
Component-level locals") or annotate "ansible" as not yet supported/planned, so
the documented pipeline matches the actual behavior used by the locals
resolution code path.
🪄 Autofix (Beta)

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

Run ID: c0e54922-8b3c-4ad4-bc56-473ef3cb8786

📥 Commits

Reviewing files that changed from the base of the PR and between 5d17db7 and b9bc572.

📒 Files selected for processing (5)
  • docs/fixes/2026-03-15-locals-terraform-state-missing-stack-context.md
  • examples/locals/stacks/deploy/dev.yaml
  • internal/exec/stack_processor_utils.go
  • internal/exec/stack_processor_utils_test.go
  • website/docs/stacks/locals.mdx

- Update TestComputeStackFileName case count from 4 to 8 in fix doc
- Remove ansible from locals pipeline/scope docs (only terraform/helmfile/packer supported)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
website/docs/stacks/locals.mdx (1)

34-34: Minor: Cycle path format differs from actual error output.

The docs show a -> b -> c -> a with ASCII arrows, but the actual error message uses Unicode arrows (a → b → c → a) per formatCyclePath() in the resolver. Consider aligning for consistency when users compare error output to docs.

Suggested fix
-3. **Cycle Detection:** Circular references are detected and reported with clear error messages showing the dependency path (e.g., `a -> b -> c -> a`).
+3. **Cycle Detection:** Circular references are detected and reported with clear error messages showing the dependency path (e.g., `a → b → c → a`).
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@website/docs/stacks/locals.mdx` at line 34, The docs currently show cycle
paths with ASCII arrows but the runtime uses Unicode arrows from
formatCyclePath(); update the example in locals.mdx to match the actual error
output (e.g., change `a -> b -> c -> a` to `a → b → c → a`) so users see the
same format as produced by the resolver's formatCyclePath() function.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@website/docs/stacks/locals.mdx`:
- Line 34: The docs currently show cycle paths with ASCII arrows but the runtime
uses Unicode arrows from formatCyclePath(); update the example in locals.mdx to
match the actual error output (e.g., change `a -> b -> c -> a` to `a → b → c →
a`) so users see the same format as produced by the resolver's formatCyclePath()
function.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e817d9a0-01c5-4b3e-8ec8-ab27876f68d1

📥 Commits

Reviewing files that changed from the base of the PR and between b9bc572 and a5a10d3.

📒 Files selected for processing (2)
  • docs/fixes/2026-03-15-locals-terraform-state-missing-stack-context.md
  • website/docs/stacks/locals.mdx

@aknysh aknysh changed the title fix: resolve stack context for locals enabling !terraform.state and YAML functions fix: resolve stack context for locals enabling !terraform.state and other YAML functions Mar 16, 2026
@aknysh aknysh merged commit 9b7152a into main Mar 16, 2026
59 checks passed
@aknysh aknysh deleted the aknysh/improve-locals-5 branch March 16, 2026 15:29
@mergify mergify bot removed the needs-cloudposse Needs Cloud Posse assistance label Mar 16, 2026
osterman pushed a commit that referenced this pull request Mar 16, 2026
…nd other YAML functions (#2207)

* updates

* fix: derive stack name for locals so !terraform.state works (#2080)

The 2-arg form of !terraform.state in locals failed with "stack is
required" because extractLocalsFromRawYAML passed an empty string as
the current stack. Add deriveStackNameForLocals() and
computeStackFileName() to derive the stack name from the file path,
vars, and atmos config before processing locals.

Includes unit tests with mock StateGetter, integration tests for Go
template conditionals with !env, a new locals-conditional fixture,
and comprehensive architecture documentation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Update locals example to showcase all features concisely

Add Sprig functions (pipe upper), multiple components (myapp-worker
with suffixed full_name), and file-scoped isolation commentary.
Update README with feature sections and try-it commands.
Add TestExampleLocalsWorkerComponent test.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Update locals documentation with processing pipeline and YAML function details

Add comprehensive documentation for locals processing pipeline, cross-component
references with !terraform.state, environment variable conditionals with !env,
and updated best practices.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* update docs

* [autofix.ci] apply automated fixes

* Fix broken link and add Gomplate/Atmos template function references in locals docs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Improve test coverage and address PR review feedback

- Handle .yaml.tmpl/.yml.tmpl extensions in computeStackFileName (longest suffix first)
- Add test cases for .yaml.tmpl, .yml.tmpl, no extension, and unknown extension
- Use filepath.Join() for all test paths (cross-platform compliance)
- Fix absible → ansible typo in locals docs
- Fix misleading comment in dev.yaml example
- Fix override semantics contradiction in fix doc

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Address PR review: fix test count, remove ansible from locals scopes

- Update TestComputeStackFileName case count from 4 to 8 in fix doc
- Remove ansible from locals pipeline/scope docs (only terraform/helmfile/packer supported)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown

These changes were released in v1.210.0-test.28.

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/l Large size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

!terraform.state in catalog file locals fails with "stack is required" error

2 participants