Quick overview
This workflow reviews Terraform pull requests in GitHub using an OpenAI tool-calling agent that can run plan, security, cost, and standards checks, then logs results to Postgres, comments on the PR, and auto-approves clean changes or routes flagged ones to Slack for human sign-off.
How it works
- Triggers on GitHub pull request events for the selected repository.
- Extracts PR metadata (repo, branch, author, title, and PR number) and fetches the PR details from GitHub for review context.
- Uses an OpenAI agent with session memory to review the PR and, as needed, calls HTTP tools to run a Terraform plan, run a Terraform security scan, estimate cost impact, and query a vector store of internal IaC standards.
- Parses the agent’s structured JSON output into fields such as findings, overall risk, verdict, blocking issues, and cost impact summary.
- Inserts the review record into a Postgres
terraform_pr_reviews table and posts a formatted review comment back to the GitHub PR.
- If the verdict is pass, submits a GitHub PR approval; otherwise, sends the findings to a Slack channel, waits for a human security decision, and then either approves the PR or requests changes in GitHub.
Setup
- Connect GitHub credentials with permission to read pull requests and create comments/reviews, and select the target owner and repository in the GitHub trigger and GitHub nodes.
- Add OpenAI credentials for the Chat Model and configure the model selection (for example,
gpt-4.1).
- Configure the HTTP endpoints used by the Terraform plan, security scan, and cost estimate tools (for example, CI/internal APIs) so they return usable results for the agent.
- Set up a vector store for your internal IaC standards and connect the vector store credentials used by the RAG search tool.
- Add Postgres credentials and create a
terraform_pr_reviews table with columns matching the insert (pr_number, repo, author, findings, overall_risk, verdict, blocking_issues, cost_impact_summary, created_at).
- Add Slack credentials, set the target channel (for example,
#terraform-security-review), and configure how reviewers resume the workflow by calling the Wait node’s webhook with a securityApproved value.