Skip to content

feat: updated name for stack depednencies - #6018

Merged
denis256 merged 4 commits into
mainfrom
OSS-3409
May 4, 2026
Merged

feat: updated name for stack depednencies#6018
denis256 merged 4 commits into
mainfrom
OSS-3409

Conversation

@denis256

@denis256 denis256 commented May 1, 2026

Copy link
Copy Markdown
Member

Description

Generated autoinclude filenames now depend on the component kind:

  • Unit autoincludes continue to be written as terragrunt.autoinclude.hcl
  • Stack autoincludes are now written as terragrunt.autoinclude.stack.hcl

RFC #5663

TODOs

Read the Gruntwork contribution guidelines.

  • I authored this code entirely myself
  • I am submitting code based on open source software (e.g. MIT, MPL-2.0, Apache)
  • I am adding or upgrading a dependency or adapted code and confirm it has a compatible open source license
  • Update the docs.
  • Update the changelog in the docs.
  • Run the relevant tests successfully, including pre-commit checks.
  • This change is backwards compatible.
  • If this change is not forwards compatible (e.g. a new feature), it is gated behind a feature flag.

Summary by CodeRabbit

  • Documentation

    • Added v1.0.4 changelog entry documenting the autoinclude naming convention: unit autoincludes keep terragrunt.autoinclude.hcl; stack autoincludes are generated as terragrunt.autoinclude.stack.hcl. Updated experiment docs and marked the “distinct filenames” behavior complete.
  • Tests

    • Added tests covering unit vs. stack autoinclude filename selection, mapping behavior, and end-to-end generation verification.

@vercel

vercel Bot commented May 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
terragrunt-docs Ready Ready Preview, Comment May 4, 2026 0:49am

Request Review

@coderabbitai

coderabbitai Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds a typed autoinclude kind that tracks whether an autoinclude originates from a unit or a stack, changes filename selection to produce terragrunt.autoinclude.hcl for units and terragrunt.autoinclude.stack.hcl for stacks, and updates parsing, generation, config gating, tests, and docs accordingly.

Changes

Autoinclude kind, filename, parsing, wiring, tests, and docs

Layer / File(s) Summary
Data Shape
internal/hclparse/autoinclude.go
Adds exported Kind AutoIncludeKind field to AutoIncludeResolved to carry unit vs. stack provenance.
Core Implementation
internal/hclparse/generate.go
Introduces exported AutoIncludeKind type, KindUnit/KindStack constants, AutoIncludeStackFile constant, and AutoIncludeFileNameForKind(kind) to map kind→filename; GenerateAutoIncludeFile now uses resolved.Kind.
Parsing / Resolution
internal/hclparse/parse.go
AutoIncludeKey now accepts AutoIncludeKind; resolveAutoIncludes passes KindUnit/KindStack; resolveAutoInclude accepts kind and sets resolved.Kind = kind.
Wiring / Integration
pkg/config/stack.go, pkg/config/config.go
generateAutoInclude uses typed kind for lookup/logging; adds exported DefaultAutoIncludeStackFile constant and extends ParseConfig gating to treat stack autoinclude filename similarly to unit autoinclude when deciding whether to auto-merge.
Tests / E2E
internal/hclparse/parse_test.go, pkg/config/autoinclude_test.go
Adds tests asserting resolved.Kind for stack autoincludes, verifies AutoIncludeFileNameForKind mappings and panics for unknown kinds, and end-to-end assertions that unit vs stack files are written (or not) and that stack autoincludes don't merge into unit config.
Documentation / Changelog
docs/src/data/experiments/stack-dependencies.mdx, docs/src/data/changelog/v1.0.4/stack-autoinclude-filename-split.mdx
Documents distinct filename behavior (terragrunt.autoinclude.hcl vs terragrunt.autoinclude.stack.hcl), updates roadmap/checklist, and adds illustrative HCL examples.

Sequence Diagram(s)

