Terraform and OpenTofu
Manage Arc databases, API tokens, retention policies and continuous queries as code with the basekick-labs/arc provider for Terraform and OpenTofu, and import what you already run.
The basekick-labs/arc provider manages a running Arc as code, from Terraform or OpenTofu. It configures the server over Arc's HTTP API. It does not install Arc: use the packages, images or Helm chart for that.
| Resource | What it manages |
|---|---|
arc_database | A database. Destroying it deletes its data, so the provider refuses unless you set force_destroy. |
arc_token | An API token and its permissions. The secret is in the value attribute. |
arc_retention_policy | Deletes data older than a number of days from a database or one measurement. |
arc_continuous_query | Runs a SQL query on a schedule and writes the result to another measurement. |
Data sources: arc_server (mode, license, cluster role), arc_databases, and arc_token (looks a token up by name, without its secret).
On Arc Enterprise, the same provider also manages RBAC, tiered-storage policies and query governance.
Versions
The provider works with Arc 26.09.4 and later. It is tested with Terraform 1.5 and 1.17, and with OpenTofu 1.13.
Set up the provider
Get an admin token
The provider needs a token with the admin permission. On a new install, Arc logs its first admin token at startup, or you set it yourself with ARC_AUTH_BOOTSTRAP_TOKEN; see Authentication.
Keep the token out of your configuration files. The provider reads ARC_ENDPOINT and ARC_TOKEN from the environment:
export ARC_ENDPOINT=http://localhost:8000
export ARC_TOKEN="<admin-api-token>"Declare the provider
terraform {
required_providers {
arc = {
source = "basekick-labs/arc"
version = "~> 0.1"
}
}
}
# endpoint and token come from ARC_ENDPOINT and ARC_TOKEN.
provider "arc" {}terraform init (or tofu init) downloads the provider from the registry. Every terraform command on this page works the same with tofu.
Describe what you want
resource "arc_database" "metrics" {
name = "metrics"
}
resource "arc_token" "grafana" {
name = "grafana"
description = "Grafana dashboards, read only"
permissions = ["read"]
}
resource "arc_retention_policy" "metrics_90d" {
name = "metrics-90d"
database = arc_database.metrics.name
retention_days = 90
is_active = true
}
output "grafana_token" {
value = arc_token.grafana.value
sensitive = true
}Run terraform apply. Running terraform plan again shows no changes.
Provider settings
| Setting | Environment variable | Default | Meaning |
|---|---|---|---|
endpoint | ARC_ENDPOINT | none | Base URL of the Arc node, for example https://arc.example.com:8000. |
token | ARC_TOKEN | none | An admin token. Not needed when Arc runs with auth.enabled = false; arc_token then cannot be used. |
ca_cert_pem | — | none | PEM certificate to trust when Arc's TLS certificate comes from a private CA. |
insecure_skip_verify | — | false | Skip TLS verification. For testing only. |
request_timeout | — | 60s | Timeout for a single HTTP request. |
consistency_timeout | — | 30s | How long the provider keeps retrying after a write: until a refusal that changed nothing clears, or until the change becomes visible. |
When the provider starts, it checks that the endpoint answers like Arc and that the token is valid and has admin. It never follows redirects, so the token is only ever sent to the endpoint you configured.
Databases
resource "arc_database" "metrics" {
name = "metrics"
force_destroy = false
}A name starts with a letter, contains only letters, digits, _ and -, and is at most 64 characters long. system, internal and _internal are reserved. Changing name replaces the database.
Destroying an arc_database deletes every file of the database. The provider refuses unless force_destroy = true is in the state. To delete a database, set force_destroy = true and apply that first, then destroy.
Arc must also allow deletes: set delete.enabled = true on the server. A large database can take a while to delete. The timeouts block raises the default limit of 10 minutes; like force_destroy, apply it before you destroy:
resource "arc_database" "archive" {
name = "archive"
force_destroy = true
timeouts {
delete = "30m"
}
}Tokens
resource "arc_token" "telegraf" {
name = "telegraf"
permissions = ["write"]
expires_at = "2027-12-31T00:00:00Z"
rotation_triggers = {
rotated = "2026-12"
}
}| Attribute | Notes |
|---|---|
permissions | Any of read, write, delete, admin. An empty set ([]) makes a token whose access comes only from RBAC teams (Arc Enterprise). |
expires_at | An RFC 3339 time, at least a minute and at most 36,500 days away. Arc cannot remove an expiry, so removing it replaces the token. Use a fixed time, not timestamp(), which changes on every plan. |
rotation_triggers | Change any value to rotate the secret; the token keeps its ID. Adding triggers to a token that had none does not rotate it. |
value | Read-only. The secret, marked sensitive. |
enabled | Read-only. false once the token has been revoked. A revoke cannot be undone, so the next apply replaces a revoked token. |
The secret is stored in state
Arc shows a token's secret only when the token is created or rotated, so the provider keeps value in Terraform state. Use a state backend that encrypts at rest, and restrict who can read it.
The provider refuses to rotate or delete the token it is itself configured with, and to remove admin from it. Doing any of those in the middle of an apply would lock the provider out.
Retention policies
resource "arc_retention_policy" "cpu_30d" {
name = "cpu-30d"
database = arc_database.metrics.name
measurement = "cpu"
retention_days = 30
buffer_days = 1
is_active = true
}is_active is required, because an active policy deletes data. Leave measurement unset to cover the whole database. retention_days must be greater than buffer_days.
Arc stores policies on any server, but its retention scheduler runs only with an Arc Enterprise license. Without a license, the provider warns you when you activate a policy: the policy runs only when you execute it through the API. See Retention policies.
Continuous queries
resource "arc_continuous_query" "cpu_hourly" {
name = "cpu-hourly"
database = arc_database.metrics.name
source_measurement = "cpu"
destination_measurement = "cpu_1h"
interval = "1h"
query = <<-SQL
SELECT time_bucket(INTERVAL '1 hour', time) AS time, host, avg(usage_user) AS usage_user
FROM metrics.cpu
WHERE time >= {start_time} AND time < {end_time}
GROUP BY 1, 2
SQL
tag_columns = ["host"]
is_active = true
}The query must contain the {start_time} and {end_time} placeholders; Arc fills them with each run's window. The interval is a duration of at least 10s. As with retention, the scheduler needs a license. See Continuous queries.
Import existing objects
Every resource can be imported, so you can bring an Arc you already run under management:
terraform import arc_database.metrics metrics
terraform import arc_token.grafana 42
terraform import arc_retention_policy.cpu_30d 7
terraform import arc_continuous_query.cpu_hourly 3Databases are imported by name, the others by their numeric ID. arcli lists the IDs: arcli auth token list, arcli retention list, arcli cq list.
An imported token has no value, because Arc cannot show the secret again. Importing never rotates it, even if the configuration has rotation_triggers. To get a new secret, change a trigger value after the import and apply.
If you create something that already exists, the provider stops and prints the terraform import command to run instead.
Troubleshooting
| Error | Cause and fix |
|---|---|
The Arc token is not an admin token | The token lacks admin. Use an admin token. |
Arc rejected the token | The token is wrong, expired or revoked. |
... is not available on this Arc: the API route is not registered | The feature is off in Arc's configuration, for example retention.enabled = false. The error names the setting. |
Refusing to delete the database | Set force_destroy = true, apply, then destroy. |
Deletes are disabled on this Arc | Set delete.enabled = true on the server. |
Authentication is disabled on this Arc | Arc runs with auth.enabled = false, so it has no tokens to manage. Remove the arc_token resources or enable auth. |
Outcome of the ... create is unknown | Arc may have created the object, but the answer was lost. Check whether it exists, then import it or re-run apply. The provider resolves this by itself where the name is unique. |
Next steps
- Terraform and OpenTofu on Arc Enterprise: RBAC, tiering, governance and clusters.
- Provider source and issues: Basekick-Labs/terraform-provider-arc.
VS Code Extension
The Arc Database Manager extension for VS Code: saved connections, SQL IntelliSense against your measurements, result grids, CSV import, and test-data generation.
OpenTelemetry Integration
Export traces, metrics, and logs from the OpenTelemetry Collector into Arc: build the collector with the Arc exporter, configure it, and query spans with SQL.