> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devhelm.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Monitoring as Code

> Define your DevHelm monitoring stack in code — YAML, Terraform, and CI/CD patterns

Monitoring as Code (MaC) lets you define monitors, alert channels, notification policies, and more as version-controlled configuration. Choose the tool that fits your workflow:

| Tool           | Best for                                         | Format        |
| -------------- | ------------------------------------------------ | ------------- |
| **YAML + CLI** | Fast iteration, standalone monitoring config     | `devhelm.yml` |
| **Terraform**  | Managing monitors alongside cloud infrastructure | HCL (`.tf`)   |

## YAML + CLI

The fastest path to monitoring as code. Define everything in a single `devhelm.yml` and deploy with the CLI.

```yaml theme={null}
version: "1"

monitors:
  - name: API Health
    type: HTTP
    config:
      url: https://api.example.com/health
      method: GET
    frequencySeconds: 60
    regions: [us-east, eu-west]

alertChannels:
  - name: Slack Alerts
    config:
      channelType: slack
      webhookUrl: ${SLACK_WEBHOOK_URL}
```

```bash theme={null}
devhelm deploy -f devhelm.yml --yes
```

<CardGroup cols={2}>
  <Card title="YAML file format" icon="file-code" href="/mac/yaml/file-format">
    Full schema reference for devhelm.yml.
  </Card>

  <Card title="Deploy workflow" icon="rocket" href="/mac/yaml/workflow">
    Validate, plan, and deploy lifecycle.
  </Card>
</CardGroup>

## Terraform provider

Manage DevHelm resources as Terraform infrastructure alongside AWS, GCP, or any other provider.

```hcl theme={null}
resource "devhelm_monitor" "api" {
  name              = "API Health"
  type              = "HTTP"
  frequency_seconds = 60
  regions           = ["us-east", "eu-west"]
  config            = jsonencode({ url = "https://api.example.com/health" })
}
```

<CardGroup cols={2}>
  <Card title="Terraform overview" icon="cube" href="/mac/terraform/overview">
    Provider setup, resources, and data sources.
  </Card>

  <Card title="Terraform monitors" icon="signal" href="/mac/terraform/monitors">
    Full devhelm\_monitor resource reference.
  </Card>
</CardGroup>

## CI/CD patterns

Automate deploys on every push. Preview changes in pull requests.

<CardGroup cols={3}>
  <Card title="CI/CD overview" icon="rotate" href="/mac/ci-cd/overview">
    Common patterns across CI systems.
  </Card>

  <Card title="GitHub Actions" icon="github" href="/mac/ci-cd/github-actions">
    Official setup-devhelm action.
  </Card>

  <Card title="Generic CI" icon="gears" href="/mac/ci-cd/generic">
    GitLab, Jenkins, CircleCI, and more.
  </Card>
</CardGroup>

## Choosing between YAML and Terraform

| Consideration                | YAML + CLI             | Terraform                       |
| ---------------------------- | ---------------------- | ------------------------------- |
| Setup time                   | Minutes                | Requires Terraform knowledge    |
| State management             | API is source of truth | Terraform state file            |
| Cloud resource co-management | No                     | Yes                             |
| PR preview                   | `devhelm plan`         | `terraform plan`                |
| Multi-environment            | Per-env YAML files     | Terraform workspaces or modules |

<Warning>
  Don't manage the same resource with both YAML and Terraform. Pick one source of truth per resource to avoid drift and conflicts.
</Warning>
