Skip to Content
GuidesManage Workflows with Terraform

Manage Workflows with Terraform

The KeeperHub Terraform provider lets you keep workflows in git and change them the way you change the rest of your infrastructure: edit a file, review the plan in a pull request, and apply it. It works with Terraform and OpenTofu.

Use it when you want to:

  • review every workflow change before it reaches KeeperHub
  • keep a history of who changed what, and roll back with git
  • run the same workflow in several organizations
  • notice when someone edits a managed workflow in the app

This page is an overview. The full reference and step-by-step guides are in the provider documentation .

What You Can Manage

ResourceWhat it manages
keeperhub_workflowA workflow: its key, name, description, project, tag, whether it is enabled, and its definition (nodes and edges)
keeperhub_projectA project that groups workflows
keeperhub_tagA tag that labels workflows
keeperhub_workflow_failure_alertWhen a workflow’s failures raise an alert, and who receives it

Data sources look up existing objects without managing them: keeperhub_workflow, keeperhub_project, keeperhub_tag, keeperhub_integration (a connection such as a wallet or a Slack workspace), keeperhub_action_schema (the fields an action takes) and keeperhub_chains.

Connect with an API Key

  1. In KeeperHub, open Settings and go to API keys, under Developer. Under Organisation keys, create a key and select both the read and the write permission. See API Keys.

  2. Give the key to the provider through the environment:

    export KEEPERHUB_API_KEY="kh_..."
  3. Install the provider from the registry with terraform init, or tofu init for OpenTofu.

The provider talks to app.keeperhub.com by default. A key with only the read permission can run terraform plan but not terraform apply, which suits jobs that only plan, such as checks on pull requests.

A key belongs to one organization, and everything the provider does happens there. To manage several organizations, add one provider block per organization with an alias and its own key.

A Minimal Example

Build the workflow in the editor, then click the download icon in the editor toolbar, Export workflow as JSON. Tick Keep connection ids so the steps keep the wallet and messaging connections they use, export, and save the file next to your Terraform configuration. See Import/Export for what the file holds.

terraform { required_providers { keeperhub = { source = "keeperhub/keeperhub" } } } provider "keeperhub" {} resource "keeperhub_workflow" "rebalance" { key = "treasury/rebalance" name = "Treasury rebalance" description = "Checks the treasury wallet every hour." definition = file("${path.module}/treasury-rebalance.workflow.json") }

key is the workflow’s stable name. Terraform finds the workflow by it, so it must be unique in the organization. The provider reads only the nodes and edges of the file; the name and other settings come from the configuration.

With Keep connection ids ticked, each step keeps the ID of the connection it uses, as integrationId in its config, so the workflow runs as it does in the editor. A plain export leaves the IDs out so the file can be shared; add them back by hand if you start from one. Credentials always stay in KeeperHub.

Run terraform plan to review the change, then terraform apply to create the workflow. A new workflow starts disabled: turn it on in the app, or set enabled = true.

Bring Existing Workflows Under Terraform

Terraform can take over a workflow you built in the editor, keeping its ID and run history:

  1. Open the workflow, and with no step selected, enter a key in the Key field of the Properties panel. Save the workflow.

  2. Export it and write a keeperhub_workflow resource with the same key and settings.

  3. Import it with an import block, or with terraform import:

    import { to = keeperhub_workflow.rebalance id = "treasury/rebalance" }
  4. Run terraform plan. When it reports 1 to import and 0 to change, apply it.

If the plan shows changes, adjust the files until it does not. The provider documentation’s importing guide lists the usual differences and how to resolve each one.

Drift and Conflicts

  • Layout and run status are not changes. Moving steps on the canvas, a step’s last run status and the formatting of the JSON file never show up in a plan.
  • Edits in the app show up as drift. A change made in the editor to anything Terraform manages appears in the next plan, and terraform apply puts the configuration back. Copy the change into your files if you want to keep it.
  • Concurrent edits are never overwritten. If someone saves the workflow after Terraform read it and before the apply writes, the apply fails without changing anything. Run the plan again and decide which version wins.
  • Leave enabled unset to let the app control it. Turning the workflow on or off in the app is then not drift. Set enabled and Terraform decides whether the workflow runs.
  • Creating never takes over. If another workflow already holds the key, the apply fails and asks you to import that workflow instead.

Learn More

The KeeperHub provider documentation  covers every resource and data source, and has guides for getting started, importing existing workflows, drift and conflicts, and running in CI.