--- published: true layout: post title: 'Automate Cloud Infrastructure Workspaces, Runs And Variables With Terraform' image: https://kinlane-images.s3.amazonaws.com/apievangelist/api-evangelist-images/automate-cloud-infrastructure-workspaces-runs-and-variables-with-terraform.png date: 2026-12-05 20:00:00 +0000 author: Kin Lane tags: - Provider Stories - Terraform - Environment Management - IT Infrastructure Management - Configuration & Secrets Management - Infrastructure as Code - Cloud Infrastructure --- 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](https://apis.io/providers/terraform/), 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](https://developer.hashicorp.com/terraform). ## What you can get done ### [Environment Management](https://apis.io/capabilities/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](https://apis.io/capabilities/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](https://apis.io/capabilities/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](https://apis.io/capabilities/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: - [Find and Cancel a Stuck Run](https://apis.io/arazzos/terraform/terraform-cancel-stuck-run-workflow/) locates an in-flight run, cancels it and unlocks the workspace. - [Destroy Infrastructure and Delete the Workspace](https://apis.io/arazzos/terraform/terraform-destroy-workspace-workflow/) tears down an environment and removes the emptied workspace. - [Onboard a Project and Its First Workspace](https://apis.io/arazzos/terraform/terraform-onboard-project-workflow/) creates a project and places a workspace in it. - [Push a New State Version Under Lock](https://apis.io/arazzos/terraform/terraform-migrate-state-version-workflow/) locks a workspace, uploads a new record of what exists, and unlocks it. - [Onboard a Sentinel or OPA Policy](https://apis.io/arazzos/terraform/terraform-onboard-policy-workflow/) adds a rule your infrastructure must follow, if it is not already there. - [Audit an Organization's Full Inventory](https://apis.io/arazzos/terraform/terraform-audit-organization-inventory-workflow/) sweeps for every project, workspace, team and policy in one pass. - [Discover a Registry Module and Vet It](https://apis.io/arazzos/terraform/terraform-discover-module-workflow/) searches the registry and checks a module's versions and downloads. - [Audit a Namespace's Published Modules](https://apis.io/arazzos/terraform/terraform-audit-namespace-modules-workflow/) reviews everything a publisher has put out. ## 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](https://apis.io/providers/terraform/#pricing). The [HCP Terraform API documentation](https://developer.hashicorp.com/terraform/cloud-docs/api-docs) is the place to start, with dedicated pages for [workspaces](https://developer.hashicorp.com/terraform/cloud-docs/api-docs/workspaces) and [runs](https://developer.hashicorp.com/terraform/cloud-docs/api-docs/run). On APIs.io, start from the [Terraform profile](https://apis.io/providers/terraform/), then the [Workspaces API](https://apis.io/apis/terraform/terraform-workspaces-api/), the [Runs API](https://apis.io/apis/terraform/terraform-runs-api/) and the [Variables API](https://apis.io/apis/terraform/terraform-variables-api/). Pick the one environment your team rebuilds most often, and make creating it with a single API call your first project.