ChatGPTSoftwareCode reviewAI score · PendingAI-assisted edit · no obvious prompt-injection riskn8n.io

Auto-review Terraform PRs with n8n: GitHub + GPT-4.1 + Postgres + Slack

GitHub PR trigger → AI Agent calls tools (plan / security scan / cost estimate / standards search) → structured review → Postgres archive + PR comment → auto-approve or Slack human review

ExperiencedStepsWorkflowPrompt
Who
Platform and security engineers who need automated code review and compliance gating for Terraform infrastructure changes
You get
PRs automatically trigger multi-dimensional review (plan diff, security, cost, org standards), results are written to a database and commented on the PR; low-risk PRs are auto-approved, high-risk ones are escalated to Slack for human confirmation
You need
n8n · github · openai · memory · ai-agent · slack

Constraints

Prerequisites: n8n instance (self-hosted or enterprise recommended), GitHub repository admin access (repo scope + PR read/write), OpenAI API key, Postgres database, Slack workspace admin access, optional vector store (for RAG retrieval of internal IaC standards) and CI endpoints (terraform plan / security scan / cost estimate). Costs depend on OpenAI model usage and n8n execution volume.

What they did

oneclick-ai published an n8n workflow template for automatically reviewing Terraform Pull Requests on GitHub. The template triggers via GitHub webhook, uses an AI Agent to call multiple tools (terraform plan, security scan, cost estimate, internal standards RAG retrieval) to generate a structured review, archives results to Postgres, comments on the PR, and finally auto-approves or escalates to human review based on risk level.

How it went

Source is a template demonstration; the author did not provide specific execution results or ROI data (author_report). The template claims that sessionId preserves review context across multiple pushes to the same PR.

Worth knowing

1. HTTP tool nodes use example addresses (ci.internal.example.com) that must be replaced with real CI endpoints in production. 2. The terraform plan tool is explicitly configured read-only; the agent must never apply. 3. The cost estimate tool suggests connecting to Infracost API or CLI output. 4. The Wait node requires an external reviewer UI to call its webhook with a securityApproved value to resume execution. 5. The vector store must be pre-loaded with the organization's Terraform style guide, naming policy, module standards, and past review precedents. 6. This site has not executed the workflow (reproduction=not_tested).

n8n workflow template

Structure checked · Not run-tested

Use “Import from File” in n8n, or copy the JSON and paste it into the editor. Connect your own accounts, then try test data. The template is inactive by default.

Setup and test checklist

Credentials to connect

  • After import, connect your own credentials on auth-required nodes; author secrets are not included.

Configuration to replace

  • Source template is n8n public workflow #19175 (~24 nodes). Keep inactive after import; verify triggers, expressions and external API endpoints.
  • Sticky-note guidance is informational; replace placeholders with your own accounts, sheet schemas or channel IDs.

Test input and expected output

  • Manually run the main path once in a test workspace and confirm credentialed nodes authenticate without errors.
  • Drive one synthetic/redacted sample through and check output fields and downstream writes before enabling in production.

Template changes

  • Author credential bindings, webhookId and execution data are removed; the workflow is inactive. Nodes, connections and original prompts are preserved. Not run-tested in n8n.
  • No business-logic edits; verify keys, quotas and privacy compliance before use.

Template retrieved: 2026-10-24

