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: draftplan #3275

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

feat: draftplan #3275

wants to merge 3 commits into from

Conversation

finnag
Copy link
Contributor

@finnag finnag commented Mar 28, 2023

what

Implement a new atlantis command "draftplan" for making draft plans.

Draft plans can run at pretty much any time in any PR as long as a terraform isn't already running for that PR, and the only result is a comment in the PR about what the plan would look like.

The draft plans do the following:

  • Run terraform with -refresh=false -lock=false
  • Do not store the plans for apply
  • Do not delete previous plans or locks
  • Do not update commit status
  • Run almost without locks (workspace still locked for some ops)
  • Do not affect automerging

This revision of the implementation is a bit more reasonable than the previous draft version.

why

It's often useful to see what plan a PR would result in, even if you do not want to apply the plan yet. Also, many times there are locks preventing a normal plan from running.

This mode could also maybe be a pretty useful mode for draft PRs, you can see what the plan would look like without affecting other PRs.

tests

  • I have tested my changes by running all the tests, and playing around in some test repos.

references

@jamengual
Copy link
Contributor

@finnag This is pretty interesting, I will be happy to review when is ready

@nitrocode
Copy link
Member

This is interesting.

I'd prefer that all plans have dynamodb lock and atlantis lock disabled since we only really need to lock on apply. If the plan generated is stale, atlantis will run terraform which will announce that the plan is stale which would force a replan anyway.

@finnag
Copy link
Contributor Author

finnag commented Mar 28, 2023

We run atlantis in merge mode now, and we rely on the plans for reviews. The reviewer looks at the plan output in addition to the PR change itself to decide whether to approve or not. It's hard to see how the plans can stay true (as in not stale) unless the lock is grabbed before the plan is created, and held until after the PR is merged? If applying triggers a new plan, the review must be done again and you're entering some sort of loop...

@nitrocode nitrocode changed the title Quickplan - WIP - want comments feat: quickplan - want comments Mar 30, 2023
@jimsmith
Copy link

I'm looking forward to seeing this being implemented and released out, a much needed function.

@jamengual
Copy link
Contributor

We run atlantis in merge mode now, and we rely on the plans for reviews. The reviewer looks at the plan output in addition to the PR change itself to decide whether to approve or not. It's hard to see how the plans can stay true (as in not stale) unless the lock is grabbed before the plan is created, and held until after the PR is merged? If applying triggers a new plan, the review must be done again and you're entering some sort of loop...

I believe the approvals are only required again if there are any file changes, if not the approval persists.

@finnag finnag marked this pull request as ready for review June 6, 2023 20:34
@finnag finnag requested a review from a team as a code owner June 6, 2023 20:34
@finnag finnag changed the title feat: quickplan - want comments feat: draftplan Jun 6, 2023
@github-actions github-actions bot added the go Pull requests that update Go code label Jun 6, 2023
@finnag
Copy link
Contributor Author

finnag commented Jun 6, 2023

@jamengual Finally had some time to clean this up a bit, if you could review and give some feedback that would be nice. We've been running with variants of this patch for a while now, it's quite useful.

@jamengual
Copy link
Contributor

@finnag does this delete the previous draftplan comment if another one is run and when an actual plan is run?

@finnag
Copy link
Contributor Author

finnag commented Jun 14, 2023

@finnag does this delete the previous draftplan comment if another one is run and when an actual plan is run?

It behaves like this, at least on GitHub:

  • Previous draftplan outpus are hidden by new plans and new draftplans
  • Previous plan outputs are hidden by new plans, but not by new draftplans.

The latter is sort of a fortunate accident because "plan" is a substring of "draftplan", and GithubClient. HidePrevCommandComments is looking for occurrences of the command name in the first line of the comment.

@jamengual jamengual added waiting-on-review Waiting for a review from a maintainer feature New functionality/enhancement labels Sep 27, 2023
@GenPage GenPage added this to the v0.27.0 milestone Oct 6, 2023
@peikk0
Copy link
Contributor

peikk0 commented Oct 11, 2023

Would it be possible to add a setting to make autoplan always run a draftplan instead of plan?

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.

Is there a way to do this without introducing such a big change? We essentially creating a pseudo-command in the Terraform binary around plan. I much rather us just call the Plan command with a flag that ignores writing the plan to the filesystem.

@GenPage GenPage added waiting-on-response Waiting for a response from the user needs discussion Large change that needs review from community/maintainers work-in-progress and removed waiting-on-review Waiting for a review from a maintainer labels Dec 11, 2023
@GenPage GenPage modified the milestones: v0.27.0, v0.28.0 Dec 12, 2023
@mattjamesaus
Copy link

Big fan of this (as the locking/unlocking is a pain when you have larger terraform workspaces with backlogged PRs), i think the comments around the plan being not a perfect representation are valid and i wonder if putting/allowing some sort of prefix to the plan output could be possible (that provides a clear disclaimer that the output isn't perfectly representative). Even better would be somehow allowing atlantis administrators to set this to be specific to their orgs terminology, so something like this could be achievable on a draft plan.

Warning

This is a draft plan and may not truly be representative of the run due to atlantis sequential locking behaviour - it's strictly to aid in code review blah blah.

Ran Draft Plan for dir: terraform/environment/aws/prod workspace: default
....

Copy link

github-actions bot commented Feb 4, 2024

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 Feb 4, 2024
@github-actions github-actions bot closed this Mar 7, 2024
@peikk0
Copy link
Contributor

peikk0 commented Mar 7, 2024

Not stale

@jamengual jamengual reopened this Mar 7, 2024
@jamengual jamengual requested a review from a team as a code owner March 7, 2024 04:26
@jamengual jamengual requested review from lukemassa and nitrocode and removed request for a team March 7, 2024 04:26
@GenPage GenPage added never-stale and removed Stale labels Mar 7, 2024
@chenrui333 chenrui333 modified the milestones: v0.28.0, v0.29.0 May 22, 2024
draftplan acts like a normal plan command, except it does not grab a
project lock or a terraform lock, and does not refresh state.
The resulting plan will only be printed as a comment, it will
not be stored and so cannot be applied.

It is intended a a lightweight method to see what a plan would
look like.
@finnag
Copy link
Contributor Author

finnag commented Oct 8, 2024

rebased to v0.30.0, added fix suggested by @peikk0 .. We've run with this in production for a year + now, so it "works for us".

@X-Guardian X-Guardian removed this from the v0.29.0 milestone Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality/enhancement go Pull requests that update Go code needs discussion Large change that needs review from community/maintainers never-stale waiting-on-response Waiting for a response from the user work-in-progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants