Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add flag to allow enable/disable project autodiscovery #3279

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const (
AllowForkPRsFlag = "allow-fork-prs"
AllowRepoConfigFlag = "allow-repo-config"
AtlantisURLFlag = "atlantis-url"
AutoDiscover = "autodiscover"
AutomergeFlag = "automerge"
ParallelPlanFlag = "parallel-plan"
ParallelApplyFlag = "parallel-apply"
Expand Down
92 changes: 92 additions & 0 deletions runatlantis.io/docs/autodiscover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Autodiscover
Atlantis can be configured to automatically discover Terraform projects in a repository.


## How To Enable
By default the autodiscover is enabled, but you can "enforce it":
1. Server Side:
```yaml
repo:
...
autodiscover:
enabled: true
...
```
1. Repo side `atlantis.yaml` file:
```yaml
version: 3
autodiscover:
enabled: true
projects:
- dir: .
```
:::tip NOTE
You need allow override in the server side configuration if you would like to disable it for a specific repo in the repo side configuration:
```yaml
repo:
...
allowed_overrides: [autodiscover]
...
```
::::

## How to Disable
You can disable it globally for each repo in the server side.
1. Server Side:
```yaml
repo:
...
autodiscover:
enabled: false
...
```
or for a specific repo in the repo side `atlantis.yaml` file:
1. Repo side `atlantis.yaml` file:
```yaml
version: 3
autodiscover:
enabled: false
projects:
- dir: .
```
:::tip NOTE
You need allow override in the server side configuration if you would like to disable it for a specific repo in the repo side configuration:
```yaml
repo:
...
allowed_overrides: [autodiscover]
...
```
::::
## Cases
### Multiple Projects
Atlantis will discover all Terraform projects in a repository. For example, if you have a repository with the following structure:
```
|── prod
│ └── project1
│ └── main.tf
| └── project2
│ └── main.tf
```
Atlantis will discover both `project1` and `project2` and create a plan for each one.

### Multi Server
Image that you have a mono repository with multiples stages, and for each stage you have a different Atlantis server. You can configure each server to discover only the projects that are related to it. For example, if you have a repository with the following structure:
```
|── prod
│ └── project1
│ └── main.tf
|── stage
|── test
└── project1
└── main.tf
```
You can create the atlantis.yaml dynamically in each server to discover only the projects that are related to it. For example, the `prod` server side configuration will have the:
```yaml
repos:
- id: /.*/
apply_requirements: [approved, mergeable]
repo_config_file: atlantis-prod.yaml
```

and you can use a [pre_workflow_hooks](./pre-workflow-hooks.md) to create the `atlantis-prod.yaml` file dynamically.
11 changes: 11 additions & 0 deletions runatlantis.io/docs/repo-level-atlantis-yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ need to be defined.
```yaml
version: 3
automerge: true
autodiscover:
enabled: true
delete_source_branch_on_merge: true
parallel_plan: true
parallel_apply: true
Expand Down Expand Up @@ -148,6 +150,15 @@ projects:
This will stop Atlantis automatically running plan when `project1/` is updated
in a pull request.

### Disabling Autodiscover
```
version: 3
autodiscover:
enabled: false
```

This will stop Atlantis automatically discovering projects in a repo.

### Run plans and applies in parallel

```yaml
Expand Down
7 changes: 6 additions & 1 deletion runatlantis.io/docs/server-side-repo-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ repos:

# allowed_overrides specifies which keys can be overridden by this repo in
# its atlantis.yaml file.
allowed_overrides: [apply_requirements, workflow, delete_source_branch_on_merge, repo_locking, custom_policy_check]
allowed_overrides: [apply_requirements, workflow, delete_source_branch_on_merge, repo_locking, custom_policy_check, autodiscover]

# allowed_workflows specifies which workflows the repos that match
# are allowed to select.
Expand Down Expand Up @@ -88,6 +88,10 @@ repos:
# policy_check defines if policy checking should be enable on this repository.
policy_check: false

# autodiscover defines if atlantis should automatically discover projects in this repository.
autodiscover:
enabled: true

# id can also be an exact match.
- id: github.com/myorg/specific-repo

Expand Down Expand Up @@ -496,6 +500,7 @@ If you set a workflow with the key `default`, it will override this.
| repo_locking | bool | false | no | Whether or not to get a lock. |
| policy_check | bool | false | no | Whether or not to run policy checks on this repository. |
| custom_policy_check | bool | false | no | Whether or not to enable custom policy check tools outside of Conftest on this repository. |
| autodiscover | Autodiscover | true | no | Whether or not to enable autodiscover on this repository. |


:::tip Notes
Expand Down
1 change: 1 addition & 0 deletions server/controllers/events/events_controller_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,7 @@ func setupE2E(t *testing.T, repoDir string, opt setupOption) (events_controllers
false,
false,
false,
valid.Autodiscover{Enabled: true},
false,
false,
"",
Expand Down
Loading