-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Automatically merge when all apply's complete #186
Comments
isn't there even a (web) hook before merging? this way atlantis would apply the plan on merge. if apply fails, the merge gets aborted? |
ah just read the docs, aborting merge wouldn't work of course, bummer.. be maybe revert and re-open pr? |
Reverting wouldn't work because Terraform will partially apply all the changes it can. If you reverted then the code wouldn't represent what was partially applied. I think running |
Could you do this using custom workflows? Something like:
I know |
I guess what I am getting at is, If BaseRepo, HeadRepo, and Pull were exposed as environment variables in the RunStepRunner run function a lot of possibilities open up. Maybe lower hanging fruit? |
Yeah that's definitely doable. But if there were multiple projects in one repo you'd want to check if there were unapplied plans. I think this is better implemented in the core. |
agreed. any issue with #229? Here is how I am using it: atlantis.yml section: workflows:
custom:
apply:
steps:
- apply
- run: ./merge_script.sh merge_script.sh: curl -sS "https://api.github.com/repos/$BASE_REPO_OWNER/$BASE_REPO_NAME/merges" \
-XPOST \
-H "Authorization: token $ATLANTIS_GH_TOKEN" \
-d "{\"base\": \"master\", \"head\": \"$HEAD_BRANCH_NAME\"}" |
Looks good to me! Only thing I'd do is not pipe stderr to /dev/null in case there's an error in the API call. I think |
Updated PR and my example above. |
User at your own risk: The above should only be used for single project applies. Otherwise the script will likely result in undesired behavior. If your pr is touching multiple projects the first apply will result in merging of the pr. |
I will take a stab at implementing this, if nobody else is working on it. |
@brndnmtthws please do |
Should we support the "merge" options? For example on our repos we only allow
|
@majormoses good question, that was something I was going to ask about. Initially I think it should just default to whatever the repo uses. Another question: how should we handle the locks with merging? Should the locks be released before or after the merge succeeds? In my case, the main reason for wanting to implement this feature is to avoid conflicts between PRs, particularly in cases where changes are applied but not merged into master. So if atlantis releases the locks, but a merge fails for some reason, we wind up with the same problem: someone could get the repo into an unclean/conflicted state. |
I would not release the lock until after the merge. |
Another question: it's possible to apply specific projects individually on a PR. What should be the behaviour if only one project is applied but multiple projects have been modified in a given PR? The logic is around here: https://github.com/runatlantis/atlantis/blob/master/server/events/project_command_builder.go#L252-L264 The easy thing to do is to only merge the PR when all plans are applied. However this wouldn't be great if someone decides to apply multiple plans individually. A more complex, and probably better alternative would be to check that all plans have been applied, and then merge the PR. Thoughts? I'll try and figure out how to implement it so we wait until every plan has been applied, either individually or all at once. |
One more Q: autoplan can be specified per project, however automerge should probably be global only. If I want to enable automerge, I would want to enable it for the entire repo. It doesn't make sense (to me, at least) to have automerge configurable per-project. Thoughts? |
I would think if you would want autoplan per project you would also want automerge per project, but overall I don't see why people would want autoplan at the project level. |
For the targeted apply approach I think I would skip supporting that and just ignore it as a use-case and only support auto merge on the |
It seems confusing to me to specify automerge at the per-project level. Autoplan I get, but not automerge. You can have N projects per PR, so specifying whether each one should be merged individually doesn't make sense (it's a 1 to N mapping). |
@brndnmtthws ok, that does make sense. |
I think it makes sense to only auto merge if all plans have been properly applied. At work we have repos for our aws, pagerduty, and github management with terraform. Some repos have multiple projects/directories in them and others do not. As long as we can differentiate behavior at a repo level I think we are good as that should allow us to treat different types of resources differently. |
To answer the questions raised:
|
Sweet, sounds good. I'm nearly finished with the PR (excluding tests & testing), so hopefully I'll have it ready by the end of the day. |
@sstarcher people want autoplan at the per-project level because of the
And you wanted:
Then you would need to use a different version: 2
projects:
- dir: project1
autoplan:
when_modified: [*.tf, ../modules/module1/*.tf]
- dir: project2
autoplan:
when_modified: [*.tf] |
Just submitted a first pass at the PR. Took a while to get all the tests working correctly, but it should work, so please test it out. |
What is the use case for having Atlantis auto merge once all the plans in a PR have been applied successfully? |
To stop the user from needing to merge it themselves. Once the applies are done it should be on master so master reflects reality. |
This precisely. It can be problematic when people don't remember to merge their PRs right away. |
Please for the love of all things, I need this feature terribly! 👍 👍 |
Similar to autoplan, automerge is a feature whereby Atlantis will merge a PR/MR once all plans have successfully been applied. This addresses issue runatlantis#186.
Provide an option where Atlantis would merge the pull request automatically if all the apply's succeeded.
The text was updated successfully, but these errors were encountered: