Metadata-Version: 2.4
Name: infragen
Version: 0.1.1
Summary: Multi-agent CLI that generates Terraform and deploys full-stack apps to AWS/GCP free tier
Project-URL: Repository, https://github.com/adityapanyala/infragen
Author: Aditya Panyala
License: MIT
Keywords: agents,aws,cli,free-tier,gcp,iac,llm,terraform
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Build Tools
Requires-Python: >=3.11
Requires-Dist: httpx>=0.27.0
Requires-Dist: langchain-core>=0.3.0
Requires-Dist: langchain-groq>=0.2.0
Requires-Dist: langgraph>=0.2.0
Requires-Dist: python-dotenv>=1.0.0
Requires-Dist: python-hcl2>=4.3.0
Requires-Dist: rich>=13.0.0
Requires-Dist: typer>=0.12.0
Provides-Extra: dev
Requires-Dist: build; extra == 'dev'
Requires-Dist: pytest>=8.0.0; extra == 'dev'
Requires-Dist: twine; extra == 'dev'
Description-Content-Type: text/markdown

# InfraGen

**Describe your app in plain English. Get it running on the AWS or GCP free tier.**

InfraGen is a multi-agent CLI that generates Terraform from natural language, audits every resource against free-tier limits *before* anything is created, shows you exactly what will happen, and — after you confirm — provisions the infrastructure and deploys your code onto it.

```
$ infragen deploy
detected: react frontend at ./frontend; fastapi backend at ./backend
free-tier eligible instance type: t3.micro
tf_write: attempt 1 generated 219 lines of HCL
guardrail: PASS, 0 warning(s)
validate: PASS
+--------------------------- review before deploy ---------------------------+
| terraform plan: 10 to add, 0 to change, 0 to destroy                       |
|   aws_instance.backend (created)                                           |
|   aws_s3_bucket.frontend (created)  ...                                    |
| free tier: all resources within free tier limits                           |
| deploy steps:                                                              |
|   1. build frontend (react)                                                |
|   2. upload frontend to s3://...                                           |
|   3. copy backend code to ubuntu@...                                       |
|   4. install dependencies and start fastapi on port 8000                   |
| estimated monthly cost: $0.00 (free tier)                                  |
+----------------------------------------------------------------------------+
Deploy this? [y/N]: y
...
deployment complete
  frontend_website_url = http://my-app.s3-website-us-east-1.amazonaws.com
  backend_public_ip    = 54.12.34.56
```

## Why InfraGen?

Free-tier users get surprise bills from two things: resources that were never free (NAT gateways, oversized instances) and forgotten resources left running. InfraGen guards both ends:

- A **deterministic free-tier auditor** checks every generated resource against hardcoded limit tables. An LLM can overlook a paid instance type; a dict lookup cannot. Ask for a `db.r5.xlarge` and you get a `db.t3.micro` with a comment explaining the substitution.
- **`infragen destroy`** tears down everything it created from tracked state, in one command.
- The review gate is backed by real `terraform plan` output — never by an AI's summary of what it *intended* to do.

---

## 1. Installation

```bash
pip install infragen
# or, isolated (recommended for CLI tools):
pipx install infragen
```

**Requirements — bring your own accounts, InfraGen ships no credentials:**

| Requirement | Where to get it |
|---|---|
| Python 3.11+ | https://python.org |
| Terraform CLI | https://developer.hashicorp.com/terraform/install |
| Groq API key (free, no credit card) | https://console.groq.com/keys |
| AWS account + CLI (`aws configure`), **or** GCP account + CLI (`gcloud auth login`) | https://aws.amazon.com/free / https://cloud.google.com/free |

Set your Groq key — either per project or globally:

```bash
# per project: a .env file in your project folder
echo GROQ_API_KEY=gsk_your_key_here > .env

# or globally, once:
echo GROQ_API_KEY=gsk_your_key_here > ~/.infragen.env
```

> Keep the key private. Never commit `.env` to git.

Then verify everything is ready:

```bash
infragen doctor
```

This checks terraform, your Groq key, AWS/GCP authentication, and (optionally) tflint, and tells you how to fix anything missing.

---

## 2. Deploy an app

From your project root:

```bash
infragen deploy              # scan, generate, review, confirm, deploy
infragen deploy --dry-run    # everything except apply - inspect first, great for CI
infragen deploy --provider gcp   # target Google Cloud instead of AWS
infragen deploy --regenerate # force fresh Terraform (default reuses .infragen/main.tf)
```

