Terraform and OpenTofu
Manage Arc Enterprise with Terraform or OpenTofu: which cluster node to target, RBAC organizations, teams and roles, and tiering and governance policies, using the basekick-labs/arc provider.
The basekick-labs/arc provider manages a running Arc as code, from Terraform or OpenTofu. On Arc Enterprise it covers RBAC, tiered-storage policies and query governance, in addition to the databases, tokens, retention policies and continuous queries it manages on any Arc. It configures the server over Arc's HTTP API. It does not deploy Arc: use the packages, images or Helm chart for that.
| Resource | What it manages | License feature |
|---|---|---|
arc_database | A database. Destroying it deletes its data, so the provider refuses unless force_destroy = true. | none |
arc_token | An API token. The secret is in value. | none |
arc_retention_policy | Deletes data older than a number of days. | retention_scheduler, to run on a schedule |
arc_continuous_query | Runs SQL on a schedule and writes the result to another measurement. | cq_scheduler, to run on a schedule |
arc_organization, arc_team, arc_role, arc_measurement_permission | RBAC: who may read or write which databases and measurements. | rbac |
arc_token_team_membership | Puts a token in a team, so it gets the team's roles. | rbac |
arc_tiering_policy | Per-database tiered storage settings. | tiering |
arc_governance_policy | Per-token query limits. | query_governance |
Data sources: arc_server (mode, license, the node's role, the primary writer and the Raft leader), arc_databases, and arc_token (looks a token up by name, without its secret).
The Arc OSS page covers databases, tokens, retention policies and continuous queries in detail. This page covers what is specific to Enterprise: clusters, RBAC, tiering and governance.
Set up the provider
The provider needs an admin token, and reads the endpoint and token from the environment:
export ARC_ENDPOINT=http://arc-writer-0.arc-headless:8000
export ARC_TOKEN="<admin-api-token>"terraform {
required_providers {
arc = {
source = "basekick-labs/arc"
version = "~> 0.1"
}
}
}
# endpoint and token come from ARC_ENDPOINT and ARC_TOKEN.
provider "arc" {}ca_cert_pem trusts a private CA for Arc's TLS certificate. The Arc OSS page describes the other settings. The provider is tested with Terraform 1.5 and 1.17, and with OpenTofu 1.13.
Which node to point the provider at
The provider talks to one Arc node for the whole run. Cluster nodes apply each other's changes with a short lag, so a write on one node and a read on another can show a resource as missing, or show stale values.
| Deployment | endpoint |
|---|---|
| Standalone | The node. |
Shared object storage, multi-writer (cluster.shared_storage_mode = true) | One node's own address, preferably a writer. On Arc 26.09.x, destroying an arc_database must go through the Raft leader writer; another node is refused, and the error names the leader. Arc 27.01.1 forwards the delete to the leader from any node. |
| Any cluster with a designated primary writer: local storage with peer replication, or a single-writer shared bucket | The primary writer. Provider 0.1.0 refuses database operations on any other node. That is required on Arc 26.09.x, where a database that holds no data yet exists only on the primary and deletes are not forwarded. Arc 27.01.1 fixes both, and relaxing the rule there is tracked in terraform-provider-arc#8. After a failover, point endpoint at the new primary. |
Do not use a load balancer that spreads requests
Through such a balancer, a token deleted on one node can still look present, or a token you just created can look missing, depending on which node answers. Before every resource operation, the provider checks that the endpoint still reaches the node it started with, and stops if not. A balancer that keeps one client on one node passes this check, and is safe for as long as it keeps doing so. On Kubernetes, give the provider one pod's own address: a headless Service name, or kubectl port-forward to one pod.
The arc_server data source reports what the node knows:
data "arc_server" "this" {}
output "arc_topology" {
value = {
mode = data.arc_server.this.mode
node = data.arc_server.this.local_node_id
role = data.arc_server.this.local_role
primary = data.arc_server.this.primary_writer_id
leader = data.arc_server.this.leader_id
policy_kinds = data.arc_server.this.seeded_policy_kinds
}
}Versions
| Arc | What the provider manages |
|---|---|
| 26.09.4 or later, standalone | Every resource. |
| 26.09.x, cluster | Databases, tokens and RBAC. On these releases each node keeps its own retention policies, continuous queries, governance policies and tiering policies, so a change made through one node would not reach the others. The provider refuses those resources. |
| 27.01.1 or later, cluster | Every resource, once the cluster has adopted each policy kind. A cluster adopts a policy kind once every node runs a release that supports it; data.arc_server.this.seeded_policy_kinds lists the kinds it has adopted. Until then, the provider refuses that kind and says why. |
RBAC
resource "arc_organization" "acme" {
name = "acme"
description = "ACME Corp"
}
resource "arc_team" "analysts" {
organization_id = arc_organization.acme.id
name = "analysts"
}
# Read access to every database whose name starts with prod_.
resource "arc_role" "prod_read" {
team_id = arc_team.analysts.id
database_pattern = "prod_*"
permissions = ["read"]
}
# Narrow that role to the cpu* measurements.
resource "arc_measurement_permission" "cpu_only" {
role_id = arc_role.prod_read.id
measurement_pattern = "cpu*"
permissions = ["read"]
}
# A token whose access comes only from its teams.
resource "arc_token" "analyst" {
name = "analyst-dashboards"
permissions = []
}
resource "arc_token_team_membership" "analyst" {
token_id = arc_token.analyst.id
team_id = arc_team.analysts.id
}- Organization names are unique, and so are team names within an organization. Names are case-sensitive.
- Changing a team's organization, or a role's team, replaces it. A measurement permission has no update in Arc, so any change replaces it.
- Deleting an organization deletes its teams, roles, measurement permissions and memberships. Deleting a team deletes everything below it.
- Arc does not keep roles or measurement permissions unique. If a create's outcome is unknown, for example because the connection dropped, the provider stops instead of sending it again and tells you what to check.
See RBAC for how Arc combines a token's own permissions with its teams' roles.
Tiering policies
resource "arc_database" "metrics" {
name = "metrics"
}
resource "arc_database" "realtime" {
name = "realtime"
}
resource "arc_tiering_policy" "metrics" {
database = arc_database.metrics.name
hot_max_age_days = 7
}
resource "arc_tiering_policy" "realtime" {
database = arc_database.realtime.name
hot_only = true
}A policy overrides the global tiering defaults for one database. Destroying it returns the database to the defaults and touches no data. Arc must run with tiered_storage.enabled = true and a cold tier.
If the database already has a policy, the provider does not take it over silently. It stops and prints the terraform import command.
Governance policies
resource "arc_token" "grafana" {
name = "grafana"
permissions = ["read"]
}
resource "arc_governance_policy" "grafana" {
token_id = arc_token.grafana.id
rate_limit_per_minute = 120
max_rows_per_query = 1000000
max_scan_duration_sec = 30
}There is one policy per token. Any limit you leave out is 0, which means unlimited. Arc must run with governance.enabled = true. On a cluster the token must be a cluster token, which every token this provider creates is. See Query governance.
Convert a standalone node to a cluster
When a standalone node with objects in it is restarted as the first node of a cluster:
- Retention policies and continuous queries keep their IDs. Nothing to do.
- RBAC organizations get new IDs, and Arc deletes their teams, roles, measurement permissions and memberships.
- Tokens created before the conversion become node-local: they exist on that node only. The provider refuses to manage a node-local token, and reading one stops the run.
Before the first apply against the cluster:
-
Create a new admin token on the cluster for the provider itself, and point
ARC_TOKENat it. The old admin token still works on this node, so use it to create the new one:curl -X POST -H "Authorization: Bearer $ARC_TOKEN" -H "Content-Type: application/json" \ -d '{"name":"terraform-admin","permissions":["read","write","delete","admin"]}' \ "$ARC_ENDPOINT/api/v1/auth/tokens" -
Remove the converted tokens and the whole RBAC tree from state, along with anything keyed on a token ID:
terraform state rm arc_token.grafana arc_governance_policy.grafana terraform state rm arc_organization.acme arc_team.analysts arc_role.prod_read \ arc_measurement_permission.cpu_only arc_token_team_membership.analyst -
Delete the old node-local tokens. Arc cannot create a cluster token under a name a node-local token still holds. Use the token's
idandnode_idfromGET /api/v1/auth/tokens:curl -X DELETE -H "Authorization: Bearer $ARC_TOKEN" \ "$ARC_ENDPOINT/api/v1/auth/tokens/<id>?node=<node_id>" -
Import each organization by its new ID, which
arcliorGET /api/v1/rbac/organizationsshows:terraform import arc_organization.acme <new-org-id> -
Run
terraform apply. It creates new cluster tokens and recreates the teams, roles, permissions, memberships and governance policies. If it stops withgovernance policies are not cluster-wide yet on this cluster, the cluster is still adopting governance policies after the old tokens went away; wait a minute and run it again.
Writes with an unknown outcome
A cluster can commit a write and still answer with an error, for example when the acknowledgement from the Raft leader is lost. How the provider handles that depends on whether Arc keeps the object unique:
- Databases, tokens, retention policies, continuous queries, organizations and teams have unique names, so sending the create again cannot make a duplicate, and the provider does. When Arc answers that the name is taken, the provider looks the object up, accepting only one created since its first attempt, and adopts it. A token is then rotated, because its original secret never arrived.
- Roles and measurement permissions are not unique, so the provider stops and tells you to check before you re-run.
Refusals that changed nothing are retried until consistency_timeout (default 30s) runs out. Examples are a policy kind being adopted, or a node that has not caught up with the cluster.
Import existing objects
terraform import arc_organization.acme 1
terraform import arc_team.analysts 2
terraform import arc_role.prod_read 3
terraform import arc_measurement_permission.cpu_only 3/4 # <role_id>/<id>
terraform import arc_token_team_membership.analyst 12/2 # <token_id>/<team_id>
terraform import arc_tiering_policy.metrics metrics # the database name
terraform import arc_governance_policy.grafana 42 # the token IDThe Arc OSS page covers databases, tokens, retention policies and continuous queries.
Troubleshooting
| Error | Cause and fix |
|---|---|
The Arc endpoint reaches a different node | Requests are spread across nodes. Point endpoint at one node. |
Not the primary writer | The cluster has a designated primary writer: point endpoint at it (data.arc_server.this.primary_writer_id). |
This node cannot delete databases | Shared-storage cluster on Arc 26.09.x: destroy databases through the Raft leader writer named in the error. Arc 27.01.1 forwards the delete itself. |
... are not cluster-wide on this Arc | A 26.09.x cluster: upgrade every node to 27.01.1 or later. |
... are not cluster-wide yet on this cluster | The cluster has not adopted that policy kind yet. It does once every node runs a release that supports it. |
Node-local token | The token predates the node joining a cluster. See Convert a standalone node to a cluster. |
... requires an enterprise license with the '<feature>' feature enabled (Arc's answer) | The license lacks the feature named in the message: rbac, tiering or query_governance. |
Next steps
- Terraform and OpenTofu on Arc OSS: databases, tokens, retention and continuous queries in detail.
- Deployment patterns: shared object storage vs local storage.
- Provider source and issues: Basekick-Labs/terraform-provider-arc.
VS Code Extension
Browse databases, run SQL, and import CSV against an Arc Enterprise cluster from VS Code with the Arc Database Manager extension and an RBAC-scoped connection token.
Redpanda Connect Integration
Stream from any Redpanda Connect source into an Arc Enterprise cluster with the native arc output plugin, writing MessagePack batches to a load-balanced writer endpoint.