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

Conversation

mtavaresmedeiros
Copy link

@mtavaresmedeiros mtavaresmedeiros commented Mar 30, 2023

what

  • The idea is to create a flag in the repository configuration side that allows disabling the autodiscovery.

why

  • After this change: feat: support atlantis.yaml without defined projects #2300, if we not specify a project in atlantis.yaml, the Atlantis will do an automatic discovery in the entire environment and try to do the plan/apply in modified files.

  • In cases where we use multiples Atlantis servers in the same repository, it can be a problem because the Atlantis server from one environment can try to do a discovery and get projects from another environment.
    example of a dir structure:
    .
    |── prod
    │   └── project1
    │   └── main.tf
    |── stage
    |── test
    └── project1
    └── main.tf

We are using the terragrunt-atlantis-config to create theatlantis.yamlin the pre_workflow_hooks. when the terragrunt-atlantis-config run in a directory that doesn't have any project(like the "stage" dir in the example above) or in a directory that does not exist(I know that it looks strange, but try to think about one scenario in which you have multiples Atlantis servers, then when you will create a new repository, for sure that you will start with the test environment, but you would like to configure it (webhooks) to support when the users create the manifest to another environment, I mean you wouldn't like to add the webhooks only when the guy create the new stage, right?), it will create a atlantis.yaml without any project, it means that it will trigger the automatic discovery and will try to do the plan/apply for any project that was modified in the pull request.

tests

  • autodiscover disabled:
{"level":"info","ts":"2023-04-04T14:38:19.764Z","caller":"events/project_command_builder.go:357","msg":"successfully parsed atlantis.yaml file","json":{"repo":"xxxxx/infra-app-env-terragrunt","pull":"5"}}
{"level":"info","ts":"2023-04-04T14:38:19.764Z","caller":"events/project_command_builder.go:392","msg":"No projects are defined in atlantis.yaml. Auto discovery is disabled. Will skip automatic detection","json":{"repo":"xxxxxxx/infra-app-env-terragrunt","pull":"5"}}
{"level":"info","ts":"2023-04-04T14:38:19.764Z","caller":"events/plan_command_runner.go:97","msg":"determined there was no project to run plan in","json":{"repo":"xxxxxxx/infra-app-env-terragrunt","pull":"5"}}
  • autodiscover enabled:
{"level":"info","ts":"2023-04-04T14:54:59.977Z","caller":"events/project_command_builder.go:357","msg":"successfully parsed atlantis.yaml file","json":{"repo":"xxxx/infra-app-env-terragrunt","pull":"5"}}
{"level":"info","ts":"2023-04-04T14:54:59.977Z","caller":"events/project_command_builder.go:395","msg":"No projects are defined in atlantis.yaml. Auto discovery is enabled, will resume automatic detection","json":{"repo":"xxxxx/infra-app-env-terragrunt","pull":"5"}}

references

Extra

Obs: about the terragrunt-atlantis-config, I create a forked and updated it to support this new flag( if approved).

@mtavaresmedeiros mtavaresmedeiros requested a review from a team as a code owner March 30, 2023 14:33
@github-actions github-actions bot added the go Pull requests that update Go code label Mar 30, 2023
@mtavaresmedeiros mtavaresmedeiros changed the title add flag to allow disable the autodiscover feat:add flag to allow disable the autodiscover Mar 30, 2023
@nitrocode
Copy link
Member

@mtavaresmedeiros please fill out the pr template. This also helps summarize the changes for pr reviewers

@nitrocode nitrocode changed the title feat:add flag to allow disable the autodiscover feat: add flag to allow enable/disable project autodiscovery Mar 31, 2023
@mtavaresmedeiros
Copy link
Author

mtavaresmedeiros commented Apr 4, 2023

@mtavaresmedeiros please fill out the pr template. This also helps summarize the changes for pr reviewers

Done

@nitrocode
Copy link
Member

@mtavaresmedeiros apologies for the long review... Do you mind resolving the conflicts when you get a chance?

@nitrocode
Copy link
Member

nitrocode commented May 7, 2023

In issue #3339, an additional global configuration (in the Atlantis server repos.yaml) would be nice to enable/disable auto discovery. This way the repo owner can create the Atlantis configuration file and override the setting if desired.

So if the repo configuration atlantis.yaml file did not exist or did not override the setting, Atlantis would no longer run plans on auto discovered projects in that repo.

What do you think about adding that within this PR?

@mtavaresmedeiros
Copy link
Author

@nitrocode Sure, I will work on it 👍.

@GenPage GenPage added the waiting-on-response Waiting for a response from the user label May 13, 2023
@github-actions
Copy link

