Large Language Models (LLMs) have become remarkably adept at writing general-purpose code in languages like Python and Java. However, the complex, interconnected world of cloud computing presents a significantly tougher challenge. Presented at NeurIPS 2024, IaC-Eval is the first comprehensive benchmark designed specifically to track how well LLMs can write "Infrastructure-as-Code" (IaC).
The results serve as a wake-up call: even top-tier models like GPT-4, which ace general coding tests, fail nearly 80% of these infrastructure tasks, highlighting a massive "domain gap" in AI capabilities.
The Challenge of Infrastructure-as-Code
In modern software development, cloud infrastructure is rarely provisioned manually through a dashboard. Instead, developers write code—often using HashiCorp Configuration Language (HCL) for Terraform—to define servers, databases, and networks.
Writing IaC is notoriously difficult. A single cloud resource, such as an AWS database, can be configured in dozens of ways and must be perfectly wired to networks, security groups, and identity roles. If a single connection is misconfigured, the entire system can fail. While LLMs show promise in general programming, evaluating their ability to handle the high-stakes requirements of cloud orchestration has been difficult. Furthermore, testing IaC code by deploying it to a real cloud environment is slow, complex, and costs actual money.
Methodology: A Deployment-Free Evaluation Pipeline
To solve the evaluation bottleneck, the researchers developed a clever, two-phase pipeline that avoids the cost and time of real cloud deployments:
- Syntactic & Provider Check: The LLM-generated code is first passed through
terraform plan. This verifies syntactic correctness and ensures the code adheres to the cloud provider's basic rules (e.g., verifying that a specified attribute actually exists). - Intent Fulfillment: To verify if the generated code actually does what the user asked, the authors utilized OPA (Open Policy Agent) and the Rego policy language. For example, if a prompt requests a "private database," a Rego policy checks the generated plan to ensure the database isn't accidentally attached to a public subnet.
This "compile-time" approach allows for rapid, scalable testing without ever spinning up a single virtual machine.
The IaC-Eval Dataset
The benchmark is powered by the IaC-Eval dataset, which consists of 458 human-curated scenarios covering a wide range of AWS services (such as VPC, S3, RDS, and Lambda). These scenarios are ranked on a difficulty scale from 1 to 6, based on the lines of code required, the number of resources involved, and the complexity of their interconnections.
Key Findings and Model Performance
The benchmark reveals a startling disparity in performance, termed the "IaC Gap." While GPT-4 scores approximately 86% on standard Python benchmarks like EvalPlus, its performance plummets on IaC-Eval. This suggests that IaC requires a level of "architectural reasoning" that current models lack.
Key performance insights include:
- Top Performers Still Struggle: GPT-4 was the top performer but only achieved a 19.36% pass@1 accuracy. WizardCoder-33B followed at 8.93%, while CodeLlama-7B struggled at just 1.97%.
- Structural Hallucinations: LLMs often generate perfect syntax but "hallucinate" how services connect. For instance, a model might create a server and a disk but forget to write the code that actually plugs the disk into the server.
- RAG is Highly Effective: Retrieval-Augmented Generation provided the biggest performance boost. By providing the model with snippets of actual AWS documentation, GPT-4’s score jumped significantly from 19% to 36%.
- Self-Correction Works: Multi-turn prompting showed that models can fix their own mistakes if they are fed the error messages from the Terraform compiler.
- LLM-as-a-Judge Fails: The study found that using an LLM to grade another LLM's IaC code is unreliable. Models often mark incorrect infrastructure as "correct" simply because the code looks plausible.
Limitations and Future Work
Currently, the IaC-Eval benchmark is limited to AWS and Terraform, and it does not yet evaluate complex HCL features like custom functions or loops. Future iterations aim to expand to Azure, Google Cloud, and other IaC tools like Pulumi. Additionally, researchers plan to include "security-aware" prompts to test if LLMs accidentally introduce vulnerabilities (like open firewalls) while solving functional problems.
The IaC-Eval dataset and framework have been open-sourced to encourage the community to close this critical gap in AI-assisted cloud engineering.
Summary updated