Terraform provider: manage flags, experiments, cohorts, keys and exports as code
Install the Lucida Terraform provider, configure it with an API key and project, manage flags, experiments, cohorts, actions, alerts, keys, export schedules, connectors and traffic exclusions, import existing objects and read drift.
The Lucida provider manages a project's definitions from Terraform. It is built from the same model as the CLI's lucida pull, plan and apply, so Terraform and the CLI manage exactly the same kinds with the same fields and the same matching rule: objects are matched by their natural key (the flag key, the name, the endpoint slug), never by id.
Install and configure
The provider's source and signed releases are on GitHub: github.com/lucidaanalytics/terraform-provider-lucida (releases). Its Terraform Registry listing is pending, so until it appears, put the release zip where Terraform looks for local providers (Terraform checks ~/.terraform.d/plugins before the registry; on Windows use %APPDATA%\terraform.d\plugins):
V=0.1.0
OS=$(uname -s | tr '[:upper:]' '[:lower:]'); ARCH=$(uname -m | sed 's/x86_64/amd64/; s/aarch64/arm64/')
D=~/.terraform.d/plugins/registry.terraform.io/lucidaanalytics/lucida
mkdir -p "$D"
curl -fsSL -o "$D/terraform-provider-lucida_${V}_${OS}_${ARCH}.zip" \
"https://github.com/lucidaanalytics/terraform-provider-lucida/releases/download/v${V}/terraform-provider-lucida_${V}_${OS}_${ARCH}.zip"Each release also has terraform-provider-lucida_<version>_SHA256SUMS and its .sig, signed with key 2443015EEBB2D44CF9EDB6DA6F6A5B5920CBA0FB, if you want to check the zip first. Once the registry listing is live, delete the zip and terraform init downloads it from the registry; your configuration does not change.
terraform {
required_providers {
lucida = {
source = "lucidaanalytics/lucida"
version = "~> 0.1"
}
}
}
provider "lucida" {
project_id = var.lucida_project_id # or $LUCIDA_PROJECT_ID
# api_key = var.lucida_api_key # or $LUCIDA_API_KEY (sensitive)
# host = "https://lucidace.com" # or $LUCIDA_HOST, for a self-hosted Lucida
}Use an API key that only carries the scopes you manage (Settings, API keys). The key and every credential attribute are Sensitive, but Terraform still writes them to state: use an encrypted remote backend.
Resources
Resource | What it manages |
|---|---|
| A feature flag, keyed by flag key |
| An experiment (destroy archives it) |
| Analytics definitions, keyed by name |
| An insight alert; |
| A query endpoint, keyed by slug |
| A project API key; destroy revokes it |
| A batch export schedule |
| A connector instance (destinations are connectors with a destination |
| A traffic exclusion rule, keyed by its note |
Data sources: lucida_project and lucida_flag (look up a flag's id by key).
Each resource has the natural key as its own argument and one definition argument: a JSON object (use jsonencode) holding the other managed fields. Unknown fields are rejected at plan time, and so is a definition that repeats the key.
resource "lucida_flag" "checkout" {
key = "new-checkout"
definition = jsonencode({
name = "New checkout"
enabled = true
filters = { rollout = 25 }
})
}Fields the API cannot change after create (a cohort's kind, an export schedule's destination and stream, a traffic exclusion's rule) force a new resource when you edit them, and the plan says so.
Keys and secrets
lucida_key returns its secret once, as the sensitive computed attribute secret. Pass it on without printing it:
resource "lucida_key" "ci" {
name = "ci-read"
definition = jsonencode({ kind = "project", scopes = ["read"] })
}
output "ci_key" {
value = lucida_key.ci.secret
sensitive = true
}Credentials for export schedules and connectors are a separate sensitive credentials argument (a JSON object), sent on create only and never read back. To rotate one, run terraform apply -replace=lucida_export_schedule.daily. Do not put a credential in definition.
Import and drift
Import takes the Lucida id (the slug for endpoints; the API returns it as id):
terraform import lucida_flag.checkout <flag id>After an import the state holds every managed field, so the first terraform plan shows how your configuration differs; copy the fields you want to keep into definition.
On every refresh, only the fields named in your definition are compared with Lucida. If someone changes one in the app, the plan shows the difference and apply puts it back. Fields you leave out are never compared and never cleared. An object deleted in Lucida disappears from state and is planned for re-creation.
Using it with the CLI
The two can share a project. The CLI's lucida pull writes the same kinds as YAML, so you can start from a pull, translate it into resources, and import the ids. Do not manage the same object from both at once: whichever applies last wins.
Limits
The provider does not create projects; it manages the objects inside one. Create the project in the console, or with
POST /v1/orgs/{id}/projectsusing an account key that holds theproject:writescope (a session is not required), then read it withdata "lucida_project".Creating an object whose key already exists fails with a pointer to
terraform import; Lucida never adopts it silently.Connector credentials cannot be changed in place, only by replacing the resource.