Repository navigation
feat(hooks): terraform init lifecycle hooks + --skip-hooks before-* fix - #2574
Conversation
--skip-hooks only skipped after-* hooks. before-* hooks run in PreRunE,
before the global persistent flag is bound to Viper in RunE, so the skip
decision (viper.GetString("skip-hooks") in RunAll) never saw the CLI value
and before-hooks fired regardless.
Resolve the flag directly from the Cobra command (preferring an explicitly
set flag, falling back to Viper for ATMOS_SKIP_HOOKS/default), mirroring how
--ci and --verbose are read in PreRunE. This makes skipping symmetric across
before-* and after-* for plan, apply, and deploy.
Tests:
- TestResolveSkipHooks: drives a real parsed Cobra flag (not viper.Set),
covering nil-cmd fallback, bare flag, list, env fallback, and CLI-wins
precedence. Fails against the old viper-only implementation.
- TestRunAll_SkipHooksFromCobraFlag: a before-terraform-plan hook is skipped
via the real flag and fires when absent (negative path).
- Strengthen stack_processor_process_stacks_test hooks cases to assert
inheritance onto components; add TestProcessStackConfig_HooksWrongScopeNotInherited.
- Add describe-component end-to-end test + fixture proving top-level
terraform.hooks (and global hooks:) are inherited by a component with no
hooks of its own.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
Dependency Review✅ No vulnerabilities or license issues found.Scanned FilesNone |
|
Wondering what really moved? Review this PR in Change Stack to inspect semantic changes, definitions, and references. Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds Cobra-aware ChangesHook skip-flag resolution and inheritance validation
Sequence Diagram(s)sequenceDiagram
participant CobraCmd
participant Hooks
participant Viper
CobraCmd->>Hooks: resolveSkipHooks(cmd) (use flag when Changed)
Hooks->>Viper: fallback to viper.GetString("skip-hooks")
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/hooks/skip_test.go (1)
41-42: ⚡ Quick winUse
assert.NoErrordirectly for consistency.Line 41 creates a variable named
requirefromassert.New(t), but this doesn't give yourequiresemantics (test continues on failure). The rest of your test cases useassert.NoError(t, ...)directly. Stick to that pattern.♻️ Align with the pattern used in other sub-tests
- require := assert.New(t) - require.NoError(cmd.ParseFlags([]string{"--skip-hooks"})) + assert.NoError(t, cmd.ParseFlags([]string{"--skip-hooks"}))🤖 Prompt for 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. In `@pkg/hooks/skip_test.go` around lines 41 - 42, Replace the local `require := assert.New(t)` usage and the subsequent `require.NoError(cmd.ParseFlags([]string{"--skip-hooks"}))` call with the direct package-level assertion `assert.NoError(t, cmd.ParseFlags([]string{"--skip-hooks"}))` so the test uses the same `assert.NoError(t, ...)` pattern as other sub-tests; remove the `require` variable and call `assert.NoError` directly against the `cmd.ParseFlags` invocation.
🤖 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.
Nitpick comments:
In `@pkg/hooks/skip_test.go`:
- Around line 41-42: Replace the local `require := assert.New(t)` usage and the
subsequent `require.NoError(cmd.ParseFlags([]string{"--skip-hooks"}))` call with
the direct package-level assertion `assert.NoError(t,
cmd.ParseFlags([]string{"--skip-hooks"}))` so the test uses the same
`assert.NoError(t, ...)` pattern as other sub-tests; remove the `require`
variable and call `assert.NoError` directly against the `cmd.ParseFlags`
invocation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 068653ac-98c3-4b47-a234-d9576b49c1a2
📒 Files selected for processing (9)
internal/exec/describe_component_hooks_test.gointernal/exec/stack_processor_process_stacks_test.gopkg/hooks/hooks.gopkg/hooks/hooks_test.gopkg/hooks/skip_test.gotests/fixtures/scenarios/hooks-terraform-scope/atmos.yamltests/fixtures/scenarios/hooks-terraform-scope/components/terraform/vpc/main.tftests/fixtures/scenarios/hooks-terraform-scope/stacks/_defaults.yamltests/fixtures/scenarios/hooks-terraform-scope/stacks/test.yaml
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2574 +/- ##
==========================================
+ Coverage 78.88% 78.92% +0.03%
==========================================
Files 1207 1207
Lines 116425 116441 +16
==========================================
+ Hits 91845 91897 +52
+ Misses 19498 19463 -35
+ Partials 5082 5081 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Wire user-facing before-terraform-init and after-terraform-init hooks on the `atmos terraform init` command. before-terraform-init was documented but never dispatched to user hooks; after-terraform-init is new. They fire via the same runHooks/RunAll path as plan/apply/deploy, so the --skip-hooks fix applies to them automatically. - Add AfterTerraformInit event constant (pkg/hooks/event.go). - Wire PreRunE/PostRunE + error-path defer in cmd/terraform/init.go, mirroring plan.go (no output capture — init has nothing to summarize). - Tests: MatchesEvent + RunAll event-filtering for before/after init, IsPostExecution and Normalize coverage for init events. - Docs: list after-terraform-init and clarify init events fire on the explicit `atmos terraform init`, not the implicit init during plan/apply. - Changelog blog post + roadmap milestone (extensibility initiative). Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
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 `@website/src/data/roadmap.js`:
- Line 297: The extensibility initiative's progress value was lowered to 83 but
a milestone was shipped; check the extensibility object in
website/src/data/roadmap.js (look for the entry with key/name "extensibility"
and its progress property) and either (a) restore/update progress to 85 if the
shipped milestone was not accounted for, or (b) if new milestones were added or
the calculation method changed, update the milestones array and/or the progress
calculation logic so the progress value correctly reflects shipped milestones;
ensure the progress numeric value matches the milestone state and add a brief
comment near the progress property explaining the rationale for the chosen
value.
🪄 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: d34189a6-cf98-42d1-aced-578645304062
📒 Files selected for processing (8)
cmd/terraform/init.gopkg/hooks/event.gopkg/hooks/event_test.gopkg/hooks/hook_test.gopkg/hooks/hooks_test.gowebsite/blog/2026-06-05-terraform-init-hooks-and-skip-hooks-fix.mdxwebsite/docs/stacks/hooks.mdxwebsite/src/data/roadmap.js
✅ Files skipped from review due to trivial changes (1)
- website/blog/2026-06-05-terraform-init-hooks-and-skip-hooks-fix.mdx
Add TestInitCmd_HookWiring exercising init's PreRunE and both PostRunE branches (single- and multi-component) against the demo-stacks fixture, mirroring the existing utils_hooks_test wrappers. Raises cmd/terraform/init.go coverage of the new hook-wiring lines from ~66% to 85.7%, satisfying the codecov patch threshold. Only the RunE error-path defer remains uncovered. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
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 `@cmd/terraform/init_hooks_test.go`:
- Around line 3-10: The import block is missing blank lines between the three
groups (stdlib, third-party, internal); update the import statement that
currently lists "testing", "github.com/stretchr/testify/assert",
"github.com/stretchr/testify/require", and
"github.com/cloudposse/atmos/pkg/hooks" so that "testing" stays in the first
group, the testify imports stay in the second group separated by a blank line
from "testing", and the "github.com/cloudposse/atmos/pkg/hooks" import is in a
third group separated by a blank line from the testify imports.
🪄 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: 90eec458-4f17-4e1a-aaef-63b4860ca5ea
📒 Files selected for processing (1)
cmd/terraform/init_hooks_test.go
Add TestInitCmd_RunE_FiresAfterInitErrorHookOnFailure: invokes init's RunE in an empty working dir (no stacks directory) so it fails fast in ValidateAtmosConfig without needing a terraform binary, and stubs the error-hook wrapper to assert the deferred after-terraform-init hook fires with the run error. This covers the RunE reset + deferred error path that the wiring test left uncovered, taking the new init hook code above the 80% patch-coverage threshold. The only remaining uncovered lines are defensive BindFlagsToViper return-err branches and the init() panic. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
💥 This pull request now has conflicts. Could you fix it Erik Osterman (Cloud Posse) (@osterman)? 🙏 |
…form-hooks # Conflicts: # website/src/data/roadmap.js
There was a problem hiding this comment.
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 `@website/src/data/roadmap.js`:
- Line 324: The shipped roadmap entry for label 'Remote import source caching
(clone once + TTL)' is missing the required pr field; update the object (the
entry with label exactly matching that string and status: 'shipped') to include
a pr key pointing to the merge PR (e.g. the GitHub PR URL or numeric identifier)
alongside the existing changelog and docs fields so the roadmap metadata
contract (status: 'shipped' requires changelog + pr) is satisfied.
🪄 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: f4a1a8b1-0560-4bc5-83ec-e93f6fb6d831
📒 Files selected for processing (2)
cmd/terraform/init.gowebsite/src/data/roadmap.js
🚧 Files skipped from review as they are similar to previous changes (1)
- cmd/terraform/init.go
There was a problem hiding this comment.
Caution
Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.
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 `@website/src/data/roadmap.js`:
- Line 324: The shipped roadmap entry for label 'Remote import source caching
(clone once + TTL)' is missing the required pr field; update the object (the
entry with label exactly matching that string and status: 'shipped') to include
a pr key pointing to the merge PR (e.g. the GitHub PR URL or numeric identifier)
alongside the existing changelog and docs fields so the roadmap metadata
contract (status: 'shipped' requires changelog + pr) is satisfied.
🪄 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: f4a1a8b1-0560-4bc5-83ec-e93f6fb6d831
📒 Files selected for processing (2)
cmd/terraform/init.gowebsite/src/data/roadmap.js
🚧 Files skipped from review as they are similar to previous changes (1)
- cmd/terraform/init.go
🛑 Comments failed to post (1)
website/src/data/roadmap.js (1)
324-324:
⚠️ Potential issue | 🟠 Major | ⚡ Quick winAdd missing
prlink on shipped roadmap milestone.This milestone is marked
status: 'shipped'but is missing the requiredprfield, which breaks the roadmap metadata contract for shipped items.Suggested minimal fix
- { label: 'Remote import source caching (clone once + TTL)', status: 'shipped', quarter: 'q2-2026', changelog: 'faster-remote-stack-imports', docs: '/stacks/imports#caching-remote-imports', description: 'Each unique remote Git repository is cloned at most once per Atmos invocation; all subdir imports from the same repo are resolved from that shared clone. An opt-in per-import ttl: (or global imports.ttl default in atmos.yaml) reuses the cloned source across invocations until it expires, enabling a warm CI cache (e.g. actions/cache of ~/.cache/atmos/stack-imports) to skip re-cloning entirely. Mutable refs like ?ref=main stay fresh by default—re-cloned once per run unless a ttl is set. Builds on the existing source-provisioning TTL/duration mechanism.', benefits: 'Large stack catalogs with many remote imports see dramatically faster run times—one clone per repo instead of one per import. CI pipelines with a cache layer can skip the network entirely on warm runs. Mutable refs stay correct by default, and ttl is opt-in so there are no surprises.' }, + { label: 'Remote import source caching (clone once + TTL)', status: 'shipped', quarter: 'q2-2026', pr: <PR_NUMBER>, changelog: 'faster-remote-stack-imports', docs: '/stacks/imports#caching-remote-imports', description: 'Each unique remote Git repository is cloned at most once per Atmos invocation; all subdir imports from the same repo are resolved from that shared clone. An opt-in per-import ttl: (or global imports.ttl default in atmos.yaml) reuses the cloned source across invocations until it expires, enabling a warm CI cache (e.g. actions/cache of ~/.cache/atmos/stack-imports) to skip re-cloning entirely. Mutable refs like ?ref=main stay fresh by default—re-cloned once per run unless a ttl is set. Builds on the existing source-provisioning TTL/duration mechanism.', benefits: 'Large stack catalogs with many remote imports see dramatically faster run times—one clone per repo instead of one per import. CI pipelines with a cache layer can skip the network entirely on warm runs. Mutable refs stay correct by default, and ttl is opt-in so there are no surprises.' },As per coding guidelines, for
website/src/data/roadmap.js, shipped milestones must includestatus: 'shipped',changelog, andpr.🤖 Prompt for 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. In `@website/src/data/roadmap.js` at line 324, The shipped roadmap entry for label 'Remote import source caching (clone once + TTL)' is missing the required pr field; update the object (the entry with label exactly matching that string and status: 'shipped') to include a pr key pointing to the merge PR (e.g. the GitHub PR URL or numeric identifier) alongside the existing changelog and docs fields so the roadmap metadata contract (status: 'shipped' requires changelog + pr) is satisfied.Source: Coding guidelines
Shipped roadmap milestones require both changelog and pr; the merged remote-import-caching entry (from #2571) was missing pr. Flagged by CodeRabbit. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The Review Dependency Licenses check regenerates NOTICE and compares; it expects the .../internal/endpoints/v2/LICENSE.txt path (matching main). An autofix bot commit had rewritten it to the parent-dir path without /v2/, causing the check to fail. Restore the /v2/ path so NOTICE matches the generated output and origin/main. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The codecov/codecov-action@v5 uploader verifies the GPG signature of the Codecov CLI it downloads. Transient Codecov-side issues (empty public-key import: "gpg: no valid OpenPGP data found" / "Can't check signature: No public key") make verification exit 1, which hard-failed the whole "Acceptance Tests (linux)" job even when every test passed. Set fail_ci_if_error: false so a coverage-upload/infra flake no longer fails a green test run. The 80% coverage gate is still enforced by Codecov's own PR status check, independent of this step's exit code. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Important Cloud Posse Engineering Team Review RequiredThis 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 |
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
|
Warning Release Documentation RequiredThis PR is labeled
|
|
These changes were released in v1.221.0-rc.7. |
|
These changes were released in v1.221.0. |
what
--skip-hooksfor before- hooks.* Previously it only skippedafter-*hooks;before-terraform-plan/apply/deployhooks ran regardless. Now--skip-hooks(skip all) and--skip-hooks=name1,name2(skip by name) are honored symmetrically for before and after events.before-terraform-initandafter-terraform-initlifecycle hooks for theatmos terraform initcommand.after-terraform-initis new;before-terraform-initwas documented but never dispatched to user hooks — now it fires. They run through the samerunHooks/RunAllpath, so the skip fix applies to them too.viper.Set), strengthen hook-inheritance coverage with a fixture proving top-levelterraform.hooks:is inherited by every component (andcomponents.terraform.hooks:is not), update the Hooks docs, blog post, and roadmap.why
--skip-hooksis a global flag bound to Viper insideRunE, but before-* hooks run earlier inPreRunE— soviper.GetString("skip-hooks")never saw the CLI value and before-hooks fired anyway. The flag is now resolved directly from the parsed command (Viper/ATMOS_SKIP_HOOKSfallback), mirroring how--ciand--verboseare read inPreRunE.init.gowired no hooks and theBeforeTerraformInitevent was never dispatched. WiringPreRunE/PostRunEon the init command (like plan/apply/deploy) closes the lifecycle gap so teams can validate tooling, vendor sources, or notify systems aroundterraform initdeclaratively.viper.Setwith anilcommand, sidestepping the exact flag-binding lifecycle that was broken — which is how the bug shipped; the new tests fail against the old implementation.references
/stacks/hooksbefore-/after-terraform-initfire on the explicitatmos terraform init, not the implicit init that plan/apply run.Summary by CodeRabbit