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: customize atlantis.yaml file name in server side config #2798

Merged
merged 10 commits into from Dec 19, 2022

Conversation

krrrr38
Copy link
Contributor

@krrrr38 krrrr38 commented Dec 14, 2022

what

  • Server-side config repos.yaml can accept repo_config_file configuration for customizing atlantis.yaml

why

Currently atlantis.yaml file must be put on the repository root. We can use this feature in the following situations.

  • service wide mono-repo
    • mono-repo put service specific directory on the repository root like frontend, backend and infrastructure
    • In this case, we want to put atlantis.yaml into infrastructure/terraform/atlantis.yaml, not repository root.
  • multiple atlantis servers can handle a same repository.

Workaround

references

@krrrr38 krrrr38 requested a review from a team as a code owner December 14, 2022 21:52
@krrrr38 krrrr38 force-pushed the feat-custom-atlantis-yaml-name branch 2 times, most recently from 1038812 to 98d0c7e Compare December 14, 2022 22:02
@krrrr38 krrrr38 marked this pull request as draft December 14, 2022 22:17
@krrrr38 krrrr38 force-pushed the feat-custom-atlantis-yaml-name branch from 98d0c7e to d2f3ce9 Compare December 14, 2022 22:25
@krrrr38 krrrr38 marked this pull request as ready for review December 14, 2022 22:27
@krrrr38 krrrr38 marked this pull request as draft December 14, 2022 22:44
@krrrr38 krrrr38 force-pushed the feat-custom-atlantis-yaml-name branch from d2f3ce9 to 6a74630 Compare December 14, 2022 22:46
@krrrr38 krrrr38 marked this pull request as ready for review December 14, 2022 22:49
@krrrr38 krrrr38 marked this pull request as draft December 14, 2022 23:36
@krrrr38 krrrr38 force-pushed the feat-custom-atlantis-yaml-name branch 2 times, most recently from fbfd285 to 7f058ea Compare December 15, 2022 00:12
@krrrr38 krrrr38 marked this pull request as ready for review December 15, 2022 00:15
@nitrocode
Copy link
Member

Nice addition! Let me ping the other @runatlantis/maintainers to get a review.

I've reviewed this and the changes seem straight forward.

@jamengual
Copy link
Contributor

hahahah 2 years ago I implemented this same feature ( not as good as this PR) I'm glad to see it coming so complete @krrrr38 thanks for the work.

I have a question:

how is this possible? Each atlantis processes have repos.yaml files that have different config_repo_file.? is that because you could match each repo regex id: to a different repo but if that the case will not be per process, no?

@krrrr38
Copy link
Contributor Author

krrrr38 commented Dec 15, 2022

@jamengual

how is this possible? Each atlantis processes have repos.yaml files that have different config_repo_file.? is that because you could match each repo regex id: to a different repo but if that the case will not be per process, no?

Like followings.

  • repository configurations
    • put atlantis-staging.yaml and atlantis-production.yaml
  • server configurations
    • atlantis-staging server run with ATLANTIS_REPO_CONFIG_JSON='{"repos":[{"id":"/.*/", "repo_config_file": "atlantis-staging.yaml"]}]}'
    • atlantis-production server run with ATLANTIS_REPO_CONFIG_JSON='{"repos":[{"id":"/.*/", "repo_config_file": "atlantis-production.yaml"]}]}'
  • then setup 2 webhook in the repository, which sent both atlantis-staging server and atlantis-production server
    • Each event processed by both servers.
    • atlantis-staging server handle atlantis-staging.yaml and atlantis-production server handle atlantis-production.yaml.
atlantis-staging.yaml example
version: 3
projects:
- name: project
  branch: /staging/
  dir: infrastructure/staging
atlantis-production.yaml example
version: 3
projects:
- name: project
  branch: /production/
  dir: infrastructure/production

Actually, the above case can be handled by one atlantis server with following config 😬 . But we can separate them into multiple atlantis servers for reasons such as the server's IAM.

version: 3
projects:
- name: project1
  branch: /staging/
  dir: infrastructure/staging
- name: project2
  branch: /production/
  dir: infrastructure/production

@krrrr38
Copy link
Contributor Author