Steps

  1. Configure GitHub trigger

    Import the workflow template into n8n and configure the GitHub Trigger node: select the target repository owner and repository, and set the event type to pull_request. Ensure the GitHub credential has repo scope and PR read/write access.

  2. Extract PR metadata and fetch diff

    When triggered, the Set - Config node extracts prNumber, repoOwner, repoName, branch, prAuthor, prTitle from the webhook payload, and generates a sessionId (format: owner/repo#prNumber). The Get - PR Diff node then calls the GitHub API to fetch the full PR details for review context.

  3. Run AI Agent multi-tool review

    The AI Agent - Terraform Reviewer node receives PR context, bound to the OpenAI Chat Model (gpt-4.1) and Window Buffer Memory (sessionId as the session key, retaining 20 turns of context). The agent calls four tools on demand: run_terraform_plan (HTTP tool, read-only plan, never apply), run_security_scan (static security scan), estimate_cost_impact (monthly cost delta), and search_iac_standards (vector store RAG for org conventions). The agent must base its review on tool outputs and must not guess.

    Execution prompt · Source text。AI Agent - Terraform Reviewer node text parameter (promptType=define)

    =You are a senior Platform/Security engineer reviewing a Terraform pull request before it can merge.
    
    Repo: {{ $json.repoOwner }}/{{ $json.repoName }} | Branch: {{ $json.branch }}
    PR #{{ $json.prNumber }} by {{ $json.prAuthor }}: "{{ $json.prTitle }}"
    
    You have four tools: run_terraform_plan (resource-level diff), run_security_scan (static security findings), estimate_cost_impact (monthly cost delta), search_iac_standards (org conventions/precedent). Use whichever combination is relevant — call multiple tools, and call them again with different parameters if needed — before writing your review. Do not guess plan output, scan findings, or cost numbers; only state what the tools returned.
    
    If earlier turns exist in this conversation (same PR), treat this as a re-review after a new push and note what changed since the prior review.
    
    Categorize findings under: security, cost, correctness (will the plan do what the PR claims), and standards (naming/tagging/module conventions). Assign each finding a severity ('low'|'medium'|'high'|'critical'). Set overallRisk to the highest severity present. List any 'critical' or 'high' security finding, or any plan output showing a destroy of a stateful resource (database, volume) as a blockingIssue requiring human sign-off.
    
    Return ONLY a JSON object (no markdown fences, no commentary) with keys: summary (2-4 sentences), findings (array of {category, description, severity}), overallRisk ('low'|'medium'|'high'|'critical'), verdict ('pass'|'flag_for_review'), blockingIssues (array of strings, empty if none), costImpactSummary (string).
  4. Parse output and publish review

    The Set - Parse Agent Output node extracts structured data via JSON.parse. The Postgres - Log PR Review node inserts the review record into the terraform_pr_reviews table (columns: pr_number, repo, author, findings, overall_risk, verdict, blocking_issues, cost_impact_summary, created_at). The GitHub - Post Review Comment node publishes a formatted review comment to the PR.

    Execution prompt · Source text。GitHub - Post Review Comment node body parameter

    =### 🤖 Terraform Review — Verdict: {{ $json.parsedOutput.verdict.toUpperCase() }} (risk: {{ $json.parsedOutput.overallRisk }})
    
    {{ $json.parsedOutput.summary }}
    
    **Findings**
    {{ $json.parsedOutput.findings.map(f => '- [' + f.severity + '] (' + f.category + ') ' + f.description).join('\n') }}
    
    **Cost impact:** {{ $json.parsedOutput.costImpactSummary }}
    
    {{ $json.parsedOutput.blockingIssues.length ? '**Blocking issues requiring human sign-off:**\n' + $json.parsedOutput.blockingIssues.join('\n') : 'No blocking issues.' }}
  5. Conditional approval or security escalation

    The IF - Review Passed node checks the verdict. If pass, GitHub - Approve PR (auto) approves the PR for merge. If flag_for_review, Slack - Request Security Review sends an alert to the configured channel (e.g. #terraform-security-review), and Wait - For Security Sign-Off pauses for a human callback. After the reviewer calls the webhook with securityApproved=true, IF - Security Approved routes to GitHub - Approve PR (delayed); otherwise GitHub - Request Changes requests changes.

    Execution prompt · Source text。Slack - Request Security Review node text parameter

    =🔒 *Terraform PR flagged for security review*
    
    *PR:* {{ $json.repoOwner }}/{{ $json.repoName }}#{{ $json.prNumber }} — "{{ $json.prTitle }}" by {{ $json.prAuthor }}
    *Overall risk:* {{ $json.parsedOutput.overallRisk }}
    
    *Blocking issues:*
    {{ $json.parsedOutput.blockingIssues.join('\n') }}
    
    *All findings:*
    {{ $json.parsedOutput.findings.map(f => '- [' + f.severity + '] (' + f.category + ') ' + f.description).join('\n') }}
    
    Reply or use the Approve/Request-Changes action to make the merge decision.

    Execution prompt · Source text。GitHub - Request Changes node body parameter

    =Changes requested after security review. Blocking issues:
    {{ $json.parsedOutput.blockingIssues.join('\n') }}

Prompt you can copy

Setup guidance · Editorial suggestion。Hand to setup assistant; confirm inputs and permissions before guiding template import and configuration

This block is the prompt. Ads are never placed here.

You are an n8n workflow setup assistant. The user wants to replicate the "AI Terraform PR Review" template. First confirm: 1) Does the user have GitHub repository admin access? 2) Is an OpenAI API key ready? 3) Is there a Postgres database and a Slack workspace? 4) Are CI endpoints exposing terraform plan / security scan / cost estimate APIs? 5) Is a vector store loaded with internal IaC standards? After confirmation, guide the user to import the template from https://n8n.io/workflows/19175/, configure credentials and node parameters step by step, and finally suggest verifying end-to-end with a test PR.

Requires repo admin access, OpenAI key, Postgres, Slack, plus optional CI endpoints and vector store

Source

Review Terraform pull requests with GitHub, GPT-4.1, Postgres and Slack · oneclick-ai · n8n.io · 2026-09-04

Comments & feedback

Tried this method? Share results, problems or improvements. Comments appear after moderation. Please avoid sensitive information.

Loading…

    Related