Table of Contents
Fetching ...

TerraFormer: Automated Infrastructure-as-Code with LLMs Fine-Tuned via Policy-Guided Verifier Feedback

Prithwish Jana, Sam Davidson, Bhavana Bhasker, Andrey Kan, Anoop Deoras, Laurent Callot

TL;DR

TerraFormer addresses the challenge of generating correct Infrastructure-as-Code (IaC) from natural language by coupling large language models with formal verifiers that assess compilability, deployability, and policy compliance. It builds two large NL-to-IaC datasets, TF-Gen for generation and TF-Mutn for mutation, through multi-turn verifier-guided repair loops and self-correction, enabling robust supervised fine-tuning and reinforcement learning. Evaluations against 17 state-of-the-art LLMs—including models orders of magnitude larger—show TerraFormer achieving higher correctness on TF-Gen and TF-Mutn, while ranking competitively on IaC-Eval and delivering top best-practices and security compliance. The approach demonstrates that verifier-driven feedback can significantly improve intent alignment and deployability, with a scalable data pipeline extendable to other IaC tools and code-generation domains.

Abstract

Automating Infrastructure-as-Code (IaC) is challenging, and large language models (LLMs) often produce incorrect configurations from natural language (NL). We present TerraFormer, a neuro-symbolic framework for IaC generation and mutation that combines supervised fine-tuning with verifier-guided reinforcement learning, using formal verification tools to provide feedback on syntax, deployability, and policy compliance. We curate two large, high-quality NL-to-IaC datasets, TF-Gen (152k instances) and TF-Mutn (52k instances), via multi-stage verification and iterative LLM self-correction. Evaluations against 17 state-of-the-art LLMs, including ~50x larger models like Sonnet 3.7, DeepSeek-R1, and GPT-4.1, show that TerraFormer improves correctness over its base LLM by 15.94% on IaC-Eval, 11.65% on TF-Gen (Test), and 19.60% on TF-Mutn (Test). It outperforms larger models on both TF-Gen (Test) and TF-Mutn (Test), ranks third on IaC-Eval, and achieves top best-practices and security compliance.

TerraFormer: Automated Infrastructure-as-Code with LLMs Fine-Tuned via Policy-Guided Verifier Feedback

TL;DR

TerraFormer addresses the challenge of generating correct Infrastructure-as-Code (IaC) from natural language by coupling large language models with formal verifiers that assess compilability, deployability, and policy compliance. It builds two large NL-to-IaC datasets, TF-Gen for generation and TF-Mutn for mutation, through multi-turn verifier-guided repair loops and self-correction, enabling robust supervised fine-tuning and reinforcement learning. Evaluations against 17 state-of-the-art LLMs—including models orders of magnitude larger—show TerraFormer achieving higher correctness on TF-Gen and TF-Mutn, while ranking competitively on IaC-Eval and delivering top best-practices and security compliance. The approach demonstrates that verifier-driven feedback can significantly improve intent alignment and deployability, with a scalable data pipeline extendable to other IaC tools and code-generation domains.

Abstract

Automating Infrastructure-as-Code (IaC) is challenging, and large language models (LLMs) often produce incorrect configurations from natural language (NL). We present TerraFormer, a neuro-symbolic framework for IaC generation and mutation that combines supervised fine-tuning with verifier-guided reinforcement learning, using formal verification tools to provide feedback on syntax, deployability, and policy compliance. We curate two large, high-quality NL-to-IaC datasets, TF-Gen (152k instances) and TF-Mutn (52k instances), via multi-stage verification and iterative LLM self-correction. Evaluations against 17 state-of-the-art LLMs, including ~50x larger models like Sonnet 3.7, DeepSeek-R1, and GPT-4.1, show that TerraFormer improves correctness over its base LLM by 15.94% on IaC-Eval, 11.65% on TF-Gen (Test), and 19.60% on TF-Mutn (Test). It outperforms larger models on both TF-Gen (Test) and TF-Mutn (Test), ranks third on IaC-Eval, and achieves top best-practices and security compliance.
Paper Structure (10 sections, 3 equations, 7 figures, 3 tables)

This paper contains 10 sections, 3 equations, 7 figures, 3 tables.

Figures (7)

  • Figure 1: Learning Objectives. Task definitions for IaC generation, i.e., creating Terraform configurations from scratch, and IaC mutation, i.e., modifying existing configurations, both taking natural language (NL) prompts as input.
  • Figure 2: Terraform Example. IaC with 2 providers (AWS, Docker) and 2 resources (S3, container) with a dependency.
  • Figure 3: Dataset Curation Pipeline. (a) Multi-turn repair loops with LLMs and verifiers produce verified Terraform configurations, NL prompts, and FL policies. (b) TF-Gen extends SeedCorpus by cloning triplets to produce multiple implementations for an infrastructure. (c) TF-Mutn augments SeedCorpus with mutated configurations, mutation prompts, and FL policies.
  • Figure 4: Learning Objectives. Instruction-tuning LLMs for the tasks of IaC generation and mutation via SFT and RL
  • Figure 5: Survey on Semantic Alignment. Cloud-expert ratings for prompt–IaC–policy alignment on sampled TF-Gen and TF-Mutn instances, and inter-rater agreement.
  • ...and 2 more figures