Common workflows
Plan on pull requests
Run Plan, without Apply, on every pull request, so reviewers know what a change does before it's merged.
- pipeline: Plan PR
events:
- type: PULL_REQUEST
actions:
- action: Plan
type: TERRAFORM_PLAN
tool: OPENTOFU
version: 1.12.6
working_directory: infra
backend:
type: ARTIFACT
artifact: infra-state
artifact_version: prod
The run status is reported to the pull request. Reviewers open the run to see the resource diff. To post the result somewhere else, add an action that sends $BUDDY_ACTION_TF_PLAN_SUMMARY, for example to Slack. See Pull request testing for how pull request pipelines work.
Require approval for cost increases
Changes that raise the monthly cost by more than 50 USD wait for approval. Cheaper changes and cost reductions go to Apply right away. The variables and limitations are described in Cost estimation.
- pipeline: Deploy infra
events:
- type: PUSH
refs:
- refs/heads/main
actions:
- action: Plan
type: TERRAFORM_PLAN
tool: OPENTOFU
version: 1.12.6
working_directory: infra
backend:
type: ARTIFACT
artifact: infra-state
artifact_version: prod
cost_estimation:
enabled: true
integration: infracost
fail_on_error: true
- action: Approve cost increase
type: WAIT_FOR_APPLY
description: "Monthly cost: $BUDDY_ACTION_TF_PLAN_COST_PAST_MONTHLY -> $BUDDY_ACTION_TF_PLAN_COST_MONTHLY $BUDDY_ACTION_TF_PLAN_COST_CURRENCY (+$BUDDY_ACTION_TF_PLAN_COST_DIFF_MONTHLY)"
trigger_conditions:
- trigger_condition: VAR_GREATER_THAN
trigger_variable_key: BUDDY_ACTION_TF_PLAN_COST_DIFF_MONTHLY
trigger_variable_value: "50"
- action: Apply
type: TERRAFORM_APPLY
tool: OPENTOFU
version: 1.12.6
working_directory: infra
backend:
type: ARTIFACT
artifact: infra-state
artifact_version: prod
Destroy the infrastructure
Pass -destroy to the Plan action. The plan then deletes every resource in the state, and Apply runs it like any other plan. Keep this in a separate, manually triggered pipeline, with an approval that blocks self-approval:
- pipeline: Destroy staging
actions:
- action: Plan destroy
type: TERRAFORM_PLAN
tool: OPENTOFU
version: 1.12.6
working_directory: infra
additional_args: -destroy
backend:
type: ARTIFACT
artifact: infra-state
artifact_version: staging
- action: Approve
type: WAIT_FOR_APPLY
description: "Destroys: $BUDDY_ACTION_TF_PLAN_DESTROY_RESOURCES"
prevent_self_approval: true
- action: Apply
type: TERRAFORM_APPLY
tool: OPENTOFU
version: 1.12.6
working_directory: infra
backend:
type: ARTIFACT
artifact: infra-state
artifact_version: staging
Import existing resources
With an import block (Terraform 1.5 and later, OpenTofu): add the block to your code and run the regular Plan → Apply pipeline. The diff shows the resource being imported.
import {
to = aws_s3_bucket.assets
id = "my-assets-bucket"
}
With terraform import: run it in the Terraform CLI action.
Validate before planning
Catch formatting and syntax errors before they reach Plan. Run fmt and validate in the Terraform CLI action at the start of the pipeline:
- action: Validate
type: TERRAFORM
version: 1.5.7
working_directory: infra
commands: |-
terraform fmt -check -recursive
terraform init -backend=false
terraform validate
- action: Plan
type: TERRAFORM_PLAN
tool: OPENTOFU
version: 1.12.6
working_directory: infra
init -backend=false downloads providers and modules without touching the state. If validation fails, the run stops before Plan.
Linters and security scanners such as tflint, checkov, or trivy can run in their own images in a Run Docker Image action.
Last modified on Nov 24, 2026