This issue is stale because it has been open for 1 month with no activity. Remove stale label or comment or this will be closed in 1 month.

@github-actions github-actions bot added the Stale label Jun 14, 2023
@mtavaresmedeiros
Copy link
Author

@nitrocode , Hello man, do you think that we can merge it, and I work on the global config a little bit later? I am trying to find a time to work on it but it is a little complicated.

@github-actions github-actions bot added build Relating to how we build Atlantis docs Documentation dependencies PRs that update a dependency file provider/azuredevops provider/bitbucket provider/github provider/gitlab github-actions website and removed build Relating to how we build Atlantis docs Documentation labels Jul 3, 2023
@jamengual
Copy link
Contributor

@mtavaresmedeiros do you think you have time to finish this?

@github-actions
Copy link

This issue is stale because it has been open for 1 month with no activity. Remove stale label or comment or this will be closed in 1 month.

@github-actions github-actions bot added the Stale label Sep 15, 2023
@FalconerTC
Copy link

@mtavaresmedeiros I'd love to see this feature merged. A scenario I have run into is that pull-request into a branch that Atlantis is not configured to run against is considered as having zero projects so auto-discovery runs.

@github-actions github-actions bot removed the Stale label Sep 16, 2023
@mtavaresmedeiros
Copy link
Author

Hello guys,

Sorry, I am trying to find a time to finish it, I will try this week.

@jamengual jamengual added the feature New functionality/enhancement label Sep 27, 2023
@GenPage
Copy link
Member

GenPage commented Oct 6, 2023

I approved the tests, should hopefully help

@mtavaresmedeiros
Copy link
Author

I think that we are done guys, sorry the delay, can you have a look on it?

@marcportabellaclotet-mt

Is there any update on this topic?
Seems that tests are waiting for a maintainer to be executed.
Thanks again.
Looking forward to have this issue merged and released ;)

Copy link
Member

Choose a reason for hiding this comment

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

Please add documentation for the repo and global configuration

@nitrocode
Copy link
Member

I kicked off the tests again.

Can you check these remaining items?

  • I think we didn't merge the pr because there wasn't a global configuration to disable autodiscovery so the only way to disable autodiscovery was using a repo config.
  • I also noticed that there isn't any runatlantis.io docs for this new config. Anytime a new feature is added, we try to update the docs so users know how to use it. Otherwise they have to dig through code or pr comments.
  • if autodisover is enabled and projects are defined, will it still auto discover projects that are not defined? We have another pr that is similar to this feat: add autodiscover enabled feature #3895 by @jskrill

Thanks @mtavaresmedeiros for all your efforts. It's pretty close.

@nitrocode
Copy link
Member

Also relevant comment #3895

Might be good for the authors to work together on this implementation.

@github-actions github-actions bot added the docs Documentation label Oct 25, 2023
@mtavaresmedeiros
Copy link
Author

mtavaresmedeiros commented Oct 25, 2023

I kicked off the tests again.

Can you check these remaining items?

* I think we didn't merge the pr because there wasn't a global configuration to disable autodiscovery so the only way to disable autodiscovery was using a repo config.

* I also noticed that there isn't any runatlantis.io docs for this new config. Anytime a new feature is added, we try to update the docs so users know how to use it. Otherwise they have to dig through code or pr comments.

* if autodisover is enabled and projects are defined, will it still auto discover projects that are not defined? We have another pr that is similar to this [feat: add discover_projects_with_missing_config feature #3895](https://github.com/runatlantis/atlantis/pull/3895) by @jskrill

Thanks @mtavaresmedeiros for all your efforts. It's pretty close.

Hi,
The Topics 1 and 2 are done,

About topic 3, follow de default behavior, it will check only the projects that are in the "atlantis.yaml" or do the discover if not have projects. And not sure what is the benefit of it, if you want the discovery in the repository, just do not specify the projects...

@jamengual jamengual added waiting-on-review Waiting for a review from a maintainer and removed waiting-on-response Waiting for a response from the user labels Nov 15, 2023
@GenPage
Copy link
Member

GenPage commented Dec 11, 2023

@mtavaresmedeiros Thank you for the PR. Can you confirm if #3895 delivers the same feature as yours, including global auto-discover? There are many conflicts in the PR now, and I believe this PR is no longer needed due to 3895 being merged.

@GenPage GenPage added waiting-on-response Waiting for a response from the user and removed waiting-on-review Waiting for a review from a maintainer labels Dec 11, 2023
@mtavaresmedeiros
Copy link
Author

yesss. it is fine, thx.

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 waiting-on-response Waiting for a response from the user
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants