DevOps & Platform Eng

AI & Terraform Security: Not a Replacement for Judgment

Terraform code is a map of your cloud's defenses. AI can help read it, but it can't replace your judgment. Here's how to use AI without sacrificing security.

A flowchart illustrating the AI-assisted Terraform security review process with human oversight.

Key Takeaways

  • AI tools like Codex and Claude Code can speed up Terraform security reviews by identifying risky patterns and explaining potential attack paths.
  • AI should assist, not replace, human security judgment; critical context and risk assessment remain the responsibility of the security engineer.
  • Sensitive production data and credentials should never be directly exposed to AI models during reviews, even when using local workflows.

Does your cloud infrastructure’s security depend on an AI bot? We need to talk.

Terraform isn’t just code. It’s the blueprint for your entire cloud control plane. Who gets access to production. What’s exposed to the screaming void of the internet. Where your precious logs go to die. How identities get their trust baked in. And critically, what can actually change anything. This isn’t casual stuff. It demands the same rigor as application security. Sometimes, more.

AI coding assistants, like Codex and Claude Code, are here. They promise faster reviews. Great. But they absolutely should not replace your own hard-won security sense. Think of them as highly motivated interns. They can read through massive repositories. Spot risky patterns. Even explain how an attacker might slither through. They can draft better remediation notes, too. But the final say? That rests with you. The human. The one who still has to answer for the breach.

So, you’re a junior security engineer. The prod deployment looms. You’re handed a Terraform repo. Your mission: review it. This is your practical guide. A way to keep the review safe, structured, and actually useful for the folks who built it. We’re talking AI-assisted workflows, not AI-dictated security.

We’ll look at two paths:

Codex, wired into a GitHub repo. Good for looking across the whole thing. For GitHub workflows. For proposing patches.

Claude Code, launched from a local clone. Better for terminal-first digging. For validation commands. For running scanners.

This isn’t about crowning a winner. It’s about using each tool where it makes sense. With the same damn security discipline.

So, What’s the Real Risk?

You’ve been tasked:

“Can you review this Terraform repo before we deploy it to production?”

And the repo looks like this:

terraform/
├── environments/
│ ├── dev/
│ ├── staging/
│ └── prod/
├── modules/
│ ├── networking/
│ ├── iam/
│ ├── compute/
│ ├── storage/
│ └── eks/
├── providers.tf
├── versions.tf
├── variables.tf
└── outputs.tf

A lazy prompt like “find security issues” is useless. A real review answers specific questions:

  • What cloud assets does this repo control?
  • Which resources are wide open to the internet?
  • Where are IAM permissions unnecessarily broad?
  • Is sensitive data handled, sent, and logged securely?
  • Are logs actually enabled for incident response?
  • Are secrets, state files, or sensitive outputs leaking?
  • What proposed fixes might break production?
  • Which findings need a human check before a PR?

Here’s the mindset: You’re not just finding bad Terraform. You’re uncovering future production risks.

Take an aws_security_group_rule that allows 0.0.0.0/0 to TCP/22. Your job isn’t just “public SSH is bad.” It’s confirming where that rule lives, who uses it, if there’s a legitimate bastion host or VPN path, and whether tightening it will block critical support.

That’s the difference between a basic scan and a professional review.

When we say local repository, we mean a standard Git clone on your machine. Your laptop. Your jump box. Wherever you do your actual work. It does not mean a local AI model.

Claude Code might still use a cloud service. “Local” just means the Terraform files are on your system during review.

Here’s a breakdown of the workflows:

Workflow Repo Location Best For
Codex GitHub repo (connected to AI) Repository-wide review, GitHub workflows, patch proposals
Claude Code Locally cloned repo Terminal-first review, Terraform validation, scanner-assisted analysis

Choose based on your company’s policies, how sensitive the repo is, your access, and how much control you need.

Give AI the code it needs to see. But keep production authority with humans and approved automation.

The AI can help you read Terraform. Understand risk. Suggest changes. Write review notes. But production credentials, deployment rights, and approval authority? That stays out of the AI’s hands. Unless your org has explicitly signed off on a different model.

Keep these out of the AI workflow unless your security policy says otherwise:

  • Production cloud credentials
  • Terraform state files (terraform.tfstate)
  • Variable files with real secrets (prod.tfvars)
  • Private keys
  • Kubeconfigs
  • CI/CD secrets
  • Vault tokens
  • Break-glass credentials

A well-scoped AI review can still flag serious issues from code alone. Think public ingress, wildcard IAM, missing encryption, no logging, exposed outputs, unsafe defaults, weak remote state configurations, and over-permissioned CI/CD pipelines.

You don’t need to give an AI tool production authority to get solid security value.

Why Does Human Judgment Still Matter?

Before you even feed code into Codex or Claude, give the repository a good look. Are there files that shouldn’t be casually shared? Sensitive data? Things that AI might misinterpret or overexpose?

Then, use the AI to get a baseline. Ask it to find all aws_security_group resources. Or list all IAM roles with * in their policies. Or identify resources missing logging configurations.

It’s a powerful starting point.

But here’s the critical part: AI doesn’t understand context.

It can tell you an SSH port is open to the world. It cannot tell you if that’s a critical vulnerability because the machine is behind a hardened bastion host that only allows access via SSH, and the security group is the only way to restrict access to that specific bastion host IP. The AI just sees 0.0.0.0/0 and screams.

Your job is to interpret these findings. To understand the business context. To know if a proposed fix will break the app that pays your salary. AI can flag syntax. It can flag known bad patterns. It can’t do the nuanced risk assessment.

What About AI-Generated Fixes?

AI can suggest remediations. It can even draft pull requests. This is where it gets interesting, and potentially dangerous.

Say you have an overly permissive IAM policy. An AI might suggest a more restrictive one. Great! But is that new policy too restrictive? Will it break essential services? The AI, again, lacks the deep understanding of your application’s dependencies and operational requirements.

Proposed fixes must be validated by a human with operational knowledge before they are merged. This is non-negotiable for production stability.

This is where the accountability loop comes in. The AI provides suggestions. You — the security engineer — validate them. You test them. You ensure they don’t cause cascading failures. You open the pull request with your confident assessment, not just a copy-paste from the AI.

Think of it like this: AI can draft the architectural diagrams, but a human engineer signs off on the building permits.

The Human Element in a Sea of Code

The takeaway is simple, yet often overlooked in the rush for AI adoption: tools are aids, not replacements.

Codex and Claude can accelerate the tedious parts of a Terraform review. They can surface common misconfigurations and potential vulnerabilities with incredible speed. They can help junior engineers learn by explaining complex configurations.

But the ultimate responsibility for securing your infrastructure lies with the humans who understand its purpose, its operational constraints, and the real-world threats it faces. Treat AI as a powerful assistant, not an autonomous security guard. Your production environment depends on it.


🧬 Related Insights

Jordan Kim
Written by

Cloud and infrastructure correspondent. Covers Kubernetes, DevOps tooling, and platform engineering.

Worth sharing?

Get the best Developer Tools stories of the week in your inbox — no noise, no spam.

Originally reported by dev.to

Stay in the loop

The week's most important stories from DevTools Feed, delivered once a week.