🧠 I Asked AI to Build My AWS Infrastructure — Here's What Went Wrong
3 real mistakes AI made while writing my Terraform code — and how I caught them

Search for a command to run...
3 real mistakes AI made while writing my Terraform code — and how I caught them

No comments yet. Be the first to comment.
Learn how to identify common AWS cost optimization mistakes, reduce unnecessary cloud expenses, and follow best practices to build a more efficient and cost-effective AWS environment.

Learn what AWS Lambda Layers are, how they work, when to use them, and how they help manage dependencies across multiple Lambda functions.

Learn the differences between horizontal and vertical scaling in AWS, how they work, their advantages and disadvantages, and when to use each approach.

Learn how Provisioned Concurrency helps eliminate AWS Lambda cold starts and delivers fast, predictable performance for serverless applications.

Last month, I had a client project that needed a full AWS setup — network, permissions, database, dashboards, and APIs. Instead of writing all the Terraform code by hand, I let AI write most of it for me. I thought it would save me a lot of time.
It did save time. But it also gave me three real problems. Let me explain each one clearly, so it actually helps you too, not just tell my story.
One of my services kept failing to deploy. No matter what I tried, it just wouldn't work.
The real reason: that one service needed its own separate region setting. AWS has some services where you must tell it "use this region for this one resource," even if the rest of your project uses a different default region. The AI didn't know this. It used one single region setting for everything.
I had to check AWS's own documentation, find the missing piece, and add it myself.
Takeaway for you: If you're using AI to write Terraform, always check the AWS docs for the exact service you're using. Some services have special rules that AI often skips because it's giving you a "general" answer, not one made for your exact case.
Next, my database refused to connect to the rest of my system. The error message just said something like "connection failed" — no clear reason why.
I asked AI to fix it. It gave me three guesses. All three were wrong.
So I checked it step by step, the way you'd actually debug a real problem:
Security group — Is traffic even allowed to reach the database?
Subnet — Is the database sitting in the correct part of the network?
IAM permission — Does the connecting service actually have permission to access the database?
Logs — What does AWS actually say happened, in detail?
The real issue turned out to be a missing IAM permission — a small setting that let the app talk to the database. It was step 3 on my list, not something obvious from the error message alone.
Takeaway for you: When you get a vague error, don't just ask AI to guess. Go through network, permissions, and logs, one at a time, like a checklist. This method works for almost any AWS connection problem, not just mine.
This one was the most eye-opening.
While reviewing the AI-generated Terraform code, I noticed something risky — it had written actual sensitive values directly inside the code files. Things like connection strings and access credentials were sitting in plain text, instead of being kept separate and protected.
This is a big problem. If this code ever got pushed to a shared repository, or shared with someone by mistake, those sensitive values would be exposed to anyone who could see the file. This is one of the most common and most dangerous security mistakes in cloud projects.
AI writes code to make things "work." It doesn't automatically think about security best practices unless you specifically ask for them. It gave me working code, but not safe code.
I caught it during review, moved all sensitive values into a separate, protected configuration (the way AWS and Terraform recommend), and made sure nothing sensitive was ever written directly into the code files.
Takeaway for you: Never trust AI-generated code blindly, especially around security. Always review it for hardcoded secrets, passwords, or keys before you commit or deploy it. Keep sensitive values separate from your code, always.
After this project, I built a simple habit:
Always read the full plan before applying any change
Check AWS docs for any service that might need special settings
Review generated code for hardcoded secrets or credentials before deploying
Never apply AI-generated code directly to a live project — test it first
Debug connection errors with a step-by-step checklist, not guesswork
Make small changes, one piece at a time, not everything at once
I'm not against using AI for cloud work. It really did save me time on the boring, repetitive parts. But this project taught me something important — AI can write code fast, but it doesn't understand your real project, your real account, or your real risks.
If you're using AI to help with AWS or Terraform, use it to save time on writing code, but stay responsible for checking it. Understand what each piece does, test small, and always know how to recover if something goes wrong.
AI can write the code. But you still need to understand the cloud.
I share real lessons like this from real client projects on my blog — follow along if you're learning AWS or Terraform.