Skip to main content

Claude/ChatGPT Prompt to Build a Terraform CI/CD Plan-Review Pipeline

Design a GitHub Actions pipeline that runs terraform plan on PRs, gates apply on approval, uses OIDC to AWS, and posts results to Slack.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt

                                

What this prompt does

This prompt frames the model as a senior DevOps engineer designing a Terraform CI/CD pipeline as a GitHub Actions workflow -- a working YAML file with least-privilege auth, not a sketch. You set [aws_auth_method], [state_backend], [approval_gate], and [notify_channel], and it returns a PR plan job, keyless AWS auth, a gated apply job, concurrency control, plan-artifact passing, and notifications.

The structure works because the rule is that nobody applies from their laptop -- the pipeline owns the credentials. [aws_auth_method] (typically GitHub OIDC assuming an IAM role) eliminates long-lived keys, and the prompt also returns the IAM trust policy for it. [approval_gate] controls what must happen before apply runs, and [state_backend] provides the lock during apply. Plan/apply artifact passing ensures apply runs the exact reviewed plan rather than re-planning, which is what makes the review meaningful instead of a rubber stamp on a plan that changes before it runs.

When to use it

  • You want plan-on-PR with apply gated behind review, not applies from laptops.
  • You need keyless AWS auth via OIDC so there are zero static keys lying around.
  • You want the IAM trust policy generated alongside the workflow.
  • You need concurrency control so two applies never run against the same state.
  • You want the apply job to run the exact reviewed plan, not re-plan.
  • You want apply success/failure announced to a chat channel.
  • You want fmt and validate running on every PR before any plan is even posted.

Example output

You get the complete .github/workflows YAML: a PR job running terraform fmt, validate, and plan and posting the plan as a PR comment; AWS auth via your chosen method with no long-lived credentials; an apply job gated on your approval gate and merge to main with a state lock; concurrency control; artifact passing so apply uses the reviewed plan; and notifications to your channel. The IAM trust policy for the auth method is included too, so the auth side is wired and not left as an exercise.

Pro tips

  • Use [aws_auth_method] as OIDC assuming an IAM role so there are no static AWS keys in the pipeline.
  • Set [approval_gate] to a real protected-environment reviewer step so apply can't run unreviewed.
  • Match [state_backend] to your locking setup (S3 + DynamoDB lock table) so applies serialize safely.
  • Don't skip artifact passing -- if apply re-plans instead of running the reviewed plan, your review meant nothing.
  • Point [notify_channel] at the channel your team actually watches so failed applies get noticed.
  • Confirm concurrency control is wired so two merges can't apply against the same state at once.
  • Have the PR job post the terraform plan as a comment so reviewers see the diff without opening logs.

Frequently Asked Questions

Does the pipeline avoid long-lived AWS keys?
Yes. With `[aws_auth_method]` set to GitHub OIDC assuming an IAM role, the pipeline authenticates with no long-lived credentials, and the prompt returns the IAM trust policy needed for it. The goal is zero static AWS keys lying around in the workflow.
How does it ensure apply runs the reviewed plan?
It uses plan/apply artifact passing so the apply job runs the exact plan that was reviewed rather than re-planning. This matters because if apply re-plans, the review meant nothing; don't skip that deliverable when adapting the workflow.
What stops two applies from colliding on the same state?
The workflow includes concurrency control so two applies never run against the same state at once, plus a state lock on your `[state_backend]` during apply. Together they serialize applies so concurrent merges can't corrupt shared state.
Where are apply results announced?
Notifications on apply success or failure go to your `[notify_channel]`. Point it at a channel your team actually watches so a failed apply gets noticed promptly rather than sitting silently in a feed nobody checks.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Terraform & Infrastructure as Code Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support