> ## 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.

# Terraform Quickstart

> Set up DevHelm monitoring with Terraform in 5 minutes — from provider install to your first plan and apply

Get your first DevHelm monitor running with Terraform in 5 minutes.

## Prerequisites

* [Terraform](https://developer.hashicorp.com/terraform/install) 1.5 or later
* A DevHelm API token — create one from **Settings → API Keys** in the [Dashboard](https://app.devhelm.io)

Set your token as an environment variable so the provider picks it up automatically:

```bash theme={null}
export DEVHELM_API_TOKEN=dh_live_xxxxxxxx
```

## 1. Configure the provider

Create a `main.tf` file:

```hcl theme={null}
terraform {
  required_version = ">= 1.5.0"
  required_providers {
    devhelm = {
      source  = "devhelmhq/devhelm"
      version = "0.2.0-beta.7"
    }
  }
}

provider "devhelm" {}
```

Initialize the working directory:

```bash theme={null}
terraform init
```

<Note>
  The provider reads `DEVHELM_API_TOKEN` from the environment. You can also set
  `token` directly in the provider block, but environment variables keep secrets
  out of your HCL files.
</Note>

## 2. Create a monitor

Add an HTTP monitor resource to your `main.tf`:

```hcl theme={null}
resource "devhelm_monitor" "api_health" {
  name              = "API Health"
  type              = "HTTP"
  frequency_seconds = 60
  regions           = ["us-east", "eu-west"]

  config = jsonencode({
    url       = "https://api.example.com/health"
    method    = "GET"
    verifyTls = true
  })

  assertions {
    type   = "status_code"
    config = jsonencode({ expected = "200", operator = "equals" })
  }

  assertions {
    type     = "response_time"
    config   = jsonencode({ thresholdMs = 2000 })
    severity = "warn"
  }
}
```

<Note>
  `config` and `assertions[].config` are JSON strings, not HCL blocks. Use
  `jsonencode({...})` with **camelCase** field names — they map directly to the
  API wire format.
</Note>

## 3. Plan and apply

Preview what Terraform will create:

```bash theme={null}
terraform plan
```

You should see one resource to add. Apply it:

```bash theme={null}
terraform apply
```

Type `yes` to confirm. Your monitor is now live and checking every 60 seconds.

## 4. Add an alert channel

Wire up Slack (or any other channel) so you get notified when things break:

```hcl theme={null}
resource "devhelm_alert_channel" "slack" {
  name         = "Engineering Slack"
  channel_type = "slack"
  webhook_url  = var.slack_webhook_url
}

variable "slack_webhook_url" {
  type      = string
  sensitive = true
}
```

Link the alert channel to your monitor:

```hcl theme={null}
resource "devhelm_monitor" "api_health" {
  # ... same config as above ...

  alert_channel_ids = [devhelm_alert_channel.slack.id]
}
```

Run `terraform apply` again — the monitor now routes failures to your Slack channel.

## 5. Organize with tags

```hcl theme={null}
resource "devhelm_tag" "production" {
  name  = "production"
  color = "#10b981"
}

resource "devhelm_monitor" "api_health" {
  # ... same config as above ...

  tag_ids = [devhelm_tag.production.id]
}
```

## Import existing resources

Already have monitors in the dashboard? Import them into Terraform state by name:

```bash theme={null}
terraform import devhelm_monitor.api_health "API Health"
terraform import devhelm_alert_channel.slack "Engineering Slack"
```

See [Importing resources](/mac/terraform/importing) for the full ID table.

## Next steps

<CardGroup cols={2}>
  <Card title="Provider overview" icon="book" href="/mac/terraform/overview">
    Full provider reference with all resources and data sources.
  </Card>

  <Card title="Monitor resource" icon="signal" href="/mac/terraform/monitors">
    Complete devhelm\_monitor attribute reference.
  </Card>

  <Card title="Alert channels" icon="bell" href="/mac/terraform/alert-channels">
    Channel-type-specific Terraform arguments.
  </Card>

  <Card title="Terraform in CI/CD" icon="rotate" href="/mac/terraform/ci-cd">
    Automate plans and applies in GitHub Actions or other CI systems.
  </Card>
</CardGroup>
