Merging, hooks and automation
Fork PRs, merge checkouts, automerge, locks after apply, apply notifications, unmerged reminders, hooks around plans and applies, depends_on, log retention, pausing every apply, teriac cancel and running commands from the API.
New in 0.2.4. Upgrade teriac server to 0.2.4 or later to use the settings on this page.
These settings shape what happens around a plan and an apply: what gets checked out, what happens
after an apply, and who hears about it. They go in a repo's entry in repos.yaml.
repos:
- id: github.com/acme/infra
allow_fork_prs: false # default: PRs from forks are refused
checkout: merge # plan the PR merged into its base branch; default "branch"
automerge: { method: squash, delete_branch: true } # or true (a merge commit)
unlock_after_apply: false # default: an applied project stays locked until the PR merges or closes
notify_applies: [infra-alerts] # every apply here, done or failed
log_retention_days: 30 # clear run logs 30 days after a PR's last apply
remind_unmerged: { after_hours: 24, notify: [infra-alerts], comment: true }
hooks: # server config only; a repo can't add hooks
pre_plan: [{ name: lint, run: "tflint" }]
post_plan: [{ name: scan, run: "checkov -f \"$PLAN_JSON\"" }]
pre_apply: [{ name: gate, run: "./scripts/change-window.sh" }]
post_apply: [{ name: notify, run: "./scripts/announce.sh" }]| Key | Default | |
|---|---|---|
allow_fork_prs |
false |
Plan and apply pull requests from forks |
checkout |
branch |
merge plans the PR merged into its base branch |
automerge |
off | true, or { method: merge | squash | rebase, delete_branch } |
unlock_after_apply |
false |
Free each project as soon as it's applied |
notify_applies |
Channels told about every apply | |
log_retention_days |
Clear run logs this many days after a PR's last apply | |
remind_unmerged |
off | { after_hours, notify, comment } |
hooks |
Commands before and after plans and applies |
Fork pull requests
A pull request from a fork runs someone else's code, and teriac would run it with your cloud credentials. So by default teriac doesn't check out, plan or apply fork PRs. It posts one comment explaining why, and every refusal is audited.
Set allow_fork_prs: true only for repos where you trust everyone who can open a PR.
Plan the merge result
By default teriac plans the PR's own commit (checkout: branch). With checkout: merge it plans
GitHub's test merge of that exact commit into the base branch, so the plan includes what's on the
base branch now. A PR with merge conflicts fails with a clear message.
After an apply
A plan is applied once
After an apply, successful or not, its plan file is deleted. Applying again needs a new
teriac plan; a failed apply says the plan was used up. Runs, output and PR comments are kept.
Locks stay until the merge
By default an applied project stays locked to its PR until the PR is merged or closed (or someone unlocks it). Another PR can't then undo an apply that was never merged. The apply reply says so, and how to unlock.
unlock_after_apply: truefrees each project as soon as it's applied.- A failed apply always keeps the lock.
- Unlock, merge and close always end a project: the lock is released and its saved plan and live output are deleted.
Automerge
automerge: true # a merge commit
automerge: { method: squash, delete_branch: true } # or merge / rebaseThe GitHub App needs Contents: read & write for this. Once every project with planned changes at the current commit is applied, and nothing failed, teriac merges the whole PR (all its files, not only the applied projects).
- Only that commit is merged: a newer push makes GitHub refuse the merge.
- Branch protection still applies. A refused merge is reported with GitHub's reason, and a merge refused for a missing permission says which one to add.
Apply notifications and reminders
notify_applies: [infra-alerts]sends a message for every apply in the repo, done or failed.remind_unmerged: { after_hours: 24, notify: [infra-alerts] }sends one reminder, mentioning whoever applied, when a PR is applied but still open after that long. It's also posted on the PR, unlesscomment: false. teriac checks with GitHub before reminding, so a merged PR is left alone.
Channels are defined under channels in repos.yaml; see
drift checks.
Hooks
Run your own commands around plans and applies:
| Hook | Runs | When it fails |
|---|---|---|
pre_plan |
Before Terraform's plan | The run fails |
post_plan |
After the plan, with PLAN_FILE and PLAN_JSON set |
The run fails, and the plan can't be applied |
pre_apply |
Before the apply | The run fails |
post_apply |
After the apply | It's reported; the apply stands |
- Hooks come from the server's config only. A repo can't add them, in
teriac.yamlor anywhere else, so a PR can't run its own commands this way. - They run with
shin the project folder, and their output goes to the log and the live view.
hooks:
post_plan:
- { name: checkov, run: "checkov -f \"$PLAN_JSON\" --framework terraform_plan --quiet" }
pre_apply:
- { name: change-window, run: "./scripts/change-window.sh" }For checks that should block an apply with an override, prefer policy commands; hooks are for anything else.
Order between plain Terraform projects
Terragrunt projects get their order from dependency blocks. Plain Terraform and OpenTofu have
none, so declare it in the repo's teriac.yaml:
projects:
- dir: network
- dir: app
depends_on: [network] # names or dirsThen app:
- is planned whenever
networkchanges; - is applied after
networkin the same command, and skipped ifnetworkfails; - is planned again after
networkis applied, for you to review, instead of applying its old plan.
teriac doesn't pass outputs between them: app reads network's values itself, for example with
a terraform_remote_state data source. This isn't Terraform's own depends_on, which orders
resources inside one project.
Log retention
log_retention_days: 30 # per repo, or TERIAC_LOG_RETENTION_DAYS (Helm: config.logRetentionDays)A PR's run logs are cleared that many days after its last apply. Summaries, metrics and PR comments stay, and the dashboard says when a log was cleared.
Pause every apply
An emergency stop for incidents. Planned windows belong in change freezes.
-
Admins pause and resume from the dashboard's Guardrails page (the Emergency stop card asks for a reason), or with the API:
curl -X POST -H "Authorization: Bearer $TERIAC_API_TOKEN" -H 'Content-Type: application/json' \ -d '{"reason": "Incident INC-4821"}' https://teriac.acme.dev/api/applies/pause curl -X POST -H "Authorization: Bearer $TERIAC_API_TOKEN" https://teriac.acme.dev/api/applies/resume -
While paused, every apply and state change in every repo is refused with the reason. Running applies finish, and plans still run.
-
The dashboard shows an All applies paused banner with who paused, when and why.
-
Emergency access can still get through. Pausing and resuming are audited.
Cancel a PR's runs
teriac cancelDrops the PR's queued plans and applies, and stops its running plans (Terraform gets an interrupt and releases its state lock). Running applies finish. The PR's author, or anyone with write access or more, can cancel. It skips the PR's queue, so it isn't stuck behind what it cancels.
Run commands from outside GitHub
POST /api/commands runs plan, apply, unlock or cancel on a PR, for example from a chat
bot or a script:
curl -X POST https://teriac.acme.dev/api/commands \
-H "Authorization: Bearer $TERIAC_API_TOKEN" -H 'Content-Type: application/json' \
-d '{"repo": "github.com/acme/infra", "pr": 42, "command": "apply -p envs/dev", "as": "alice"}'- It runs as a GitHub login: the one in
aswith the API token, or yourself when signed in with GitHub. Password and SSO users have no GitHub identity, so they can't. - That person's permissions and the PR's approvals, locks, freezes and fork rule apply, as for a comment.
- The answer is
202 Accepted. teriac posts the result on the PR, saying it came from the API and for whom, and the request is audited.