# terrafy

![Python](https://img.shields.io/badge/python-3.9%2B-blue?logo=python&logoColor=white)
![License](https://img.shields.io/github/license/ifaakash/terrafy)
![Issues](https://img.shields.io/github/issues/ifaakash/terrafy)
![Last Commit](https://img.shields.io/github/last-commit/ifaakash/terrafy)
![Gemini](https://img.shields.io/badge/powered%20by-Gemini-8E75B2?logo=google&logoColor=white)

> CLI to generate production-ready Terraform HCL configuration from human language — powered by Gemini.

---

## How It Works

1. **Authenticate** — provide your Gemini API key
2. **Create** — describe your infrastructure in plain English
3. **Done** — terrafy generates a `.tf` file and saves it locally

---

## Installation

### Requirements

- Python 3.9+
- [Gemini API key](https://aistudio.google.com/app/apikey)

### Build & Install

```bash
python3 -m build
pip3 install .
```

### Rebuild (clean)

```bash
rm -rf build/ dist/ src/*.egg-info
python3 -m build
pip3 install .
```

---

## Usage

### Step 1 — Authenticate

```bash
terrafy authenticate <GEMINI_API_KEY>
```

### Step 2 — Generate HCL

```bash
terrafy create "Create an S3 bucket to hold images. The name starts with the environment then project prefix"
```

This will:
- Call Gemini with your request
- Print the generated HCL to the terminal
- Save it to a named `.tf` file (e.g. `s3_bucket.tf`) in your current directory

### View Docs

```bash
terrafy docs
```

---

## Commands

| Command        | Description                              | Example                                      |
|----------------|------------------------------------------|----------------------------------------------|
| `authenticate` | Set your Gemini API key                  | `terrafy authenticate sk-qwerty`             |
| `create`       | Generate HCL from a natural language request | `terrafy create "S3 bucket for images"` |
| `docs`         | Show usage instructions                  | `terrafy docs`                               |

---

## Dependencies

- [typer](https://typer.tiangolo.com/) — CLI framework
- [rich](https://github.com/Textualize/rich) — terminal formatting
- [google-genai](https://github.com/googleapis/python-genai) — Gemini API client
