Skip to main content

Cloud-Gym

Scalable Training Data Generation for Infrastructure-as-Code Repair via Environment Inversion.

Cloud-Gym generates (broken_config, error_message, fix) training pairs for IaC repair by applying environment inversion — taking working Terraform, CloudFormation, and OpenTofu configs and systematically breaking them using a defined fault taxonomy. It includes a benchmark (188 entries across 8 error categories) and fine-tuned models that run entirely on CPU.

stackfix: AI-Powered IaC Repair

The stackfix CLI tool validates and repairs broken IaC files using fine-tuned local models. No API keys, no cloud costs, no data leaves your machine.

Install

pip install stackfix

Download a Model

# Recommended: 3B Q4 (1.8 GB, 87% pass@1)
python -c "
from huggingface_hub import hf_hub_download
hf_hub_download('Tetsuto/iac-repair-3b-gguf', 'iac-repair-3b-q4.gguf', local_dir='.')
"

Usage

# Check files for errors
stackfix check main.tf template.yaml

# Repair a broken file (show diff)
stackfix repair main.tf --backend gguf --model iac-repair-3b-q4.gguf

# Repair and apply fix in place
stackfix repair main.tf --apply --backend gguf --model iac-repair-3b-q4.gguf

# Explain errors in plain language
stackfix discuss main.tf --backend gguf --model iac-repair-3b-q4.gguf

# Pipe mode (stdin/stdout)
cat broken.tf | stackfix repair - --backend gguf --model iac-repair-3b-q4.gguf > fixed.tf

# Check all changed IaC files in git
stackfix git-diff --backend gguf --model iac-repair-3b-q4.gguf

Models

Model Size RAM Speed (CPU) pass@1 HuggingFace
7B Q4 4.5 GB ~8 GB ~20 tok/s 0.926 Tetsuto/iac-repair-7b-gguf
3B Q4 1.8 GB ~4 GB 49 tok/s 0.867 Tetsuto/iac-repair-3b-gguf
0.5B Q4 379 MB ~800 MB 127 tok/s 0.723 Tetsuto/iac-repair-0.5b-gguf

All models are fine-tuned Qwen2.5-Coder with LoRA, exported to GGUF. They run on any CPU (Linux, macOS, Windows).

Backends

Backend Install Platform Use Case
gguf pip install stackfix Any (CPU) Default — CI/CD, Lambda, servers
mlx pip install stackfix[mlx] Apple Silicon Local dev on Mac
ollama pip install stackfix[ollama] + Ollama Any When Ollama is already running

CI/CD Integration

Add to your GitHub Actions workflow to catch IaC errors on every PR:

- name: Check IaC
  run: |
    pip install stackfix
    python -c "
    from huggingface_hub import hf_hub_download
    hf_hub_download('Tetsuto/iac-repair-3b-gguf', 'iac-repair-3b-q4.gguf', local_dir='.')
    "
    stackfix check **/*.tf **/*.yaml

See examples/USE_CASES.md for more deployment scenarios (pre-commit hooks, Lambda, pipeline integration).

Pre-Commit Hook

# .pre-commit-config.yaml
repos:
  - repo: local
    hooks:
      - id: stackfix
        name: stackfix
        entry: stackfix pre-commit --backend gguf --model iac-repair-3b-q4.gguf
        language: python
        types_or: [terraform, yaml]
        additional_dependencies: ['stackfix[gguf]']

Benchmark

188 entries across 8 error categories, 3 difficulty levels, and 2 formats (Terraform + CloudFormation).

Results Summary

Model pass@1 Terraform CloudFormation High Medium Low
7B v2 fine-tuned 0.926 0.993 0.750 0.960 0.897 0.923
3B rank4 fine-tuned 0.867 0.912 0.750 0.964 0.797 0.821
qwen2.5-coder:7b (base) 0.856 0.905 0.707 0.840 0.859 0.893
0.5B distilled 0.723 0.775 0.590 0.809 0.648 0.731
llama3.2:3b (base) 0.641 0.734 0.361 0.684 0.636 0.533
gemma-4-26b (base) 0.009 0.000 0.032 0.000 0.004 0.051

Fine-tuning a 0.5B model outperforms a 26B base model by 80x.

Training Data Generation

Cloud-Gym generates training data via environment inversion:

  1. Collect working IaC configs from GitHub, Terraform Registry, AWS samples
  2. Break them systematically using a fault taxonomy (28+ fault types across 8 categories)
  3. Validate broken configs to capture real error messages
  4. Pair (broken + errors) with the original working config as the gold fix
# Generate training data
cloud-gym taxonomy          # View fault types
python scripts/scrape.py    # Collect gold configs
cloud-gym invert            # Generate broken variants
cloud-gym export            # Export training pairs

Project Structure

cloudgym/
  taxonomy/     Fault type definitions (28+ types, 8 categories)
  scraper/      Gold config collection
  validator/    IaC validation wrappers (terraform, cfn-lint)
  inverter/     Fault injection engines
  generator/    Training data pipeline
  benchmark/    Evaluation harness
  fixer/        stackfix CLI tool + model backends
scripts/        Training, evaluation, and export scripts
examples/       Broken IaC examples + use case docs

Supported Formats

  • Terraform (.tf) — validated with terraform validate
  • CloudFormation (.yaml, .yml, .json) — validated with cfn-lint
  • OpenTofu (.tf) — same as Terraform

License

MIT

Metadata

Release files for stackfix 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stackfix 0.1.2
File Size Uploaded
stackfix-0.1.2.tar.gz 483.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stackfix 0.1.2
File Interpreter ABI Platform
stackfix-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 549.4 kB

Release files / stackfix-0.1.2.tar.gz

Download URL stackfix-0.1.2.tar.gz
Size 483.5 kB
Tags Source
SHA-256 checksum
How to use checksums
eb67f692849b0a6a65ebe64fd603cd368f6359680c302d9ec7792c6737740c88
BLAKE2b-256 checksum
How to use checksums
db97cddb6a7b4f9aed6127d884817a179e247902b195a235c887c834c3e49f95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / stackfix-0.1.2-py3-none-any.whl

Download URL stackfix-0.1.2-py3-none-any.whl
Size 65.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
37fc5d16ae3e20394d8db3de449bf88dd90c4dcdb4f18c23734ba8b85b061b11
BLAKE2b-256 checksum
How to use checksums
63206e6d6a56d00fb543bddc4770496c0c716c91f70243841b5f02171aabaa00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page