close
Skip to content

feat: extend autodiscover.ignore_paths to targeted -d commands#6466

Open
emanuelbesliu wants to merge 5 commits into
runatlantis:mainfrom
emanuelbesliu:feat/ignore-paths-targeted-commands
Open

feat: extend autodiscover.ignore_paths to targeted -d commands#6466
emanuelbesliu wants to merge 5 commits into
runatlantis:mainfrom
emanuelbesliu:feat/ignore-paths-targeted-commands

Conversation

@emanuelbesliu
Copy link
Copy Markdown

Summary

Extends autodiscover.ignore_paths to also filter targeted commands (atlantis plan -d <path>, atlantis apply -d <path>) when the path has no explicit project configuration.

Fixes #6460

Problem

In multi-instance setups where each Atlantis instance manages a different directory subtree (e.g., environments/prod/ vs environments/nonprod/), autodiscover.ignore_paths correctly prevents auto-discovery of projects in ignored paths. However, when a user runs a targeted command like atlantis apply -d environments/prod/test, both instances would react because the targeted command path bypassed ignore_paths filtering.

Solution

Added isAutoDiscoverPathIgnored checks in buildProjectPlanCommand and buildProjectCommand — the two functions that handle targeted -d commands. The check:

  1. Parses the repo config to determine if the targeted path has an explicit project entry
  2. If it does → allows the command (explicit config takes precedence)
  3. If it doesn't → checks ignore_paths and silently skips if matched

This mirrors the existing semantics in getMergedProjectCfgs and buildAllProjectCommandsByPlan, where ignore_paths only filters auto-discovered (non-configured) paths.

Why not in buildProjectCommandCtx?

The check is intentionally placed in the caller functions rather than the shared buildProjectCommandCtx because the latter is also called from buildAllProjectCommandsByPlan which has its own filtering logic that preserves explicitly-planned paths tracked in PullStatus. Putting the check there would break that behavior.

Tests

  • TestDefaultProjectCommandBuilder_BuildTargetedCommand_IgnorePaths — global config ignore_paths blocks targeted plan/apply
  • TestDefaultProjectCommandBuilder_BuildTargetedCommand_IgnorePathsRepoCfg — repo-level ignore_paths blocks targeted commands
  • TestDefaultProjectCommandBuilder_BuildTargetedCommand_IgnorePathsExplicitProjectAllowed — explicit project config overrides ignore_paths

Docs

Updated repo-level-atlantis-yaml.md and server-side-repo-config.md to document the broader scope of ignore_paths.

Previously, autodiscover.ignore_paths only filtered projects during
auto-discovery (plan-all) and apply-all. Targeted commands like
'atlantis plan -d <path>' and 'atlantis apply -d <path>' bypassed
this filtering entirely, causing issues in multi-instance setups
where each Atlantis instance manages a different directory subtree.

This change adds ignore_paths checking to buildProjectPlanCommand and
buildProjectCommand (the targeted command handlers). When a user runs
a targeted command against a path that matches ignore_paths and has no
explicit project configuration in atlantis.yaml, the command is silently
skipped (returns no projects).

Paths with explicit project config are NOT affected — the ignore only
applies to paths that would otherwise be auto-discovered.

Fixes runatlantis#6460

Signed-off-by: emanuelbesliu <32497562+emanuelbesliu@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 12, 2026 08:49
@dosubot dosubot Bot added docs Documentation feature New functionality/enhancement go Pull requests that update Go code labels May 12, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Extends autodiscover.ignore_paths behavior so targeted -d plan/apply commands are ignored when the target dir has no explicit project configuration, helping multi-instance Atlantis deployments avoid reacting to out-of-scope paths.

Changes:

  • Added ignore_paths filtering for targeted plan -d and other targeted commands when there is no explicit project config for the target dir.
  • Added unit tests covering global and repo-level ignore_paths behavior and the “explicit project overrides ignore_paths” case.
  • Updated documentation to clarify that ignore_paths also applies to targeted -d commands when the path is not explicitly configured.

Reviewed changes

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

File Description
server/events/project_command_builder.go Applies ignore_paths filtering to targeted command builders (plan + non-plan targeted commands).
server/events/project_command_builder_test.go Adds tests for targeted command behavior with global/repo-level ignore_paths and explicit-project override.
runatlantis.io/docs/server-side-repo-config.md Documents that ignore_paths also affects targeted -d commands when no explicit project config exists.
runatlantis.io/docs/repo-level-atlantis-yaml.md Expands ignore_paths docs to include targeted plan/apply -d semantics and multi-instance motivation.

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_test.go
…DiscoverModeEnabled

Address Copilot review feedback on PR runatlantis#6466:
- Extract duplicated ignore_paths logic into shouldIgnoreTargetedDir()
- Gate the check behind autoDiscoverModeEnabled() for consistency
- Add targeted apply -d assertions to repo-level config test

Signed-off-by: emanuelbesliu <32497562+emanuelbesliu@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

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

Comment thread server/events/project_command_builder.go
Comment thread server/events/project_command_builder.go Outdated
Comment thread server/events/project_command_builder.go
Comment thread server/events/project_command_builder_test.go
- Skip ignore_paths check when -d uses glob patterns
- Fix doc comment to reference repo config file generically
- Add apply assertions to ExplicitProjectAllowed test

Signed-off-by: emanuelbesliu <32497562+emanuelbesliu@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

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

Comment thread server/events/project_command_builder.go
Comment thread runatlantis.io/docs/repo-level-atlantis-yaml.md Outdated
Update docs to reflect that ignore_paths filtering covers all targeted
-d commands (plan, apply, import, state rm, etc.), not just plan/apply.

Signed-off-by: emanuelbesliu <32497562+emanuelbesliu@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

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

Comment thread server/events/project_command_builder.go
Comment thread runatlantis.io/docs/repo-level-atlantis-yaml.md Outdated
Comment thread runatlantis.io/docs/server-side-repo-config.md Outdated
Signed-off-by: emanuelbesliu <32497562+emanuelbesliu@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation feature New functionality/enhancement go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

autodiscover.ignore_paths should filter targeted -d commands, not just autodiscovery

2 participants