krrrr38 commented Dec 15, 2022

Ah, but in this case with base branch staging, when I comment atlantis plan, atlantis-staging server returns plan result and atlantis-production server returns no projects result. so might be better to set ATLANTIS_SILENCE_NO_PROJECTS=true, too. https://www.runatlantis.io/docs/server-configuration.html#silence-no-projects

server/events/vcs/bitbucketcloud/client.go Outdated Show resolved Hide resolved
server/events/vcs/bitbucketserver/client.go Outdated Show resolved Hide resolved
server/events/vcs/not_configured_vcs_client.go Outdated Show resolved Hide resolved
server/events/vcs/azuredevops_client.go Outdated Show resolved Hide resolved
@jamengual
Copy link
Contributor

Undestood, I was doing something similar before. you might want this too:

https://www.runatlantis.io/docs/server-configuration.html#vcs-status-name

and a well documented example in docs will be wonderful.

@jamengual
Copy link
Contributor

jamengual commented Dec 15, 2022

Another way this could be done ( not in this PR) is using a github action that can route the call to the specified atlantis server without having to have two webhooks in the same project.

if the atlantis command could be configured to pass a name like ATLANTIS_COMMAND_NAME="atlantis-prod" or some other method could work too ( label based etc)

this is me just thinking out loud and I like your aproach more because it supports all the VCSs

Copy link
Member

@GenPage GenPage left a comment

Choose a reason for hiding this comment

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

Great PR, it would be nice to see some ways to auto-trigger "silence-no-projects" if a custom Atlantis YAML is set but it is not trivial. I generally would like us to try and reduce the number of flags we have but outside the scope of this PR :)

@krrrr38
Copy link
Contributor Author

krrrr38 commented Dec 15, 2022

Thank you for the reviews, everyone.

a well documented example in docs will be wonderful.

I added the usecase like c55a253. I'm not good at English, so let me know if something is weird.

call to the specified atlantis server

I've seen such an issue #326. Sounds good.


:::tip Notes
* If `no projects` comments are annoying, set [--silence-no-projects](server-configuration.html#silence-no-projects).
* When using different atlantis server vcs users such as `@atlantis-staging`, you can call `@atlantis-staging plan` instead `atlantis plan` to call `stating-server` only.
Copy link
Contributor Author

@krrrr38 krrrr38 Dec 16, 2022

Choose a reason for hiding this comment

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

I didn't know this usage, but we can call one of atlantis-server by using vcs user. (BTW run apply is dangerous and useless...?)

// Valid commands contain:
// - The initial "executable" name, 'run' or 'atlantis' or '@GithubUser'
// where GithubUser is the API user Atlantis is running as.
// - Then a command: 'plan', 'apply', 'unlock', 'version, 'approve_policies',
// or 'help'.
// - Then optional flags, then an optional separator '--' followed by optional
// extra flags to be appended to the terraform plan/apply command.
//
// Examples:
// - atlantis help
// - run apply
// - @GithubUser plan -w staging

Copy link
Member

Choose a reason for hiding this comment

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

That is a nice call out, and something I learned today. @krrrr38 Are you asking a question about run apply or pointing out that its dangerous and useless? I think it should be removed, but we don't know any other use cases by users. It seems to just be an alias for atlantis.

executableNames := []string{"run", atlantisExecutable, "@" + vcsUser}
if !e.stringInSlice(args[0], executableNames) {
return CommentParseResult{Ignore: true}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@GenPage

I discuss it in the other PR, too. I'm worry about that almost users don't know it and it might execute unintentional apply.

But currently this feature is already provided and we might be better to discuss it in the next major release and so on, not in this PR.

@krrrr38 krrrr38 force-pushed the feat-custom-atlantis-yaml-name branch from e3070b1 to f7ce09c Compare December 19, 2022 04:26
@nitrocode nitrocode merged commit 08e9c5a into runatlantis:main Dec 19, 2022
@nitrocode
Copy link
Member

Thank you again @krrrr38 ! These contributions are very helpful!

@krrrr38
Copy link
Contributor Author

krrrr38 commented Dec 19, 2022

Thank you for your high quality and quickly review, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow custom name for atlantis.yaml
4 participants