Skip to content

fix(terraform): store saved plans beside the state in S3, not as artifacts - #375

Merged
tobias0106 merged 2 commits into
mainfrom
terraform-plan-to-s3
Oct 8, 2026
Merged

tobias0106 merged 2 commits into
mainfrom
terraform-plan-to-s3

Conversation

@tobias0106

@tobias0106 tobias0106 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

terraform-stack.yml uploaded tfplan as an Actions artifact. A saved plan is a zip of the full prior state plus every variable value, sensitive or not (terraform show -json tfplan prints them), and anyone with read access to the repository can download artifacts.

Now:

  • Plan writes s3://<bucket>/tfplans/<state key>/<pr head sha>.tfplan, bucket and key taken from the initialised backend. Readable by exactly who can read the state already.
  • Apply downloads it (merge sha, then PR head sha, same lookup as before), applies, deletes it.
  • One shared tfplans/ prefix so a single lifecycle rule per bucket can expire unapplied plans and the old versions the post-apply delete leaves behind (lifecycle filters only match a literal prefix). Roles scoped to their own state prefix need tfplans/<prefix>/* added: the two ClickPipes roles, done in terraform-core.
  • Non-s3 backends fail with Unsupported backend.
  • Removed: plan-retention-days input (no caller passes it), the slug step, actions: write from the documented caller permissions.

Rollout:

  • Merge the terraform-core ClickPipes role import first, so monta-app/terraform can write tfplans/ before it bumps.
  • Bump the pin in terraform and terraform-core. A PR planned under the old pin finds no S3 plan after the bump: re-run its plan or recover.
  • Then delete the existing tfplan-* artifacts in both repos.
  • Add a lifecycle rule on tfplans/ to each state bucket (expire after 7 days, noncurrent after 1 day).

Tested: actionlint clean; plan-store resolution against an s3 and a local backend file. Not yet run end to end.

🤖 Generated with Claude Code

…facts

A saved plan holds the full prior state and every variable value, and
Actions artifacts are downloadable by anyone with read on the repo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tobias0106
tobias0106 requested a review from a team as a code owner October 7, 2026 12:26
@tobias0106
tobias0106 requested review from sudheer-monta and removed request for a team October 7, 2026 12:26
…ycle rule can expire them

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tobias0106
tobias0106 merged commit a7ef030 into main Oct 8, 2026
1 check passed
@tobias0106
tobias0106 deleted the terraform-plan-to-s3 branch October 8, 2026 12:43
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.

2 participants