How AI is applied across API Evangelist and APIs.io. Read my AI disclosure →
API Evangelist API Evangelist
Discovery
Learnings
Guidance
Toolbox
Alignment
API Evangelist LLC

Automate Cloud Infrastructure Workspaces, Runs And Variables With Terraform

December 5th, 2026 · Kin Lane
Automate Cloud Infrastructure Workspaces, Runs And Variables With Terraform

If your business runs on the cloud, somebody on your team is setting up servers, databases and networks, changing them, and eventually tearing them down. Doing that by hand in a cloud console is slow, hard to repeat and easy to get wrong. Terraform lets you write down what your infrastructure should look like and then makes it so, and HCP Terraform puts all of that behind an API, which means your own software, or an AI assistant working for you, can create environments, roll out changes and clean up afterward without anyone clicking through screens. I keep a profile of what Terraform offers on APIs.io, and this is the version for the business reader.

What Terraform does

Terraform, from HashiCorp, is an open-source infrastructure-as-code tool. Infrastructure as code means describing your cloud setup in text files, the way a recipe describes a meal, so it can be reviewed, versioned and rebuilt the same way every time. Terraform uses its own declarative configuration language, HCL, where you say what you want rather than the steps to get there. HCP Terraform, the hosted service, and Terraform Enterprise, the self-managed edition, expose a REST API for managing workspaces, runs, state, policies and who has access. You can find it at developer.hashicorp.com/terraform.

What you can get done

Environment Management

A workspace is where Terraform keeps one environment, say production, staging or a single customer’s setup, along with its history and current state. Managing workspaces through the API means a new project or a new client can get its own environment automatically, and you can lock one while sensitive work is happening so nobody changes it underneath you.

  • GET /organizations/{organization_name}/workspaces lists every workspace in your organization.
  • POST /organizations/{organization_name}/workspaces creates a new workspace.
  • PATCH /workspaces/{workspace_id} updates a workspace’s settings.
  • POST /workspaces/{workspace_id}/actions/lock locks a workspace so no changes can run.
  • DELETE /workspaces/{workspace_id} removes a workspace you no longer need.

IT Infrastructure Management

A run is Terraform doing the actual work: it plans what would change in your cloud, and then, once approved, applies it. Driving runs from the API lets you build a release process where changes are proposed, reviewed and applied on your schedule, and where a bad plan can be thrown away before it touches anything.

  • POST /runs starts a new run, which produces a plan of the changes.
  • GET /runs/{run_id} checks on a run and its plan.
  • POST /runs/{run_id}/actions/apply approves the plan and makes the changes.
  • POST /runs/{run_id}/actions/discard throws away a plan you do not want.
  • POST /runs/{run_id}/actions/cancel stops a run that is in progress.

Configuration & Secrets Management

Every environment needs settings, things like a region, a server size or a password for a database. Terraform stores these as workspace variables, and can mark the sensitive ones so they are not shown back. Managing them through the API keeps configuration in one place instead of scattered across spreadsheets and chat messages.

  • GET /workspaces/{workspace_id}/vars lists a workspace’s variables.
  • POST /workspaces/{workspace_id}/vars adds a variable or secret.
  • PATCH /workspaces/{workspace_id}/vars/{variable_id} changes a value.
  • DELETE /workspaces/{workspace_id}/vars/{variable_id} removes one.

Package Registries & Distribution

Most teams do not write everything from scratch. The public Terraform registry holds shared modules, ready-made building blocks for common setups, and the API lets you search it and see how actively a module is maintained before you rely on it.

  • GET /v1/modules/search searches the registry for modules.
  • GET /v1/modules/{namespace} lists everything a publisher offers.
  • GET /v1/modules/{namespace}/{name}/{provider} gets the latest version of a module.
  • GET /v1/modules/{namespace}/{name}/{provider}/versions lists a module’s versions.

Workflows that put it together

A workflow is a recipe of several API calls made in order to finish one job. We have written these down as Arazzo workflows, a standard format for describing them:

Getting started

Terraform is listed as freemium with self-serve signup, and there is a free tier. You can see the details in the pricing section of the Terraform profile.

The HCP Terraform API documentation is the place to start, with dedicated pages for workspaces and runs. On APIs.io, start from the Terraform profile, then the Workspaces API, the Runs API and the Variables API.

Pick the one environment your team rebuilds most often, and make creating it with a single API call your first project.