runatlantis / atlantis

Terraform Pull Request Automation
https://www.runatlantis.io
Other
7.82k stars 1.06k forks source link

Feature Request: Autoplan based on pull request destination branch #431

Open Phylu opened 5 years ago

Phylu commented 5 years ago

We currently use a gitflow approach for all our repositories including the terraform repository. We have different environments of our infrastructure which are based on different terraform/atlantis projects.

I suggest to have a configuration to run autoplanning based on the destination branch of a pull request. For example:

Therefore I suggest the autoplan config to be extended to contain the following features:

enabled: true
when_modified: ["*.tf"]
destination_branch: branchname

Where I am not sure is how when_modified and destination_plan should interact.

If this feature seems interesting and the behaviour is clear, I might take a shot at implementing this.

lkysow commented 5 years ago

Hi Janosch, On first glance this seems reasonable. I do want to think more about what other conditions users might have for autoplanning. If there's a lot of them, then adding a new key for each is not a good idea and instead I would prefer a plugin-type solution.

Are they allowed to be configured both?

Yes, they're both necessary.

Which one takes precedence? E.g. if both are defined must any of them match or both for a project to be autoplanned.

They must both match. But if destination_branch is not set, it defaults to matching any.

Phylu commented 5 years ago

I do want to think more about what other conditions users might have for autoplanning. If there's a lot of them, then adding a new key for each is not a good idea and instead I would prefer a plugin-type solution.

Sure. Let me know what makes most sense here.

smiller171 commented 5 years ago

I'm looking to be able to select the workspace to plan and apply against based on the base branch. It looks like this suggestion would allow me to do that.

lkysow commented 5 years ago

I'm looking to be able to select the workspace to plan and apply against based on the base branch. It looks like this suggestion would allow me to do that.

You could do this through custom workflows. You already have the HEAD_BRANCH_NAME and BASE_BRANCH_NAME variables available.

smiller171 commented 5 years ago

~@ivankisic~ @lkysow yes, and I plan to work something like that out. Unfortunately it's made more difficult because the branch names don't match the workspace names (and that's not likely to change) So I have to create a mapping between the branch name and the workspace name.

It's unclear where variables can be expanded right now.

ivankisic commented 5 years ago

@smiller171 not sure why I'm being tagged here. If you're aiming for @lkysow that's with an "L".

smiller171 commented 5 years ago

@ivankisic Yep. Not sure how I managed that, sorry

phzietsman commented 3 years ago

You could do this through custom workflows. You already have the HEAD_BRANCH_NAME and BASE_BRANCH_NAME variables available.

@lkysow If I wanted to limit plans to only PRs against develop and master, how would I achieve this? I can see how the BASE_BRANCH_NAME can be used to inject the var-file to apply, but how do I prevent plans for all other PRs?

In the server side repo config example there is a branch option, but in the references its not there and I get an error if I pass it into the config. I'm sure I'm missing something simple.