In HCP Terraform, how do VCS-driven, CLI-driven and API-driven workflows differ in what starts a run and where its configuration comes from?
answer
- three doors into one run lifecycle
- webhook, terminal command, or your own tooling
- who supplies the files each time
- a linked repository is the source of truth
basics
~20 sVCS-driven runs start from webhooks and use a commit on the linked branch. CLI-driven runs start from terraform plan or apply and upload a local directory. API-driven runs start from your tooling, which uploads a tar.gz file.
solid answer
~40 sAll three are remote operations in an HCP Terraform workspace; they differ in the trigger and the source of the configuration. In the VCS-driven workflow, HCP Terraform registers webhooks, queues a run when commits land on the workspace's linked branch, and takes the code from that commit. In the CLI-driven workflow, `terraform plan` and `terraform apply` upload the local working directory and stream the run to your terminal. In the API-driven workflow, your own tooling uploads a `.tar.gz` to a configuration version, and by default that upload queues the run. A workspace linked to a repository refuses a remote `terraform apply`, because the repository is its source of truth, although `terraform plan` still works there as a speculative plan.
go deeper
Recall the three names, then give one trigger and one configuration source for each: webhook and commit, command and local directory, tooling and uploaded archive.
Explain why a linked repository refuses a remote terraform apply but accepts terraform plan, and why a manual UI run does not fetch the latest commit.
Show that you separate the workflow from the execution mode, and warn that Ctrl-C after a remote apply has started only stops the log stream, not the apply.
Treat a VCS-linked workspace as a governance choice: the repository becomes the only route to apply, so review rules on that branch start to carry real weight.
## One lifecycle, three ways in A **run** is one execution of Terraform managed by HCP Terraform: it plans, may wait for approval, and may apply. An **HCP Terraform workspace** (not a CLI workspace) supplies the configuration, state and variables for that run. HCP Terraform calls these *remote operations*, because in Remote execution mode they execute on its own disposable virtual machines rather than on your computer. The documentation names three workflows for managing runs. They differ in two things: **what starts a run** and **where the configuration comes from**. A **configuration version** is the snapshot of Terraform files a run is locked to, and each workflow produces it differently. ## The comparison | Workflow | What starts a run | Where the configuration comes from | When it fits | |---|---|---|---| | VCS-driven | A webhook, when commits land on the linked branch | That commit in the connected repository | The documented primary mode | | CLI-driven | `terraform plan` or `terraform apply` with the CLI integration configured | The local working directory, uploaded | Terminal habits, or an existing pipeline | | API-driven | Your own tooling calling HCP Terraform's API | A `.tar.gz` file your tooling uploads | Unsupported VCS systems, generated configuration, custom integrations | ## VCS-driven in detail Connecting a workspace to a repository registers webhooks with the VCS provider. After that: - A commit merged to the linked branch queues a **normal run**. Other branches are ignored. - A pull request against that branch gets a **speculative plan**, a plan-only run, instead of a normal run. - The first run must be started by hand: a workspace with no runs does not accept new runs from a webhook. - A commit SHA the workspace already processed into a run is not processed again, so re-sending the same webhook does nothing. Make a new commit. - Starting a run with **+ New run** in the UI does not fetch the newest commit. It uses the workspace's current configuration version, which is why manual runs suit a changed variable value with unchanged code. By default the run then waits for someone with permission to apply runs to confirm it. Turning on **Auto apply** removes that wait for successful plans queued by a commit. ## CLI-driven in detail With the CLI integration configured, ordinary commands create remote runs: - `terraform plan` starts a speculative plan from local files. It works in every workspace, including one linked to a repository. - `terraform apply` starts a normal plan and apply from local files, but only in a workspace **without** a linked repository. In a linked workspace, remote applies are not allowed, and the way to apply is to merge to the designated branch. - Saved plans (`terraform plan -out` then `terraform apply` on that file) follow the same rule: they are for workspaces with no linked repository. The files are local but the run is not. It uses the workspace's variables, and output is streamed to your terminal. If the remote apply has already started, pressing Ctrl-C stops the log streaming, not the apply. CLI runs also control approval with the `-auto-approve` flag rather than the workspace's main auto-apply setting. ## API-driven in detail The workspace is not tied to a repository and HCP Terraform does not fetch anything from version control. The tooling is yours: 1. Package the configuration directory as a `.tar.gz` file. 2. Create a configuration version through the `configuration-versions` API, which returns an upload URL. 3. Upload the file. With `auto-queue-runs` left at its default of `true`, the upload queues a run. If it was set to `false`, your tooling starts the run through the `runs` API. The flexibility is the point, and the cost: the documentation describes this workflow as more flexible but requiring you to create some tooling. ## Two things not to confuse - **Workflow versus execution mode.** The workflow says how a run starts. The execution mode says where it executes. In **Local** execution mode the workspace is only a state store and these remote runs do not happen. - **Same rules once the run exists.** The workflow changes the way in, not the checks: a CLI-driven run still has any applicable Sentinel or OPA policies enforced on it, as a VCS-driven one does.
- A variable value changed in a VCS-driven HCP Terraform workspace but the code did not. How do you get it applied?Start a run manually with **+ New run**, which needs permission to queue plans. It uses the workspace's current configuration version and the new variable value. No webhook fires for a variable change, and a manual run does not fetch the latest commit, so this is the expected path.
- A new HCP Terraform workspace was just connected to a repository, and the next commit started nothing. Why?A workspace with no runs does not accept new runs through a VCS webhook. One run must be queued manually first, which confirms the workspace is ready. After that, commits to the linked branch queue runs normally.
- Can you run terraform plan from a laptop against an HCP Terraform workspace linked to a repository?Yes. With the CLI integration configured it starts a speculative plan using your local files and the workspace's variables, so you can check an edit before opening a pull request. It can never apply. To change infrastructure in that workspace you merge to the linked branch.
- Running terraform apply from a laptop is a normal way to apply in a VCS-linked workspace.
- A CLI-driven run in remote mode executes on my machine using my shell variables.
- Clicking New run in the UI always pulls the newest commit from the repository.
- An API-driven workspace still fetches its configuration from a repository on each run.
- A newly connected workspace starts running from its first webhook with no manual run.
- A pull request queues a normal run that simply waits for approval.