How I Built an Offline Mock Cloud to Train a Deterministic Terraform AI

Dev.to AI
Generative AI AI Safety

Generic AI models are terrible at writing enterprise Terraform. If you ask GPT-4o or Claude 3.5 to spin up an EC2 instance, they’ll do fine. But if you ask them to build a cross-region Transit Gateway, attach three VPCs, enforce strict least-privilege IAM, and attach a WAFv2 to a CloudFront distribution - they will hallucinate. They will invent arguments that don't exist in the provider schema, create circular dependencies, or miss critical cross-module references. Why? Because Large Language Models are probabilistic. They guess what the code should look like.