AI
LLMs Struggle to Generate Secure Cloud Infrastructure Code, Study Finds
A benchmark of seven AI models reveals that code validity and security compliance are disconnected—and prompt engineering alone cannot fix it.
Researchers have tested whether large language models can reliably generate secure Infrastructure-as-Code (IaC) configurations for cloud environments. The findings suggest that the ability to produce syntactically correct code does not translate to security-compliant outputs—a critical gap as cloud misconfiguration remains a leading source of security breaches.
The Benchmark Study#
The team evaluated seven models across AWS Terraform generation tasks: three proprietary LLMs (Claude Opus 4, GPT-5.4, and Gemini 2.5 Pro) and four open-source smaller language models (Qwen2.5-Coder-14B, WizardCoder-33B, CodeLlama-13B, and Magicoder-S-CL-7B). The experiments spanned 17 scenarios with integrated security scanning using Checkov and Trivy tools within a GitLab CI/CD pipeline. Researchers tested two distinct prompt strategies at three security levels, using a pass@5 methodology to measure success.
Validity vs. Security: A Broken Connection#
The core finding challenges a common assumption: syntactic validity and security compliance operate largely independently in AI-generated infrastructure code. For example, WizardCoder-33B produced well-formed Terraform in 77.8% of test cases yet achieved zero compliance when scanned by Checkov. Meanwhile, Claude Opus 4 attained only 23.1% Checkov compliance but reached 92.5% Trivy pass rates when given detailed security-focused prompts—illustrating how results vary across both models and scanning tools.
This decoupling means that developers cannot assume code that "looks right" is actually secure, regardless of which model generates it.
The Limits of Prompt Engineering#
While refined prompting strategies modestly improve security outcomes, the research concludes that engineering prompts alone is insufficient. Automated multi-tool scanning remains a necessary safeguard for any IaC generation workflow, independent of whether the model is closed, open-source, large, or small. The findings underscore that human review and validation layers are essential complements to LLM-assisted infrastructure development.
The researchers have made all experimental artifacts publicly available to support further investigation in this critical area.

