How to automatically trigger newly created stacks
Last updated: September 18, 2025
When using automation to create Spacelift stacks (for example, by dropping configuration files in Terraform root modules), newly created stacks may not automatically run because they're waiting for a trigger event. This article explains how to set up automatic triggering for newly created stacks.
The Problem
A typical workflow:
A PR adds a new stack.
The PR gets merged.
A stack gets created.
The newly created stack doesn't automatically get trigged.
Solution: Using a Trigger Policy
You can create a trigger policy that automatically triggers newly created stacks. This policy should be attached to the administrative stack that creates other stacks.
Here's an example trigger policy:
package spacelift
import future.keywords
trigger[stack_id] {
some change in input.run.changes
# Only act on added spacelift_stack resources
change.action == "added"
change.entity.type == "spacelift_stack"
# Extract the real stack ID from the nested value
stack_id := change.entity.data.values.id
}
sample = trueHow It Works
This trigger policy:
Evaluates at the end of each run on your administrative stack
Looks for newly added
spacelift_stackresourcesExtracts the stack ID from each newly created stack
Automatically triggers a run on those new stacks
Only triggers on creation (not updates) to avoid unnecessary runs
Handles multiple stacks being created in a single run
Alternative Solution: Using spacelift_run Resource
You can also use the spacelift_run resource alongside your spacelift_stack resources. The spacelift_run resource has a keepers parameter that triggers recreation when values change, which can be used to ensure an initial run occurs.
Important Notes
Trigger policies only evaluate at the end of a run, so you need a completed run first
The policy uses the resource address/name from the data input to dynamically determine which stacks to trigger
This approach works best when you have a centralized administrative stack managing the creation of other stacks