skip to content

In HCP Terraform, how does a VCS trigger pattern differ from a run trigger between workspaces, and when would you use each?

level: middleimportance: should knowfreq 36%

answer

  1. similar names, different events
  2. one reacts to files, one to applies
  3. monorepo noise versus upstream dependency
  4. no data travels with the trigger

basics

~20 s

A trigger pattern filters which changed repository files start a run in a VCS-connected workspace. A run trigger queues a run in one workspace after a source workspace applies successfully. One reacts to commits, the other to applies.

solid answer

~40 s

They answer different questions. A trigger pattern is a glob in a workspace's VCS settings, such as `/submodule/**/*.tf`, deciding which changed files in the repository start a run; it also governs speculative plans on pull requests, and it is the tool for a monorepo. A run trigger connects a workspace to up to 20 source workspaces, so a successful apply in a source queues a run in the receiving workspace; it is the tool for infrastructure that depends on another workspace's results. A run trigger moves no data, so the configuration still reads values with something like the `tfe_outputs` data source. Runs it queues do not auto-apply unless **Auto-apply run triggers** is enabled, a setting separate from the main auto-apply.

go deeper

for a junior

Keep the two events apart: changed files in a repository for trigger patterns, a successful apply in another workspace for run triggers.

for a middle

Explain the working directory, patterns against prefixes, and why run-triggered runs need their own auto-apply setting while no data travels with the trigger.

for a senior

Recognise when filtering gives way, such as a missing changed-file list or a 300-file GitHub merge, and diagnose a shared module change that started nothing.

for a principal

Weigh the fan-out: run triggers express a real dependency between workspaces, but long chains multiply runs and approvals, so question how far a split estate should rely on them.

## Two features with nearly one name Both features start runs in an **HCP Terraform workspace**, and interviewers like them because candidates mix them up. They respond to different events and live in different settings. | | Trigger pattern | Run trigger | |---|---|---| | Event | Files change in a connected repository | A source workspace's run applies successfully | | Settings page | **Version Control** | **Run Triggers** | | Solves | Too many irrelevant runs in a shared repository | A workspace going stale after an upstream change | | Also affects | Speculative plans on pull requests | Nothing on pull requests | | Auto-apply | Main **Auto apply** setting | Separate **Auto-apply run triggers** setting | ## Working directory first The **Terraform Working Directory** setting says where Terraform executes runs. It defaults to the repository root. In a repository holding `staging` and `production` directories, each workspace points at its own. A working directory is required when you use trigger prefixes. The working directory does not by itself solve run noise. That is the job of the automatic run triggering options. ## Automatic run triggering A workspace picks one of three options: - **Always trigger runs** begins a run for changes to any file in the repository. The documentation does not recommend it for true monorepos, because it queues unnecessary runs. - **Only trigger runs when files in specified paths change** uses path rules, in two forms: - **Trigger patterns**, the recommended form, are globs: `/submodule/**/*.tf`, or `/**/networking/**/*` for any file with a `networking` directory on its path. - **Trigger prefixes** queue runs for changes in matching directories, including the working directory. - **Trigger runs when a git tag is published** begins runs for tags matching a chosen format. All matching tags trigger runs, regardless of the VCS branch setting. A shared `modules` directory needs its own entry. If a workspace watches only its working directory, a change to a module it uses queues nothing there. ## When filtering gives way Path rules fail towards running too much rather than too little: - If HCP Terraform receives no list of changed files, or the list is too large to process, it triggers runs on **all attached workspaces**. - With GitHub, merging a pull request that changes 300 or more files triggers runs for every workspace connected to the repository, because GitHub's API reports a limit of 300 changed files for a merge. Expect several runs with completed plans and no changes after such an event. They are a safety measure, not a broken filter. Two smaller details also trip people up. Glob patterns match hidden files and directories, whose names begin with a dot, so a change there can start a run. And the path rules apply to speculative plans too: a pull request outside the watched paths gets no plan in that workspace, although the workspace still posts a passing commit status. ## Run triggers in detail A **run trigger** is configured on the receiving workspace, naming source workspaces: 1. A run in a source workspace applies successfully. 2. HCP Terraform queues a new run in the receiving workspace, and that run's details link back to the source workspace and the applied run. 3. The run plans, then waits for confirmation unless **Auto-apply run triggers** is on. Details that come up in interviews: - **What fires it.** A successful apply, not a finished plan. A failed apply does not fire it, and a plan with no changes normally ends without an apply. - **Limit.** Each workspace can connect to up to 20 source workspaces. - **Permissions.** You need admin access on the receiving workspace and permission to read runs on the source. - **Auto-apply.** The main **Auto apply** setting does not cover these runs. The separate setting operates independently of it. - **No data.** The trigger only queues a run. To read values, the configuration uses a data source. HashiCorp recommends `tfe_outputs` over `terraform_remote_state` because it does not require full access to the workspace's state. ## Choosing Ask what should cause the run. If the answer is that a file changed, use the VCS settings. If the answer is that another workspace changed real infrastructure, use a run trigger. A workspace can use both: a monorepo workspace with path rules can also name an upstream source.

  • A source workspace applied, and the connected HCP Terraform workspace has Auto apply on, yet its triggered run is waiting. Why?
    Runs queued by a run trigger do not auto-apply unless **Auto-apply run triggers** is enabled. That setting operates independently of the main **Auto apply** setting, so this run waits for someone with permission to apply runs.
  • After one large merge, every HCP Terraform workspace on a monorepo ran despite their trigger patterns. What happened?
    HCP Terraform triggers all attached workspaces when it gets no list of changed files or the list is too large. On GitHub, a merged pull request changing 300 or more files does this because of the API's reporting limit. The runs are safe, and many finish with no changes.
  • A workspace's trigger pattern watches its own directory, but a shared module change started nothing there. What is missing?
    The shared module's directory must be added to that workspace's automatic run triggering paths, as a pattern or a prefix. Without it, the change is treated as irrelevant to the workspace and starts neither a run nor a speculative plan there.

  • A trigger pattern reacts to another workspace finishing its apply.
  • A run trigger passes the source workspace's outputs into the receiving run.
  • With Auto apply on, runs queued by a run trigger apply on their own.
  • A source workspace's plan is enough to fire a run trigger.
  • If a large merge exceeds the changed-file list, path filters simply start no runs.
  • Setting a working directory alone stops unrelated commits from starting runs.