sequenceDiagram
    rect rgba(30,144,255,0.5)
    participant CLI as CLI
    end
    participant Parser as Parser
    participant Generator as Generator
    participant FS as Filesystem
    participant Config as ConfigLoader

    CLI->>Parser: parse config (detect autoinclude blocks)
    Parser->>Parser: resolve autoinclude\n(tag as KindUnit or KindStack)
    Parser->>Config: return ParseResult (AutoIncludes with Kind)
    Config->>Generator: request GenerateAutoIncludeFile(resolved)
    Generator->>Generator: AutoIncludeFileNameForKind(resolved.Kind)
    Generator->>FS: write file named by kind (unit or .stack)
    FS-->>Generator: write success/failure
    Generator->>CLI: log output including filename and kind
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 68.75% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title refers to 'stack depednencies' (with a typo) but accurately describes the main change: updated naming for stack autoinclude files as part of stack dependencies feature.
Description check ✅ Passed The description explains the core change and includes most checklist items marked complete, though the 'I authored this code entirely myself' checkbox remains unchecked without explanation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch OSS-3409

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
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

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

@denis256
denis256 marked this pull request as ready for review May 1, 2026 20:12
@denis256
denis256 requested a review from yhakbar as a code owner May 1, 2026 20:12

@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 the current code and only fix it if needed.

Inline comments:
In `@docs/src/data/changelog/v1.0.4/stack-autoinclude-filename-split.mdx`:
- Around line 13-34: The HCL example references undefined units (unit.vpc.path
and unit.shared.path) which will raise "Variable not found" during the two‑pass
autoinclude parse; fix by adding minimal stub unit declarations for the
referenced units (e.g., unit "vpc" and unit "shared") with matching source and
path values above the existing unit "app" and before stack "networking", or
alternatively add a clear inline note that those unit declarations are
intentionally omitted and the paths are illustrative only; ensure the stubs use
the same identifiers (unit.vpc and unit.shared) so the autoinclude dependency
lines (dependency "vpc" { config_path = unit.vpc.path } and dependency "shared"
{ config_path = unit.shared.path }) resolve.
🪄 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: f7ec1c72-4683-4e77-ba2c-a8155edb1cd3

📥 Commits

Reviewing files that changed from the base of the PR and between c45c1a9 and 3789ed4.

📒 Files selected for processing (9)
  • docs/src/data/changelog/v1.0.4/stack-autoinclude-filename-split.mdx
  • docs/src/data/experiments/stack-dependencies.mdx
  • internal/hclparse/autoinclude.go
  • internal/hclparse/generate.go
  • internal/hclparse/parse.go
  • internal/hclparse/parse_test.go
  • pkg/config/autoinclude_test.go
  • pkg/config/config.go
  • pkg/config/stack.go

Comment on lines +13 to +34
```hcl
# terragrunt.stack.hcl
unit "app" {
source = "../catalog/units/app"
path = "app"

autoinclude {
# Generated as: .terragrunt-stack/app/terragrunt.autoinclude.hcl
dependency "vpc" { config_path = unit.vpc.path }
}
}

stack "networking" {
source = "../catalog/stacks/networking"
path = "networking"

autoinclude {
# Generated as: .terragrunt-stack/networking/terragrunt.autoinclude.stack.hcl
dependency "shared" { config_path = unit.shared.path }
}
}
```

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

HCL example references undefined units — copy-paste would error.

unit.vpc.path (line 21) and unit.shared.path (line 31) reference units that are not declared in the example. During the two-pass autoinclude parser, these would fail with a "Variable not found" diagnostic, which could confuse readers who copy the snippet.

Consider adding stub unit declarations or a note that the referenced units are omitted:

✏️ Proposed fix — add the missing unit stubs
 ```hcl
 # terragrunt.stack.hcl
+unit "vpc" {
+  source = "../catalog/units/vpc"
+  path   = "vpc"
+}
+
 unit "app" {
   source = "../catalog/units/app"
   path   = "app"
 
   autoinclude {
     # Generated as: .terragrunt-stack/app/terragrunt.autoinclude.hcl
     dependency "vpc" { config_path = unit.vpc.path }
   }
 }
 
+unit "shared" {
+  source = "../catalog/units/shared"
+  path   = "shared"
+}
+
 stack "networking" {
   source = "../catalog/stacks/networking"
   path   = "networking"
 
   autoinclude {
     # Generated as: .terragrunt-stack/networking/terragrunt.autoinclude.stack.hcl
     dependency "shared" { config_path = unit.shared.path }
   }
 }
</details>

<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

```suggestion

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

