Loading video player...
(Sponsorship disclosure - Big thanks to Trigger.dev for sponsoring this video. As you know, I only partner with tools that I actually find useful for my workflow. If you're looking to build reliable background jobs without the infrastructure headache - https://fandf.co/4aHYdKw) This AI Agent Writes Terraform AND Deploys It ā From Scratch In this video, I build a complete AI-powered infrastructure agent from scratch that takes plain English like "Deploy an EC2 server on AWS" and does everything automatically ā parses the request, generates production-ready Terraform code in real-time, validates it, estimates your monthly cost, waits for your approval, and deploys real cloud infrastructure. The entire system is built with Trigger.dev ā an open-source TypeScript platform for long-running AI agent workflows. No timeouts, built-in retries, real-time streaming, and human-in-the-loop approval where the task literally pauses and waits for you to click a button before spending your money. š„ What You'll Learn: 1. How to build a multi-step AI agent from scratch using TypeScript 2. How to use Trigger.dev for long-running task orchestration 3. How to use Google Gemini AI (FREE) with Vercel AI SDK for structured output and streaming 4. How to generate production-ready Terraform code with AI 5. The Evaluator-Optimizer pattern ā AI that validates and auto-fixes its own code 6. Human-in-the-loop approval workflows with Trigger.dev wait tokens 7. Real-time streaming from backend to frontend 8. Deploying real AWS infrastructure with terraform apply š ļø Tech Stack: Next.js 15 (App Router) Trigger.dev (Task Orchestration + Streams + Human Approval) Google Gemini 2.0 Flash (via Vercel AI SDK) Zod (Schema Validation) Terraform (Infrastructure as Code) TypeScript Tailwind CSS š Links: Source Code: https://fandf.co/4aHYdKw Trigger.dev (free): https://fandf.co/4aHYdKw Trigger.dev Docs: https://fandf.co/4aHYdKw Google Gemini API (free): https://aistudio.google.com Vercel AI SDK: https://sdk.vercel.ai Terraform: https://terraform.io š How the AI Agent Works: Step 1 ā Parse: User types a sentence. Gemini AI converts it into a structured JSON spec using Zod schema validation. No hallucinated fields ā the output is guaranteed to match the exact shape we define. Step 2 ā Generate: The structured spec gets sent to Gemini which generates production-ready Terraform HCL code. The code streams to the frontend token-by-token in real-time using Trigger.dev streams. Step 3 ā Validate + Auto-Fix: AI validates the generated Terraform for syntax errors, security issues, and best practices. If errors are found, it automatically sends them back to the AI for fixing. This Evaluator-Optimizer loop runs up to 3 times. Then it estimates your monthly cost with a per-resource breakdown. Step 4 ā Human Approval: The Trigger.dev task literally PAUSES using wait tokens. The frontend shows the generated code, estimated cost, and Approve/Reject buttons. No compute is used while waiting. When you click a button, the task wakes up and continues. Step 5 ā Deploy: On approval, the agent writes the Terraform file to disk, runs terraform init and terraform apply, and streams the output live. Real cloud resources get created ā VPC, subnets, security groups, EC2 instances ā everything. š” Why Trigger.dev? No timeouts ā Terraform deployments can take 10+ minutes. Regular serverless functions timeout at 30 seconds. Built-in retries ā Cloud APIs fail. Trigger.dev handles exponential backoff automatically. Real-time streaming ā Push live updates from backend tasks to the frontend. Human-in-the-loop ā Tasks can pause and wait for user approval before continuing. Full observability ā Every task run is visible in the Trigger.dev dashboard with logs, timing, and stream data. #AIAgent #TriggerDev #Terraform #DevOps #AWS #CloudInfrastructure #AI #TypeScript #NextJS #Tutorial #GeminiAI #BuildFromScratch