Repository navigation
fix(flags): scope --skip-hooks to the terraform command subtree - #2578
Conversation
Lifecycle hooks only ever run on terraform plan/apply/deploy, yet --skip-hooks was registered as a global persistent flag on RootCmd, so it leaked into the Global Flags section of nearly every command's help (auth, helmfile, atlantis, toolchain, about, secret, validate, ...). Move the flag from the global flag set to the terraform persistent-flag registry, following the --github-token/toolchain precedent. Behavior is unchanged for terraform users: the flag (and ATMOS_SKIP_HOOKS) still resolve through viper exactly as before, since terraformParser is already registered persistently and bound to viper. - Remove the global registration in pkg/flags/global_builder.go. - Drop the now-unused SkipHooks field in pkg/flags/global/flags.go. - Register --skip-hooks in cmd/terraform/flags.go (registerExecutionFlags). - Move docs from global-flags.mdx into the terraform command docs and fix the cross-links in stacks/hooks.mdx. - Regenerate affected --help golden snapshots. 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 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthrough
ChangesTerraform CLI flag scope and test toolchain
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2578 +/- ##
==========================================
+ Coverage 79.17% 79.21% +0.03%
==========================================
Files 1298 1298
Lines 123772 123780 +8
==========================================
+ Hits 98000 98048 +48
+ Misses 20290 20253 -37
+ Partials 5482 5479 -3
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
The native-ci scenario writes github-output.txt and github-step-summary.txt at runtime via $GITHUB_OUTPUT / $GITHUB_STEP_SUMMARY, but its .gitignore (unlike the newer native-ci-gha-plan scenario) did not ignore them, so the files were tracked and every local run dirtied them — including baking in "terraform: executable file not found" when terraform was absent. Ignore both files (matching native-ci-gha-plan/.gitignore) and untrack them. They are runtime artifacts, not fixtures. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The CLI integration/snapshot tests shelled out to whatever terraform/tofu
binary happened to be on the host (fixtures default to command: terraform).
When the binary was absent, terraform-invoking tests baked
"executable file not found" into golden snapshots and CI scratch files.
Standardize the suite on OpenTofu and make the binary requirement explicit:
- Force OpenTofu for all tests via a single harness default in
runCLICommandTest: set ATMOS_COMPONENTS_TERRAFORM_COMMAND=tofu unless the
test already sets it. The product default stays "terraform"; this only
affects tests. Tests that specifically exercise the terraform binary (the
`atmos terraform -help/-version passthrough` parity tests) opt out by
setting the var to "terraform" in their own env block.
- Sanitize the harness-injected env var out of debug-level snapshots
("Found ENV variable ATMOS_COMPONENTS_TERRAFORM_COMMAND=tofu") so it never
lands in goldens and the selection mechanism stays invisible to output.
- Gate every binary-invoking test on a precondition (`tofu`, or `terraform`
for the opt-out parity tests) so a missing binary SKIPS cleanly instead of
contaminating goldens/scratch files. Add RequireTofu and register the
`tofu` / `terraform_or_tofu` preconditions.
- Regenerate the affected describe/config/stacks goldens (command: tofu).
CI installs both terraform and tofu and bypasses preconditions, so coverage
is unchanged there.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/test-cases/exec-command.yaml (1)
41-59:⚠️ Potential issue | 🟡 MinorAdd
tofuprecondition to test 3 (exec-command exit-code 1)
- tests/cli_test.go forces
ATMOS_COMPONENTS_TERRAFORM_COMMAND=tofufor this suite, so this failing-apply case will try to runtofueven though the args sayterraform; withoutpreconditions: ["tofu"], it won’t skip whentofuisn’t installed (while tests (0) and (2) already do).🤖 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 `@tests/test-cases/exec-command.yaml` around lines 41 - 59, The test "atmos exit code should be same as command exit code (1)" is missing the tofu precondition so the suite-wide forced ATMOS_COMPONENTS_TERRAFORM_COMMAND=tofu causes this failing-apply case to attempt running `tofu` instead of skipping; add preconditions: ["tofu"] to that test block (the test named exactly "atmos exit code should be same as command exit code (1)" in tests/test-cases/exec-command.yaml) so it will be skipped when `tofu` is not installed and behave like the other suites that already include this precondition.
🤖 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.
Outside diff comments:
In `@tests/test-cases/exec-command.yaml`:
- Around line 41-59: The test "atmos exit code should be same as command exit
code (1)" is missing the tofu precondition so the suite-wide forced
ATMOS_COMPONENTS_TERRAFORM_COMMAND=tofu causes this failing-apply case to
attempt running `tofu` instead of skipping; add preconditions: ["tofu"] to that
test block (the test named exactly "atmos exit code should be same as command
exit code (1)" in tests/test-cases/exec-command.yaml) so it will be skipped when
`tofu` is not installed and behave like the other suites that already include
this precondition.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: c33a444d-e66b-4b5e-843d-c5b70d1efef5
📒 Files selected for processing (30)
tests/cli_test.gotests/preconditions.gotests/snapshots/TestCLICommands_atmos_--chdir_config_isolation.stdout.goldentests/snapshots/TestCLICommands_atmos_describe_component_mock_-s_dev_(stack-names_example).stdout.goldentests/snapshots/TestCLICommands_atmos_describe_component_mock_-s_production_(stack-names_example).stdout.goldentests/snapshots/TestCLICommands_atmos_describe_component_vpc_-s_dev_(native-terraform_example).stdout.goldentests/snapshots/TestCLICommands_atmos_describe_component_vpc_-s_my-legacy-prod-stack.stdout.goldentests/snapshots/TestCLICommands_atmos_describe_component_vpc_-s_no-name-prod.stdout.goldentests/snapshots/TestCLICommands_atmos_describe_component_vpc_-s_production_(native-terraform_example).stdout.goldentests/snapshots/TestCLICommands_atmos_describe_config.stdout.goldentests/snapshots/TestCLICommands_atmos_describe_config_-f_yaml.stdout.goldentests/snapshots/TestCLICommands_atmos_describe_config_imports.stdout.goldentests/snapshots/TestCLICommands_atmos_describe_configuration.stdout.goldentests/snapshots/TestCLICommands_atmos_stacks_with_relative_paths.stdout.goldentests/snapshots/TestCLICommands_describe_component_with_component_name_(backward_compatibility).stdout.goldentests/snapshots/TestCLICommands_describe_component_with_current_directory_(.).stdout.goldentests/snapshots/TestCLICommands_describe_component_with_relative_path.stdout.goldentests/snapshots/TestCLICommands_describe_component_with_stack_flag.stdout.goldentests/snapshots/TestCLICommands_indentation.stdout.goldentests/snapshots/TestCLICommands_secrets-masking_describe_config.stdout.goldentests/snapshots/TestCLICommands_secrets-masking_describe_stacks.stdout.goldentests/test-cases/atmos-functions.yamltests/test-cases/env.yamltests/test-cases/exec-command.yamltests/test-cases/help-and-usage.yamltests/test-cases/metadata.yamltests/test-cases/native-ci-gha-plan.yamltests/test-cases/native-ci-planfile.yamltests/test-cases/secrets-masking.yamltests/test-cases/workflows.yaml
✅ Files skipped from review due to trivial changes (12)
- tests/snapshots/TestCLICommands_atmos_describe_configuration.stdout.golden
- tests/snapshots/TestCLICommands_indentation.stdout.golden
- tests/snapshots/TestCLICommands_atmos_describe_component_vpc_-s_my-legacy-prod-stack.stdout.golden
- tests/snapshots/TestCLICommands_atmos_describe_component_vpc_-s_production_(native-terraform_example).stdout.golden
- tests/test-cases/env.yaml
- tests/snapshots/TestCLICommands_atmos_describe_component_vpc_-s_no-name-prod.stdout.golden
- tests/snapshots/TestCLICommands_secrets-masking_describe_config.stdout.golden
- tests/snapshots/TestCLICommands_describe_component_with_component_name_(backward_compatibility).stdout.golden
- tests/test-cases/native-ci-gha-plan.yaml
- tests/snapshots/TestCLICommands_atmos_stacks_with_relative_paths.stdout.golden
- tests/snapshots/TestCLICommands_describe_component_with_stack_flag.stdout.golden
- tests/snapshots/TestCLICommands_atmos_describe_component_mock_-s_production_(stack-names_example).stdout.golden
…lchain The CLI test suite shelled out to host-installed binaries (brew, setup-* GitHub Actions). Dogfood the toolchain instead: TestMain now provisions any missing tool via the Atmos toolchain itself. - Add testhelpers.ProvisionToolchain: for each pinned tool (terraform/tofu/packer/helmfile/helm) not already on PATH, install it via dependencies.NewEnvironmentFromDeps into a stable, shared cache dir and prepend the toolchain bin dirs to PATH. "Install as necessary": in CI the setup-* actions already supply the binaries, so nothing downloads there; locally (no host binaries) the toolchain installs them. - Call it from TestMain before running tests. Best-effort: on failure (offline / rate limits) it logs a warning and returns, leaving the per-test preconditions to skip the affected tests. - ATMOS_TEST_SKIP_TOOL_PROVISION=true opts out. Pinned versions match .github/workflows/test.yml. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The `atmos terraform plan with github actions env` test asserted has_changes=false / "No Changes for", but it runs `atmos terraform plan mycomponent -s prod`, and `mycomponent` always creates one null_resource -> has_changes=true / "Resource Changes Found". It only passed because the now- untracked github-output.txt / github-step-summary.txt scratch files were previously committed with stale content containing those substrings, and file_contains is a substring check. Commit d7b97f4 correctly untracked those runtime artifacts, exposing the false positive in a clean CI checkout (where the files don't exist and the run writes only the real single-run output). Fix the assertions to the truthful output (verified against a real tofu plan and the CI failure log): has_changes=true and "Resource Changes Found for". Co-Authored-By: Claude Opus 4.8 <[email protected]>
The Codecov upload step fails on the linux Acceptance Tests job (repo-wide,
all branches): the default cli.codecov.io installer fetches Codecov's GPG
public key from Keybase to verify the downloaded binary, but that key is
currently 404'ing ("SELF-SIGNED PUBLIC KEY NOT FOUND"), so verification fails
with "gpg: Can't check signature: No public key" and the upload exits 1 under
fail_ci_if_error: true.
Set use_pypi: true so the Codecov CLI is installed from PyPI, which skips the
Keybase key fetch and signature check. See codecov/codecov-action#1955. Safe
to remove once Codecov restores the key.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
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: 2
🤖 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 @.github/workflows/test.yml:
- Line 77: The workflow uses floating GitHub Action tags (e.g.,
actions/setup-go@v6, actions/upload-artifact@v4, actions/download-artifact@v8,
hashicorp/setup-terraform@v4, opentofu/setup-opentofu@v2,
codecov/codecov-action@v7, azure/setup-helm@v4, reviewdog/action-tflint@v1,
InoUno/[email protected]) which can drift; replace each floating ref with the
corresponding pinned full commit SHA for every `uses:` entry (all occurrences of
those refs in the file) so the workflow refers to an immutable commit, updating
each `uses:` line to use the exact commit SHA for that action and keeping the
rest of the step intact.
- Around line 77-80: The workflow uses actions/setup-go@v6 with its default
caching enabled for PR runs; update the setup step that references
actions/setup-go@v6 (the step with id "go") to explicitly disable cache by
adding `cache: false` (or wrap cache usage behind a trusted-event condition so
PRs don't use the cache), and apply the same change to the other setup-go
occurrences referenced in the file (the block around lines 203-209) so PR
workflows will not use the setup-go cache.
🪄 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: 00b51c54-784f-448b-9a02-66cc24a1702f
📒 Files selected for processing (13)
.github/workflows/test.ymltests/cli_test.gotests/snapshots/TestCLICommands_atmos_describe_component_mock_-s_dev_(stack-names_example).stdout.goldentests/snapshots/TestCLICommands_atmos_describe_component_mock_-s_production_(stack-names_example).stdout.goldentests/snapshots/TestCLICommands_atmos_describe_component_vpc_-s_dev_(native-terraform_example).stdout.goldentests/snapshots/TestCLICommands_atmos_describe_component_vpc_-s_my-legacy-prod-stack.stdout.goldentests/snapshots/TestCLICommands_atmos_describe_component_vpc_-s_no-name-prod.stdout.goldentests/snapshots/TestCLICommands_atmos_describe_component_vpc_-s_production_(native-terraform_example).stdout.goldentests/snapshots/TestCLICommands_atmos_describe_config.stdout.goldentests/snapshots/TestCLICommands_secrets-masking_describe_config.stdout.goldentests/snapshots/TestCLICommands_secrets-masking_describe_stacks.stdout.goldentests/test-cases/native-ci-planfile.yamlwebsite/docs/stacks/hooks.mdx
✅ Files skipped from review due to trivial changes (6)
- tests/snapshots/TestCLICommands_secrets-masking_describe_config.stdout.golden
- tests/snapshots/TestCLICommands_secrets-masking_describe_stacks.stdout.golden
- tests/snapshots/TestCLICommands_atmos_describe_component_vpc_-s_no-name-prod.stdout.golden
- tests/snapshots/TestCLICommands_atmos_describe_component_vpc_-s_dev_(native-terraform_example).stdout.golden
- tests/snapshots/TestCLICommands_atmos_describe_component_mock_-s_dev_(stack-names_example).stdout.golden
- tests/snapshots/TestCLICommands_atmos_describe_component_vpc_-s_production_(native-terraform_example).stdout.golden
🚧 Files skipped from review as they are similar to previous changes (5)
- tests/test-cases/native-ci-planfile.yaml
- tests/snapshots/TestCLICommands_atmos_describe_component_mock_-s_production_(stack-names_example).stdout.golden
- website/docs/stacks/hooks.mdx
- tests/snapshots/TestCLICommands_atmos_describe_component_vpc_-s_my-legacy-prod-stack.stdout.golden
- tests/cli_test.go
🛑 Comments failed to post (2)
.github/workflows/test.yml (2)
77-77:
⚠️ Potential issue | 🟠 Major🧩 Analysis chain
🏁 Script executed:
#!/bin/bash # Verify unpinned action refs in workflow files rg -nP '^\s*uses:\s*[^@]+@v[0-9]+' .github/workflowsRepository: cloudposse/atmos
Length of output: 3983
Pin GitHub Action refs to commit SHAs (no floating
@v*tags) in.github/workflows/test.yml.Several
uses:entries still use floating tags, e.g.:
actions/setup-go@v6(lines 77, 205)actions/upload-artifact@v4(line 98)actions/download-artifact@v8(lines 133, 356, 420, 500)hashicorp/setup-terraform@v4(lines 156, 370, 519, 599)opentofu/setup-opentofu@v2(lines 163, 376, 526, 605)codecov/codecov-action@v7(line 257)azure/setup-helm@v4(line 435)reviewdog/action-tflint@v1(line 611)InoUno/[email protected](line 647)Pin each to a full commit SHA to prevent CI supply-chain drift.
🧰 Tools
🪛 zizmor (1.25.2)
[error] 77-77: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)
(unpinned-uses)
[error] 77-77: runtime artifacts potentially vulnerable to a cache poisoning attack (cache-poisoning): enables caching by default
(cache-poisoning)
🤖 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 @.github/workflows/test.yml at line 77, The workflow uses floating GitHub Action tags (e.g., actions/setup-go@v6, actions/upload-artifact@v4, actions/download-artifact@v8, hashicorp/setup-terraform@v4, opentofu/setup-opentofu@v2, codecov/codecov-action@v7, azure/setup-helm@v4, reviewdog/action-tflint@v1, InoUno/[email protected]) which can drift; replace each floating ref with the corresponding pinned full commit SHA for every `uses:` entry (all occurrences of those refs in the file) so the workflow refers to an immutable commit, updating each `uses:` line to use the exact commit SHA for that action and keeping the rest of the step intact.Source: Linters/SAST tools
77-80:
⚠️ Potential issue | 🟠 MajorDisable
actions/setup-gocache for PR runs.
actions/setup-go@v6has caching enabled by default; in.github/workflows/test.ymlthepull_requestworkflow uses it without acache:setting. Setcache: false(or enable cache only for trusted events).Suggested patch
- name: Set up Go uses: actions/setup-go@v6 with: go-version-file: "go.mod" + cache: false id: goAlso applies to: 203-209
🧰 Tools
🪛 zizmor (1.25.2)
[error] 77-77: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)
(unpinned-uses)
[error] 77-77: runtime artifacts potentially vulnerable to a cache poisoning attack (cache-poisoning): enables caching by default
(cache-poisoning)
🤖 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 @.github/workflows/test.yml around lines 77 - 80, The workflow uses actions/setup-go@v6 with its default caching enabled for PR runs; update the setup step that references actions/setup-go@v6 (the step with id "go") to explicitly disable cache by adding `cache: false` (or wrap cache usage behind a trusted-event condition so PRs don't use the cache), and apply the same change to the other setup-go occurrences referenced in the file (the block around lines 203-209) so PR workflows will not use the setup-go cache.
|
💥 This pull request now has conflicts. Could you fix it Erik Osterman (Cloud Posse) (@osterman)? 🙏 |
# Conflicts: # .github/workflows/test.yml
|
💥 This pull request now has conflicts. Could you fix it Erik Osterman (Cloud Posse) (@osterman)? 🙏 |
# Conflicts: # tests/fixtures/scenarios/native-ci/github-output.txt # tests/fixtures/scenarios/native-ci/github-step-summary.txt
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
|
These changes were released in v1.222.0-rc.0. |
what
--skip-hooksto the terraform command subtree. The flag (andATMOS_SKIP_HOOKS) moved off the global flag set ontoatmos terraformand its subcommands, so it no longer appears in the help of unrelated commands (auth,helmfile,atlantis,toolchain,about,secret, …). Lifecycle hooks only ever run onterraform plan/apply/deploy.tests/fixtures/scenarios/native-ci/{github-output,github-step-summary}.txtare runtime artifacts; gitignored and untracked (matching the newernative-ci-gha-planscenario).ATMOS_COMPONENTS_TERRAFORM_COMMAND=tofuvia a single test-harness default, gates every binary-invoking test on a precondition so a missing binary skips cleanly (instead of baking "executable file not found" into goldens), and sanitizes the harness-injected env var out of debug snapshots. A small parity set (terraform -help/-version passthrough) opts back into terraform.TestMaininstalls any missing pinned binary (terraform/tofu/packer/helmfile/helm) through the Atmos toolchain itself and prepends it toPATH— "install as necessary", so CI (which supplies them viasetup-*actions) downloads nothing while local runs become self-contained. No host binaries (brew, etc.) required.why
--skip-hookson every command was misleading — hooks only run on terraform. Mirrors the existing--github-token/toolchain scoping precedent.terraform; only tests change.references
--github-token/toolchain flag-scoping precedent inpkg/flags/global_builder.go.