Terraform provider
The Lumen Terraform provider lets you declare flows, connections and alert policies next to the rest of your infrastructure, review changes in a plan, and keep them in version control. It uses the same server-side apply as the CLI, so Terraform and lumen apply see the same resources.
Install the provider
The provider is a Go program, terraform-provider-lumen, with the source address buji-code/lumen.
Where the provider is distributed has not been decided. Until it is, build it from the repository and point Terraform at it with dev_overrides, which needs no terraform init for this provider.
go build -o ~/.terraform.d/lumen-dev/ ./cmd/terraform-provider-lumen
provider_installation {
dev_overrides {
"buji-code/lumen" = "/Users/you/.terraform.d/lumen-dev"
}
direct {}
}
export TF_CLI_CONFIG_FILE=~/.terraformrc-lumen
Then require it in your configuration:
terraform {
required_providers {
lumen = {
source = "buji-code/lumen"
}
}
}
Configure it
Every setting is optional. Each falls back to an environment variable, then to the current context of the lumen CLI, token included.
| Setting | Environment variable | Default |
|---|---|---|
server | LUMEN_SERVER | The context's server. |
namespace | LUMEN_NAMESPACE | The context's namespace. Your workspace's namespace is tenant- plus its name. |
token | LUMEN_TOKEN | The token lumen login stored, refreshed when it expires. |
context | LUMEN_CONTEXT | The current CLI context. |
config_path | LUMEN_CONFIG | ~/.config/lumen/config.yaml. |
field_manager | LUMEN_FIELD_MANAGER | lumen-terraform. |
force_conflicts | false. Set it to take over fields another manager owns. |
On your own machine, provider "lumen" {} is enough once you have run lumen login (see Install the CLI). In automation, use an API key with the Build scope, and name the workspace, because a key alone does not set the provider's namespace:
variable "lumen_api_key" {
type = string
sensitive = true
}
provider "lumen" {
server = "https://api.go-lumen.ai"
namespace = "tenant-acme"
token = var.lumen_api_key
}
Or leave token out and export LUMEN_TOKEN, so the key never appears in your configuration.
Declare a connection and a flow
resource "lumen_connector" "inbox" {
name = "invoices-inbox"
spec = {
class_ref = { name = "email-forward" }
config = jsonencode({ allowedSenders = ["*@supplier.example"] })
}
}
resource "lumen_flow" "pdfs" {
name = "invoice-pdfs"
spec = {
display_name = "Invoice PDFs, merged"
triggers = [
{
id = "email"
ref = { name = "email-arrives" }
connector_ref = { name = lumen_connector.inbox.name }
config = jsonencode({ attachments = "separate", requireAttachment = true })
next = ["pdfs"]
},
{
id = "manual"
ref = { name = "manual-run" }
next = ["pdfs"]
},
]
nodes = [
{ id = "pdfs", step_ref = { name = "keep-pdfs" }, next = ["merge"] },
{ id = "merge", step_ref = { name = "merge-pdfs" }, next = ["keep"] },
{ id = "keep", step_ref = { name = "keep-in-lumen" } },
]
}
}
# The address that starts the flow, as the server reports it.
output "forward_to" {
value = jsondecode(lumen_connector.inbox.observed_spec).config.address
}
terraform plan
terraform apply
The field names are the resource's own in snake case: displayName is display_name, stepRef is step_ref. Run lumen explain flow.spec.nodes --recursive to see every field and what it means.
How a spec maps to HCL
- Objects are nested attributes, lists are lists, and maps are maps.
- A field with no fixed shape, such as a step's or a trigger's
config, is a JSON string. Write it withjsonencode(). - Required fields, allowed values, patterns and size limits are checked at plan time. Rules that need the whole resource are left to the server and reported when you apply.
- Keys the server adds, such as the address of a forwarding connection, are not differences.
observed_specholds the spec as the server has it. - Changing a connection's class replaces it.
Already have the YAML?
lumen_manifest applies any object from a YAML or JSON file. It is the way to keep the files you already wrote for lumen apply, and to manage kinds newer than the provider:
resource "lumen_manifest" "invoice_pdfs" {
manifest = file("${path.module}/flows/gitops-invoice-pdfs.yaml")
}
What the provider has
| Kind | Terraform name |
|---|---|
| Flow | lumen_flow |
| Connection | lumen_connector |
| Alert policy | lumen_alert_policy |
| Step | lumen_step |
| Form | lumen_form |
| Sheet, database | lumen_sheet, lumen_sheet_base |
| Knowledge collection | lumen_knowledge_collection |
| Model class | lumen_model_class |
| Worker pool | lumen_worker_pool |
| Any object | lumen_manifest |
| Run, file, alert | data.lumen_run, data.lumen_file, data.lumen_alert (read only) |
The provider also has resources for cluster-wide kinds (lumen_tenant, lumen_plan, lumen_region, lumen_cluster_step, and similar). They are for whoever operates a Lumen installation, and a workspace key cannot write them.
Read a run as data:
data "lumen_run" "last" {
name = "7c1f0a5e-3b52-4d6e-9a41-0b2c7e8d1f34"
}
Import what exists
Import by name, in the provider's namespace, or by namespace/name:
terraform import lumen_flow.pdfs invoice-pdfs
terraform import lumen_flow.pdfs tenant-acme/invoice-pdfs
terraform import lumen_manifest.probe 'lumen.ai/v1alpha1,Probe,tenant-acme/api'
The last form is a manifest's import id: apiVersion,kind,namespace/name.
Good to know
- Writes are server-side applies as
lumen-terraform. A field that someone else owns (the console, the CLI,kubectl) is a conflict, unless you setforce_conflicts = true. - Terraform owns what it creates. A flow made through Terraform is owned by Git, so the console shows it as Managed in Git and read only. A flow built in the console is owned by the console, and Terraform cannot change it. See Flows as YAML.
- Labels and annotations in state are only the ones you set. The ones Lumen adds, such as the owner label, are not differences.
- Secrets such as a connection's password do not belong in a plan or in state. Make those connections with
lumen connectand refer to them, or keep the secret in your own secret store.