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

# Terraform

> Manage DNZ records from Terraform with a generic REST provider.

There's no DNZ provider yet. A generic REST provider such as
[`Mastercard/restapi`](https://registry.terraform.io/providers/Mastercard/restapi/latest) works with
DNZ's [records API](/api/records).

**1. Create a token**

Under **Settings → API tokens**, create a token with `records.write` (and `zones.read`), limited
to the zones Terraform manages. See [API tokens](/api/overview#api-tokens).

**2. Find the zone's id**

```bash theme={null}
curl -H "Authorization: Bearer $DNZ_TOKEN" https://dns.example.com/api/token
```

The answer lists the zones the token can reach, with their ids. Or run
`dnz --json zone list`.

**3. Describe the records**

```hcl main.tf theme={null}
provider "restapi" {
  uri                  = "https://dns.example.com/api"
  headers              = { Authorization = "Bearer ${var.dnz_token}" }
  write_returns_object = true
}

resource "restapi_object" "app" {
  path          = "/zones/3/records"
  update_path   = "/records/{id}"
  destroy_path  = "/records/{id}"
  update_method = "PATCH"
  data = jsonencode({ name = "app", type = "A", value = "192.0.2.20", ttl = 300 })
}
```

Every change Terraform makes appears in the [audit log](/admin/audit-log) as the token's creator
"via" the token's name.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.