Spacelift should take terraform plan and pass into terraform apply to ensure it only plans once
When outputting terraform plan log output into a PR to allow approvers to easily review a PR, we assume these are the changes which are going to be applied to the state file which is being changed. However when the PR is merged into the default branch, the default behaviour of Spacelift is to replan off the default branch and apply those changes.
However, this poses a problem- if there are changes in the environment between the last plan outputting in the PR and the second plan after merge. This could mean that Spacelift is applying changes which have not been approved by the original PR reviewer. In the real world of AWS ClickOps, this is a very real issue where another Engineer could have made manual changes in the case of an incident to mitigate an issue and Spacelift would be reverting these changes.
Having an extra gate after merge and on apply to production environments would be fine at small scale, but not for those customers who are managing large scale infrastructure and want to follow a strict GitOps workflow, it is very important to make things easier to manage, not harder and the audit trail clearer.
- Workaround
- Problem
Log in to comment and vote
Comments15
Amaranth Dew
May 6, 2025
This is essential to workflows and is a standard in terms of CI/CD flows the plan is leveraged as an artifact and applied. There should be no potential for changes to occur between when the plan is run and when the apply occurs.
Magenta Sun
May 7, 2025
Thanks
> What would “safe” look like for you?`
We want to be able to apply the plan that the approver has approved in the MR, we don’t want to have to have another gate in the Spacelift UI (we want autodeploy) as we have a lot of infrastructure and this would be a bit of overhead.
> Where does current behavior create risk, friction, or delay?
Currently the plan posted in the MR is not what is actually applied. The second plan after merge to main is what is applied. However this adds adds the extra risk (for us) in the fact that the first plan which is viewed by the MR approver is not necessarily what is applied to the environment. I understand in a perfect world, our terraform would be perfectly idempotent and we would not have ClickOps in our environments- this is not the case, we are every much relying on Spacelift to help get us to this place but right now we cannot guarantee that between MR being opened and approved and then merged into main and replanned that there will not be manual changes in AWS environment for example or anything else.
> What does a successful, trustable GitOps flow feel like—especially at scale?
Ensuring the plan in the MR which the approver has reviewed and approved is what is actually applied.
Teal Astronaut
May 23, 2025
I think it could work like this.
We have a plan in the PR.
When spacelift re-plans, its should compare the 2 plans.
IF they are the same, then go ahead and apply.
IF they are different, then it should stop, and it should be flagged.
Black Breeze
May 7, 2025
Thanks for raising this—it’s a really important concern.
You’re absolutely right that Spacelift plans twice, and in many ways, that’s a feature, not a flaw. The second plan ensures that the assumptions made during PR review still hold true at the time of apply. Infrastructure may have changed in the meantime—another PR could’ve landed, or someone may have ClickOps-ed something in response to an incident, as you noted.
The messy reality is: environments drift, sometimes on purpose. And blindly trusting a stale plan can be just as dangerous as re-applying unreviewed changes.
That said, if the goal is to make the apply feel as safe and trusted as the plan that was reviewed, maybe the answer isn’t skipping the replan—but making the difference between plans visible. Comparing checksums (or even full diffs) could flag when the apply would do something materially different than what was approved.
Before we jump into solutions, though—can we step back and clarify the job you’re trying to get done here?
What would “safe” look like for you?
Where does current behavior create risk, friction, or delay?
What does a successful, trustable GitOps flow feel like—especially at scale?
Understanding this will help us design something that’s both possible and actually solves the right problem.
Black Breeze
May 7, 2025
Thanks!
So to make sure we’re on the same page:
- you don’t mind planning again (given that there’s a real value to it);
- you’re concerned about the MR plan and the merge plan potentially being different;
Is that correct?
Black Breeze
May 27, 2025
Magenta Sun
May 30, 2025
Appreciate the feedback, thanks