Skip to content

fix: filter apply plans through autodiscover.ignore_paths#6332

Closed
jholm117 wants to merge 4 commits into
runatlantis:mainfrom
jholm117:fix/ignore-paths-apply
Closed

fix: filter apply plans through autodiscover.ignore_paths#6332
jholm117 wants to merge 4 commits into
runatlantis:mainfrom
jholm117:fix/ignore-paths-apply

Conversation

@jholm117

@jholm117 jholm117 commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Summary

autodiscover.ignore_paths is correctly respected during atlantis plan (via getMergedProjectCfgsisAutoDiscoverPathIgnored), but atlantis apply (without -p) uses PendingPlanFinder.Find() which only filters .terragrunt-cache/ directories. This means apply discovers and attempts to apply .tfplan files in paths that should be ignored (e.g. .terraform/modules/).

Changes

  • server/events/project_command_builder.gobuildAllProjectCommandsByPlan(): After PendingPlanFinder.Find() returns plans, load the repo config from the default workspace dir and filter plans through isAutoDiscoverPathIgnored() before building command contexts.

  • server/events/project_command_builder.goisAutoDiscoverPathIgnored(): Fix global config shadowing repo-level ignore_paths. The default global config always sets AutoDiscover (with mode=auto, no IgnorePaths), which caused the function to short-circuit before checking the repo's atlantis.yaml. Changed to only prefer global config when it explicitly sets IgnorePaths.

  • server/events/project_command_builder_test.go: Add two tests:

    • TestDefaultProjectCommandBuilder_BuildMultiApply_IgnorePathsignore_paths via global config
    • TestDefaultProjectCommandBuilder_BuildMultiApply_IgnorePathsRepoCfgignore_paths via repo-level atlantis.yaml (no global config)

    Both set up a directory structure with plans in project1/, project2/, and .terraform/modules/some_module/test-deployment/, and verify only the 2 non-ignored projects get apply commands.

Fixes #6325

@jholm117 jholm117 force-pushed the fix/ignore-paths-apply branch 2 times, most recently from e636edb to 9a5a32d Compare March 24, 2026 13:26
@jholm117 jholm117 marked this pull request as ready for review March 24, 2026 17:27
Copilot AI review requested due to automatic review settings March 24, 2026 17:28
@dosubot dosubot Bot added bug Something isn't working go Pull requests that update Go code labels Mar 24, 2026
@jholm117 jholm117 force-pushed the fix/ignore-paths-apply branch from 9a5a32d to a9dbddf Compare March 24, 2026 17:34

Copilot AI 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.

Pull request overview

This PR fixes a behavioral inconsistency where atlantis apply (without -p) could discover and attempt to apply .tfplan files from paths that should be excluded by autodiscover.ignore_paths, even though atlantis plan already respects those ignore rules.

Changes:

  • Add autodiscover.ignore_paths filtering to the multi-apply path (buildAllProjectCommandsByPlan) after pending plans are discovered.
  • Adjust isAutoDiscoverPathIgnored to avoid default/global autodiscover config unintentionally suppressing repo-level ignore_paths.
  • Add tests to ensure ignored paths are not applied for both global-config and repo-config ignore_paths scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
server/events/project_command_builder.go Filters pending plans during multi-apply via ignore_paths; updates global-vs-repo ignore_paths precedence logic.
server/events/project_command_builder_test.go Adds multi-apply tests asserting plans under ignored paths (e.g., .terraform/**) do not generate apply contexts.

Comment thread server/events/project_command_builder.go Outdated
Comment thread server/events/project_command_builder.go Outdated
Comment thread server/events/project_command_builder.go Outdated
jholm117 and others added 2 commits April 16, 2026 11:58
buildAllProjectCommandsByPlan() used PendingPlanFinder.Find() which only
filtered .terragrunt-cache/ directories. This meant atlantis apply (without
-p) would discover and attempt to apply .tfplan files in paths that should
be ignored per autodiscover.ignore_paths (e.g. .terraform/modules/).

Fix: after PendingPlanFinder.Find() returns, load the repo config and filter
plans through isAutoDiscoverPathIgnored() before building commands. This
mirrors the filtering already done in the plan path (getMergedProjectCfgs).

Also fix isAutoDiscoverPathIgnored() to fall through to repo-level config
when the global config has AutoDiscover set but no IgnorePaths. Previously,
the default global config (which always sets AutoDiscover with mode=auto)
would shadow repo-level ignore_paths from atlantis.yaml.

Fixes: runatlantis#6325

Signed-off-by: Jeff Holm <jholm117@gmail.com>
- Use IgnorePaths != nil instead of len() > 0 so an explicitly empty
  global ignore_paths can override repo-level config
- Skip explicitly configured project dirs when filtering apply plans,
  matching the plan-path behavior in getMergedProjectCfgs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Jeffrey Holm <jeff.holm@scale.com>
@jholm117 jholm117 force-pushed the fix/ignore-paths-apply branch from e2481df to d5ba14c Compare April 16, 2026 16:03
jholm117 added a commit to jholm117/atlantis that referenced this pull request Apr 16, 2026
Both buildAllCommandsByCfg and buildAllProjectCommandsByPlan were
doing the same HasRepoCfg then ParseRepoCfg sequence. Extract it
into a single helper so the logic lives in one place.

Addresses review feedback on runatlantis#6332.
lukemassa
lukemassa previously approved these changes May 9, 2026

@lukemassa lukemassa 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.

LGTM!

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 9, 2026
Signed-off-by: Rui Chen <rui@chenrui.dev>
Signed-off-by: Rui Chen <rui@chenrui.dev>
@chenrui333

Copy link
Copy Markdown
Member

Superseded by #6397

@chenrui333 chenrui333 closed this Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update Go code lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

autodiscover.ignore_paths not respected during apply

4 participants