**What it does, step by step:**

1. **Scans your codebase** — detects React/Vue/Next/static frontends (via `package.json`), FastAPI/Flask/Django backends (via `requirements.txt` and entry-point detection), build commands, ports, and Dockerfiles.
2. **Checks your account** — queries which instance types are actually free-tier eligible for *your* AWS account (eligibility varies by account age since AWS's 2025 free-tier change).
3. **Generates Terraform** — an LLM agent writes HCL; a deterministic guardrail audits it; `terraform validate` checks it. Failures loop back to the writer with the errors (max 3 attempts).
4. **Shows the review panel** — the real `terraform plan` diff, free-tier status per resource, the exact deploy steps, and the cost ($0.00 or it doesn't pass).
5. **On your "y"** — applies the Terraform, then deploys code: builds and syncs the frontend to S3/GCS, copies the backend to the instance over ssh, installs dependencies in a venv, starts the server, and **verifies it responds** before reporting success.
6. **Writes docs** — a README in `.infragen/` describing what's deployed, its URLs, and how to clean up.

**Supported app shapes** (any combination):

| Your app | AWS | GCP |
|---|---|---|
| Static frontend (React/Vue/Next/plain HTML) | S3 static website | Cloud Storage website |
| Python backend (FastAPI/Flask/Django) | EC2 (free-tier instance) | Compute Engine e2-micro |

Everything generated lives in `.infragen/` inside your project — Terraform, state, deploy steps, docs. Re-running `infragen deploy` updates the **same** stack (it will not duplicate resources), so deploying a code change is just: edit code, run `infragen deploy`, confirm.

---

## 3. Tear it down

```bash
infragen destroy         # lists every resource, asks for confirmation
infragen destroy --yes   # skip the prompt
```

Empties S3/GCS buckets first (a non-empty bucket would otherwise block deletion), then destroys everything in state. **Free-tier hours are finite — never leave a test instance running.**

---

## 4. Other commands

```bash
infragen                          # interactive REPL: describe infra, get audited Terraform
infragen explain ./main.tf        # plain-English explanation of any Terraform file/dir
infragen translate ./ --to gcp    # convert AWS Terraform to GCP (or --to aws), audited
infragen validate ./              # terraform validate + free-tier audit + tflint
infragen doctor                   # check prerequisites
```

**The REPL** is for infrastructure without a codebase — describe what you want and get validated, free-tier-audited HCL saved to `.infragen/`:

```
infragen> create an S3 bucket with versioning for app assets
infragen> a lambda function behind API gateway with a dynamodb table
infragen> exit
```

**Try asking for something expensive** — `create a db.r5.xlarge postgres RDS` — and watch it substitute the free-tier equivalent instead of refusing or obeying.

---

## 5. Troubleshooting

| Symptom | Fix |
|---|---|
| `infragen` is not recognized as a command | pip's scripts folder isn't on PATH. Use `python -m infragen` instead, or install with `pipx install infragen` (puts CLIs on PATH reliably), or add the folder printed by `python -c "import sysconfig; print(sysconfig.get_path('scripts'))"` to your PATH |
| Red "setup required" panel | Follow its instructions — missing Groq key or cloud CLI auth |
| ssh/scp step fails right after first deploy | The instance may still be booting (~90s). Re-run `infragen deploy` — it's idempotent |
| `BACKEND_FAILED` + log tail in the start step | Your app crashed on the server; the tail of `app.log` is printed — fix and redeploy |
| Deploy succeeded but app changed since | Just run `infragen deploy` again — infra stays, code re-deploys |
| Want to start over completely | `infragen destroy`, delete `.infragen/`, then `infragen deploy --regenerate` |

---

## How it works (for the curious)

A LangGraph state machine drives generation, running on Groq's free LLM tier (`openai/gpt-oss-120b`, with live model-availability checks since Groq rotates models). The design rule throughout: **anything safety- or correctness-critical is deterministic code — LLMs only generate and explain.** The free-tier auditor is an HCL parser plus rule tables. The deployment steps are built from your scanned app spec plus real terraform outputs. The review panel parses actual `terraform plan` text. The server-start step curls the app from inside the instance and refuses to report success if it doesn't answer.

## Development

```bash
git clone https://github.com/adityapanyala/infragen.git
cd infragen
pip install -e ".[dev]"
python -m pytest tests/ -q     # 30 tests, no API key or network needed
```

## License

MIT