In `@docs/src/data/changelog/v1.0.4/stack-autoinclude-filename-split.mdx` around
lines 13 - 34, The HCL example references undefined units (unit.vpc.path and
unit.shared.path) which will raise "Variable not found" during the two‑pass
autoinclude parse; fix by adding minimal stub unit declarations for the
referenced units (e.g., unit "vpc" and unit "shared") with matching source and
path values above the existing unit "app" and before stack "networking", or
alternatively add a clear inline note that those unit declarations are
intentionally omitted and the paths are illustrative only; ensure the stubs use
the same identifiers (unit.vpc and unit.shared) so the autoinclude dependency
lines (dependency "vpc" { config_path = unit.vpc.path } and dependency "shared"
{ config_path = unit.shared.path }) resolve.

yhakbar
yhakbar previously approved these changes May 1, 2026

@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 the current code and only fix it if needed.

Inline comments:
In `@internal/hclparse/autoinclude.go`:
- Around line 56-57: Update the Resolve() doc comment to state that callers must
also set the Kind field (type AutoIncludeKind) after the call, just like
SourceBytes, because calling AutoIncludeFileNameForKind with the zero-value Kind
("") will panic; reference Resolve(), the Kind field, AutoIncludeKind,
SourceBytes, and AutoIncludeFileNameForKind in the comment so callers know to
populate Kind before using helpers that derive filenames.
🪄 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: 9c6f3346-5f93-4743-b090-472fbc1416bb

📥 Commits

Reviewing files that changed from the base of the PR and between 3789ed4 and 959ecd8.

📒 Files selected for processing (6)
  • internal/hclparse/autoinclude.go
  • internal/hclparse/generate.go
  • internal/hclparse/parse.go
  • internal/hclparse/parse_test.go
  • pkg/config/config.go
  • pkg/config/stack.go
✅ Files skipped from review due to trivial changes (1)
  • internal/hclparse/parse_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • internal/hclparse/parse.go
  • pkg/config/stack.go
  • pkg/config/config.go
  • internal/hclparse/generate.go

Comment on lines +56 to +57
// Kind is KindUnit or KindStack and drives the generated filename (terragrunt.autoinclude.hcl vs terragrunt.autoinclude.stack.hcl).
Kind AutoIncludeKind

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Resolve() doc comment omits the Kind post-call requirement.

Resolve() already documents that callers must set SourceBytes after the call. The new Kind field carries the same obligation — if AutoIncludeFileNameForKind is called with the zero-value Kind (""), it panics immediately. The doc comment on Resolve() (lines 72–86) should add an equivalent notice for Kind, matching the existing SourceBytes guidance.

📝 Proposed doc update on `Resolve()`
 // Callers that need to record the originating file's bytes on the returned
 // AutoIncludeResolved (so generation can slice expressions from the correct
 // source after include merging) should set SourceBytes on the result.
+//
+// Callers must also set Kind (KindUnit or KindStack) on the result before
+// passing it to AutoIncludeFileNameForKind; the zero value ("") is not valid
+// and will cause a panic.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/hclparse/autoinclude.go` around lines 56 - 57, Update the Resolve()
doc comment to state that callers must also set the Kind field (type
AutoIncludeKind) after the call, just like SourceBytes, because calling
AutoIncludeFileNameForKind with the zero-value Kind ("") will panic; reference
Resolve(), the Kind field, AutoIncludeKind, SourceBytes, and
AutoIncludeFileNameForKind in the comment so callers know to populate Kind
before using helpers that derive filenames.

@denis256
denis256 merged commit 3543ebe into main May 4, 2026
52 checks passed
@denis256
denis256 deleted the OSS-3409 branch May 4, 2026 13:18
Rahul-Kumar-prog pushed a commit to Rahul-Kumar-prog/terragrunt that referenced this pull request May 10, 2026
* feat: updated name for stack dependencies

* chore: hcl parsing kind

* chore: stack auto include file name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants