Repository navigation
feat(terraform): add tflint hook and terraform lint command - #2675
Conversation
Add a `tflint` scanner hook kind that lints Terraform/OpenTofu on lifecycle events with zero configuration. Because `tflint --format=sarif` writes SARIF only to stdout (no file-output flag), the shared CommandEngine gains an opt-in `CaptureStdout` mode that redirects the subprocess's stdout into the existing ATMOS_OUTPUT_FILE side channel; stderr still streams. tflint then rides the shared sarif result handler, so findings render in the terminal, Atmos Pro, and — in CI — as a step summary, inline PR annotations, and a GitHub Code Scanning upload, identical to trivy/checkov/kics. Ships the example (examples/hooks-tflint), docs (kind: tflint section), changelog blog post, and a roadmap milestone. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
Dependency Review✅ No vulnerabilities or license issues found.Scanned Files
|
Resource Changes Found for
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds built-in TFLint scanning through hooks, workflow steps, and ChangesTerraform linting and TFLint integration
Estimated code review effort: 5 (Critical) | ~120 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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.
Actionable comments posted: 2
🧹 Nitpick comments (1)
pkg/hooks/command_engine_test.go (1)
113-182: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsolidate
runEngine/runEngineWithKindand table-drive the two new tests.
runEngineWithKind(lines 113-130) duplicatesrunEngine(lines 26-46) almost verbatim, differing only in howkindis built. Also,TestCommandEngine_CaptureStdoutWritesToOutputFileandTestCommandEngine_NoCaptureStdoutLeavesOutputFileEmptyare the same scenario varying onlyCaptureStdout— a good fit for a table-driven test. As per coding guidelines,**/*_test.go: "Use table-driven tests for testing multiple scenarios in Go."♻️ Suggested consolidation
func runEngine(t *testing.T, hook *Hook) (*Output, error) { t.Helper() kind := &Kind{ Name: "command", OnFailure: OnFailureWarn, Engine: &CommandEngine{}, } - resolved := kind.ResolveDefaults(hook) - ctx := &ExecContext{ - Hook: resolved, - Kind: kind, - AtmosConfig: &schema.AtmosConfiguration{ - TerraformDirAbsolutePath: t.TempDir(), - }, - Info: &schema.ConfigAndStacksInfo{ - Stack: "test-stack", - ComponentFromArg: "test-component", - }, - } - return kind.Engine.Run(ctx) + return runEngineWithKind(t, kind, hook) }-func TestCommandEngine_CaptureStdoutWritesToOutputFile(t *testing.T) { - ... -} - -func TestCommandEngine_NoCaptureStdoutLeavesOutputFileEmpty(t *testing.T) { - ... -} +func TestCommandEngine_CaptureStdout(t *testing.T) { + cases := []struct { + name string + captureStdout bool + body string + wantArtifact bool + }{ + {"captures stdout into output file", true, `{"runs":[{"tool":{"driver":{"name":"tflint"}}}]}`, true}, + {"leaves output file empty", false, "should not be captured", false}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + exe := testExePath(t) + kind := &Kind{Name: "command", OnFailure: OnFailureWarn, Engine: &CommandEngine{}, CaptureStdout: tc.captureStdout} + hook := &Hook{ + Kind: "command", + Command: exe, + Args: []string{"-test.run", "^$"}, + Env: map[string]string{ + "_ATMOS_TEST_ECHO_STDOUT": "1", + "_ATMOS_TEST_STDOUT_BODY": tc.body, + }, + } + out, err := runEngineWithKind(t, kind, hook) + require.NoError(t, err) + if tc.wantArtifact { + require.NotNil(t, out.Artifact) + assert.Equal(t, tc.body, string(out.Artifact.Body)) + } else { + assert.Nil(t, out.Artifact) + } + }) + } +}🤖 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/command_engine_test.go` around lines 113 - 182, `runEngineWithKind` is duplicating `runEngine` with only the `Kind` setup differing, so consolidate the shared setup into one helper and let both callers reuse it via `CommandEngine`/`ExecContext` preparation. Also combine `TestCommandEngine_CaptureStdoutWritesToOutputFile` and `TestCommandEngine_NoCaptureStdoutLeavesOutputFileEmpty` into a table-driven test that varies only `CaptureStdout` on `Kind` while keeping the shared `Hook`, `testExePath`, and stdout body setup in one place.Source: Coding guidelines
🤖 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 `@examples/hooks-tflint/stacks/deploy/test.yaml`:
- Around line 16-20: The hook event name is using the hyphenated form instead of
the documented dotted form, so the tflint hook in the `hooks.lint.events` list
will not trigger as intended. Update the event value in this test fixture to
match the same `after.terraform.plan` identifier used elsewhere in the PR,
keeping the change localized to the `hooks` configuration for the `lint` entry.
In `@pkg/hooks/command_engine.go`:
- Around line 216-234: The hook stdout capture failure in runSubprocess
currently uses a dynamic fmt.Errorf message, which violates the static error
requirement. Update the os.Create failure path to return the appropriate
predefined error from errors/errors.go using the same errUtils.Build style used
in resolveBinaryOnPath, and preserve the underlying create error as the wrapped
cause. Keep the fix localized to runSubprocess and ensure the returned error is
constructed from a static error identifier rather than a raw formatted string.
---
Nitpick comments:
In `@pkg/hooks/command_engine_test.go`:
- Around line 113-182: `runEngineWithKind` is duplicating `runEngine` with only
the `Kind` setup differing, so consolidate the shared setup into one helper and
let both callers reuse it via `CommandEngine`/`ExecContext` preparation. Also
combine `TestCommandEngine_CaptureStdoutWritesToOutputFile` and
`TestCommandEngine_NoCaptureStdoutLeavesOutputFileEmpty` into a table-driven
test that varies only `CaptureStdout` on `Kind` while keeping the shared `Hook`,
`testExePath`, and stdout body setup in one place.
🪄 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: fa854da5-d496-4731-bbd6-341c3d30714b
📒 Files selected for processing (16)
cmd/terraform/hooks_kinds.goexamples/hooks-tflint/README.mdexamples/hooks-tflint/atmos.yamlexamples/hooks-tflint/components/terraform/bucket/main.tfexamples/hooks-tflint/components/terraform/bucket/variables.tfexamples/hooks-tflint/components/terraform/bucket/versions.tfexamples/hooks-tflint/stacks/deploy/test.yamlpkg/hooks/command_engine.gopkg/hooks/command_engine_test.gopkg/hooks/kind.gopkg/hooks/kinds/tflint/kind.gopkg/hooks/kinds/tflint/kind_test.gopkg/hooks/main_test.gowebsite/blog/2026-07-01-tflint-hook-kind.mdxwebsite/docs/stacks/hooks.mdxwebsite/src/data/roadmap.js
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2675 +/- ##
==========================================
+ Coverage 81.72% 81.78% +0.05%
==========================================
Files 1779 1791 +12
Lines 170835 172737 +1902
==========================================
+ Hits 139615 141270 +1655
- Misses 23493 23667 +174
- Partials 7727 7800 +73
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
…ue-forward docs - Use static errUtils.ErrCreateFile (new sentinel) for the stdout-capture create failure instead of a raw fmt.Errorf (CodeRabbit; CLAUDE.md mandates static errors). - examples/hooks-tflint: fire the hook on `before.terraform.init` (dotted, matching sibling examples) so linting fails fast before any init/plan work. - examples/hooks-tflint: drop the fake AWS provider + S3 bucket; a linter needs no cloud provider or credentials. Component is now a provider-free `terraform_data` resource (renamed bucket -> example) that lints and plans fully offline; an intentionally-unused variable yields a deterministic finding. - Docs/blog: lead with the value a linter brings — code consistency, enforced conventions, and hygiene (unused declarations, deprecated syntax) — and use the before-init event. Co-Authored-By: Claude Opus 4.8 (1M context) <[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)
website/docs/stacks/hooks.mdx (1)
856-857: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winScanner count is now stale.
This section still says "the three built-in SARIF scanners —
checkov,trivy,kics— all participate", but Line 248 in this same doc was correctly updated to list four (trivy,checkov,kics,tflint). Update this line to includetflinttoo, for consistency.📝 Proposed fix
-the hook or the terraform command. Outside CI they no-op. Findings derive from the -tool's SARIF, so the three built-in SARIF scanners — `checkov`, `trivy`, `kics` — -all participate; `infracost` (cost, not findings) does not. +the hook or the terraform command. Outside CI they no-op. Findings derive from the +tool's SARIF, so the four built-in SARIF scanners — `checkov`, `trivy`, `kics`, +`tflint` — all participate; `infracost` (cost, not findings) does not.🤖 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/docs/stacks/hooks.mdx` around lines 856 - 857, The scanner list in the hooks documentation is stale: the sentence in the SARIF section still names only three built-in scanners. Update the text in the relevant docs block to match the current set used elsewhere in this file by including `tflint` alongside `checkov`, `trivy`, and `kics`, keeping the wording consistent with the existing SARIF scanner references.
🤖 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 `@website/docs/stacks/hooks.mdx`:
- Around line 856-857: The scanner list in the hooks documentation is stale: the
sentence in the SARIF section still names only three built-in scanners. Update
the text in the relevant docs block to match the current set used elsewhere in
this file by including `tflint` alongside `checkov`, `trivy`, and `kics`,
keeping the wording consistent with the existing SARIF scanner references.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f0e4ef13-b0b6-4401-a616-4c58a7e0ecbe
📒 Files selected for processing (9)
errors/errors.goexamples/hooks-tflint/README.mdexamples/hooks-tflint/components/terraform/example/main.tfexamples/hooks-tflint/components/terraform/example/variables.tfexamples/hooks-tflint/components/terraform/example/versions.tfexamples/hooks-tflint/stacks/deploy/test.yamlpkg/hooks/command_engine.gowebsite/blog/2026-07-01-tflint-hook-kind.mdxwebsite/docs/stacks/hooks.mdx
🚧 Files skipped from review as they are similar to previous changes (2)
- examples/hooks-tflint/stacks/deploy/test.yaml
- pkg/hooks/command_engine.go
Adds a tflint hook (kind: tflint) to the native-ci-e2e scenario so tflint is exercised end-to-end in CI at parity with checkov/trivy/kics — its stdout SARIF flows through the native-CI outputs (step summary, PR annotations, Code Scanning). The hook fires on before-terraform-init (a linter should fail fast), is scoped with --filter=tflint_target.tf, and auto-installs via dependencies.tools (tflint 0.59.1, resolved from the aqua-public registry like checkov). tflint_target.tf declares an unused local that trips the builtin terraform_unused_declarations rule; it is inert for Terraform so it still applies cleanly against the Floci emulator. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool. What Enabling Code Scanning Means:
For more information about GitHub Code Scanning, check out the documentation. |
1 similar comment
|
You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool. What Enabling Code Scanning Means:
For more information about GitHub Code Scanning, check out the documentation. |
|
Note SHA Pin Verification Passed ✅All 133 third-party action reference(s) are SHA-pinned (128 tag-verified, 5 branch-pinned). |
|
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 |
The numbered-list continuation lines in the terraform-lint auth-disabled fix writeup used 3-space indentation (aligned to the "1. " marker width), which violates this repo's .editorconfig indent_size=2 rule for *.md files and failed the native `atmos validate editorconfig --affected` check in CI. Verified locally with the same command CI runs: atmos validate editorconfig --affected --base origin/main Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
💥 This pull request now has conflicts. Could you fix it Erik Osterman (Cloud Posse) (@osterman)? 🙏 |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
internal/exec/validate_stacks.go (1)
288-303: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse
lo.Uniqfor the validation errors.
github.com/samber/lois already a dependency and this package already uses it, sovalidationErrorMessages = lo.Uniq(validationErrorMessages)avoids the small redundant helper while keeping first-seen order.🤖 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 `@internal/exec/validate_stacks.go` around lines 288 - 303, Replace the local deduplication helper `dedupeStrings` with `lo.Uniq` when processing `validationErrorMessages`, preserving first-seen order and removing the now-unused helper.cmd/terraform/lint.go (1)
240-285: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winPer-stack-file
OnProgressupdates may flood CI logs on large repos.
errOptions.OnProgressfires once per stack file (before filtering). In non-TTY mode — the primary environment this PR's CI-facing lint command targets —spinner.Updatefalls back toui.Info(message)per call, so a monorepo with hundreds of stack files prints hundreds of "Discovering..." lines to CI logs. Consider throttling (e.g. every Nth file, or a time-based interval) or skipping progress reporting entirely when not a TTY.🤖 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 `@cmd/terraform/lint.go` around lines 240 - 285, Throttle or disable the per-stack-file progress reporting configured in terraformLintDescribeStacks, especially for non-TTY output where spinner.Update emits one CI log line per callback. Preserve progress feedback for interactive terminals while limiting updates to a reasonable interval or batch size, and ensure the final success/error messages remain unchanged.pkg/hooks/sarif/normalize.go (1)
266-296: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
githubBlobBaseURLduplicated verbatim acrosshooks/sarifandscanners/sarif. Same consts, samesync.Onceguard, same body — one shared root cause: this GitHub Actions URL-construction logic was written twice instead of once.
pkg/hooks/sarif/normalize.go#L266-L296: extract this block to a small shared helper (e.g. a common internal package importable by bothpkg/hooks/sarifandpkg/scanners/sarif) and have this file call it.pkg/scanners/sarif/normalize.go#L266-L295: remove this identical copy and call the same shared helper instead of re-declaring the consts/sync.Once/function.🤖 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/sarif/normalize.go` around lines 266 - 296, The GitHub Actions blob URL logic is duplicated across both SARIF normalizers. Extract the constants, sync.Once environment binding, and URL construction from githubBlobBaseURL into a shared internal helper importable by both packages; update pkg/hooks/sarif/normalize.go lines 266-296 to call it, and remove the duplicate declarations and implementation from pkg/scanners/sarif/normalize.go lines 266-295 so its githubBlobBaseURL flow uses the same helper.
🤖 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 `@pkg/scanners/tflint/tflint.go`:
- Around line 25-36: Update tflint.DefaultArgs() to replace the positional
$ATMOS_COMPONENT_PATH argument with --chdir=$ATMOS_COMPONENT_PATH. Adjust the
corresponding default-argument assertions in the TFLint scanner and hook kind
tests to expect the new flag form.
In `@pkg/ui/spinner/spinner.go`:
- Around line 329-330: Update the width field comments in both
dynamicSpinnerModel and manualSpinnerModel to reflect that width is initialized
synchronously via initialWidth(), rather than remaining zero until the first
resize event; keep the comments consistent with spinnerModel.width.
---
Nitpick comments:
In `@cmd/terraform/lint.go`:
- Around line 240-285: Throttle or disable the per-stack-file progress reporting
configured in terraformLintDescribeStacks, especially for non-TTY output where
spinner.Update emits one CI log line per callback. Preserve progress feedback
for interactive terminals while limiting updates to a reasonable interval or
batch size, and ensure the final success/error messages remain unchanged.
In `@internal/exec/validate_stacks.go`:
- Around line 288-303: Replace the local deduplication helper `dedupeStrings`
with `lo.Uniq` when processing `validationErrorMessages`, preserving first-seen
order and removing the now-unused helper.
In `@pkg/hooks/sarif/normalize.go`:
- Around line 266-296: The GitHub Actions blob URL logic is duplicated across
both SARIF normalizers. Extract the constants, sync.Once environment binding,
and URL construction from githubBlobBaseURL into a shared internal helper
importable by both packages; update pkg/hooks/sarif/normalize.go lines 266-296
to call it, and remove the duplicate declarations and implementation from
pkg/scanners/sarif/normalize.go lines 266-295 so its githubBlobBaseURL flow uses
the same helper.
🪄 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: 1492a94b-1bdb-4f2e-a536-2484b2289aee
📒 Files selected for processing (43)
cmd/terraform/lint.gocmd/terraform/lint_test.gointernal/exec/describe_stacks.gointernal/exec/describe_stacks_component_processor.gointernal/exec/describe_stacks_component_processor_auth_test.gointernal/exec/stack_processor_utils.gointernal/exec/terraform_affected.gointernal/exec/validate_stacks.gointernal/exec/yaml_func_terraform_state.gointernal/exec/yaml_func_terraform_state_yq_defaults_test.gointernal/exec/yaml_func_utils.gointernal/exec/yaml_func_utils_lenient_test.gopkg/datafetcher/schema/atmos/config/1.0.jsonpkg/datafetcher/schema/atmos/manifest/1.0.jsonpkg/hooks/command_engine.gopkg/hooks/kinds/tflint/kind_test.gopkg/hooks/sarif/handler.gopkg/hooks/sarif/handler_test.gopkg/hooks/sarif/markdown.gopkg/hooks/sarif/markdown_test.gopkg/hooks/sarif/normalize.gopkg/hooks/sarif/normalize_test.gopkg/hooks/sarif/sarif_test.gopkg/scanners/runner.gopkg/scanners/runner_test.gopkg/scanners/sarif/handler.gopkg/scanners/sarif/handler_test.gopkg/scanners/sarif/markdown.gopkg/scanners/sarif/markdown_test.gopkg/scanners/sarif/normalize.gopkg/scanners/sarif/normalize_test.gopkg/scanners/sarif/rich_test.gopkg/scanners/sarif/sarif.gopkg/scanners/sarif/sarif_test.gopkg/scanners/tflint/command.gopkg/scanners/tflint/command_test.gopkg/scanners/tflint/tflint.gopkg/scanners/tflint/tflint_test.gopkg/scanners/types.gopkg/schema/schema.gopkg/terraform/generate/file_generator.gopkg/terraform/generate/file_generator_test.gopkg/ui/spinner/spinner.go
🚧 Files skipped from review as they are similar to previous changes (9)
- pkg/hooks/command_engine.go
- pkg/scanners/types.go
- internal/exec/terraform_affected.go
- pkg/scanners/sarif/normalize_test.go
- pkg/scanners/runner_test.go
- pkg/scanners/sarif/sarif.go
- pkg/scanners/runner.go
- pkg/scanners/sarif/handler_test.go
- pkg/scanners/sarif/sarif_test.go
# Conflicts: # internal/exec/yaml_func_utils.go
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 `@pkg/auth/config_helpers.go`:
- Around line 178-183: Update the identity selection logic around
resolveComponentIdentityMarker to resolve global identity names through
IdentityCaseMap rather than an exact map lookup, with the appropriate fallback
when no case-insensitive match exists. Use the resolved canonical name when
reading and writing normalizedIdentities so markers such as “IDENTITY” correctly
target the configured “identity” entry and preserve both true and false
selections.
🪄 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: e7cde610-9e6f-4fe4-a98c-1d9ec28fc510
📒 Files selected for processing (4)
errors/errors.gointernal/exec/stack_processor_utils.gointernal/exec/yaml_func_utils.gopkg/auth/config_helpers.go
🚧 Files skipped from review as they are similar to previous changes (2)
- internal/exec/stack_processor_utils.go
- internal/exec/yaml_func_utils.go
…directory arg
TFLint 0.47+ removed support for positional [FILE or DIR...] arguments
("Command line arguments support was dropped in v0.47. Use --chdir or
--filter instead."). CI pins tflint 0.59.1, so every lint run was hitting
this error instead of producing real findings. Verified directly against
0.59.1: the positional form errors immediately, --chdir works.
Fixing this surfaced a second bug: --chdir reports paths relative to the
scanning process's own cwd rather than the target directory, so the
Location column's component-relative shortening (which only handled
absolute paths) stopped working. shortenToComponent now resolves relative
paths against the process cwd before comparing.
Also fixes two stale spinner.go field comments (still said width was
"0 until the first resize event" after initialWidth() started seeding it
synchronously at construction).
Addresses CodeRabbit review comments on PR #2675.
atmos validate stacks was rejecting the native-ci-e2e fixture's `kind: tflint` hook with "value must be one of \"store\", \"command\", ...\" ci.download\"" — the manifest and stack-config JSON schemas' hooks.<name>.kind enum was never updated when the tflint hook kind was added, so CI's [native ci] terraform plan job failed at the validate-stacks step before ever reaching the lint itself.
…inal color test pkg/runner/step/tflint_test.go asserted a "--chdir" before "--format=sarif" argument order that never matched pkg/scanners/tflint.DefaultArgs()'s actual output (format first) — these two tests were failing on both the linux and macos acceptance-test jobs. TestHandler_RichTerminalBodyIncludesSourceExcerpt asserted a literal, uncolored "[tflint] variables.tf:2:10" substring, but richStyle wraps each segment in its own ANSI codes when the terminal's color profile is detected as color-capable — which some CI runners' non-TTY output apparently is. Force NO_COLOR for that test so the assertion is hermetic instead of environment-dependent.
resolveComponentIdentityMarker looked up globalAuth.Identities[identityName] with the component marker's own casing. Viper lower-cases config keys during load, so a marker spelled "IDENTITY" never matched a globally-configured "identity" entry, even though they're the same identity — the marker was incorrectly treated as undefined (dropped if default:false, rejected if default:true). Resolve through globalAuth.IdentityCaseMap when an exact match misses, and write the marker's outcome back under the identity's own canonical key so it overrides the existing entry instead of creating a separate, differently-cased one. Extracted as resolveGlobalIdentityKey to keep the caller flat (nestif).
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 `@pkg/auth/config_helpers_test.go`:
- Around line 350-395: Update the “true marker” and “false marker” tests in the
MergeComponentAuthFromConfig coverage to use a mixed-case global identity key
such as “Identity”, with IdentityCaseMap mapping “identity” to “Identity” and
the component configuration retaining the lowercase marker. Assert the marker
updates mergedAuth.Identities["Identity"], preserves its Kind, applies both
boolean values through a table-driven test, and does not create
mergedAuth.Identities["identity"].
🪄 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: ffb7c23d-f136-4a53-8ea0-2c79e8e1c80d
📒 Files selected for processing (2)
pkg/auth/config_helpers.gopkg/auth/config_helpers_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- pkg/auth/config_helpers.go
The test hardcoded Unix-style "/repo/..." paths for both file and componentDir. filepath.IsAbs requires a volume name (drive letter or UNC) on Windows, so these strings aren't absolute there — the component-relative shortening locationCell/shortenToComponent exercises never engaged, and every subtest returned the full path unchanged instead of the shortened form, failing on windows-latest. Build componentDir/file from t.TempDir() (real, platform-correct absolute paths), matching the pattern already used correctly by the adjacent TestLocationCell_ComponentRelative_ChdirRelativePath test.
TestMergeComponentAuthFromConfig_DefaultOnlyMarkerCaseInsensitiveMatch used
IdentityCaseMap["identity"] == "identity", making case-map resolution
indistinguishable from an exact/already-lowercase match — an exact-match
regression in resolveGlobalIdentityKey wouldn't have failed this test.
Use a genuinely mixed-case global identity key ("Identity", distinct from
both the IdentityCaseMap's lowercase key and the marker's own casing), so
the assertion can only pass by actually resolving through IdentityCaseMap.
Converted to table-driven per the repo's Go test convention.
Addresses CodeRabbit review comment on PR #2675.
|
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.224.0. |
what
tflinthook kind that lints Terraform/OpenTofu on lifecycle events with zero configuration (kind: tflint, defaults toafter.terraform.plan).atmos terraform lintCLI command (--all/--affected/single-component targeting) that runs TFLint once per unique component even when it's used by multiple stacks, instead of repeating the same lint for every stack.CommandEnginean opt-inCaptureStdoutmode: sincetflint --format=sarifwrites SARIF only to stdout (no file-output flag), the engine redirects the tool's stdout into the existingATMOS_OUTPUT_FILEside channel.sarifresult handler so findings render in the terminal, Atmos Pro, and — in CI — as a step summary, inline PR annotations, and a GitHub Code Scanning upload, exactly like the existing scanner kinds.examples/hooks-tflint, akind: tflintdocs section instacks/hooks.mdx,atmos terraform lintCLI docs, a changelog blog post, and a roadmap milestone.why
terraform validatemisses lint-class problems (unused declarations, deprecated syntax, invalid provider/instance settings); Atmos had built-in security/cost scanner kinds but no linter kind.references
kind: tflint)examples/hooks-tflintSummary by CodeRabbit
atmos terraform lintwith--all/--affected,--stack,--error-mode,--max-findings, andmarkdown/richoutput.tflinthook kind and atflintworkflow step that consumes SARIF emitted to stdout.argsfield in addition towith.--identity=falseTerraform lint to avoid evaluating unauthenticated YAML/function values.tflint/Terraform lint docs plus blog content and runnable hook/lint examples.