YAML for Terraform Drift Detection

View as Markdown

Run terraform/tofu init and plan in refresh-only mode to find resources that were changed or removed outside of Terraform, then render the drift per resource.

YAML parameters for Terraform Drift Detection

PARAMETERS
toolrequiredstring enum
The Terraform tool to run: OPENTOFU, TERRAFORM (FOSS, up to 1.5.7) or CUSTOM.
Allowed enum:
OPENTOFU,
TERRAFORM,
CUSTOM
typerequiredstring

Value: TERRAFORM_DRIFT_DETECTION

actionrequiredstring
Unique identifier for the action within the pipeline.
fail_on_driftboolean
Whether the action fails once the infrastructure differs from the Terraform state. Defaults to true; set it to false to report the drift in the output variables and let the pipeline continue.
cost_estimationTerraformCostEstimationYaml
Monthly cost estimation of the plan with Infracost, shown per resource in the run, exported as BUDDY_ACTION_TF_DRIFT_COST_* variables and sent as a commit status to the Git provider. Prices AWS, Azure and Google Cloud resources.
versionstring
Tool version, e.g. 1.9.0 or latest. Required unless tool is CUSTOM.
custom_binary_pathstring
Path to the binary inside the Docker image, e.g. /usr/local/bin/tofu. Required when tool is CUSTOM.
docker_image_namestring
Custom Docker image to run in. Required when tool is CUSTOM.
docker_image_tagstring
Tag of the custom Docker image.
image_locationstring enum
The location of the image used by the action.
Allowed enum:
PUBLIC_REGISTRY,
PRIVATE_REGISTRY,
ACTION,
ARTIFACT_REGISTRY
docker_registrystring enum
The type of registry from which the image is retrieved.
Allowed enum:
NONE,
DOCKER_HUB,
AMAZON_ECR,
GOOGLE_GCR,
GOOGLE_ARTIFACT_REGISTRY,
OTHER,
GIT_HUB_CONTAINER_REGISTRY,
ARTIFACT_REGISTRY,
DIGITAL_OCEAN_CONTAINER_REGISTRY
registrystring
The URL of the Docker registry. Required when docker_registry is OTHER.
loginstring
Username for Docker registry authentication. Used with password when docker_registry is OTHER.
passwordstring
Password for Docker registry authentication. Used with login when docker_registry is OTHER.
regionstring
The region of the Docker registry (for Amazon ECR).
integrationstring
Docker registry integration used to pull the custom image. It refers to an integration in the workspace by its identifier, not by its display name.
working_directorystring
Path relative to the repository root. Defaults to ..
additional_argsstring
Extra CLI arguments appended to the command, as a single space-separated string. Example: -var-file=prod.tfvars -parallelism=20.
tf_workspacestring
Terraform workspace to run in, exported to the tool as TF_WORKSPACE. Set the same value in the Plan and Apply actions, otherwise Apply runs against a different state. Defaults to default, or to TF_WORKSPACE set as a pipeline variable.
backendTerraformRunBackendYaml
State backend configuration: type (CUSTOM, AMAZON, GOOGLE, ARTIFACT), integration, region, artifact and artifact_version. Defaults to CUSTOM, which means the backend is declared in the Terraform code. The backend integration is separate from the action integration pulling the custom runner image.
trigger_timestring enum
Specifies when the action should be executed. ON_SUCCESS actions run after every successful run, also one ended by an EARLY_EXIT action.
Allowed enum:
ON_EVERY_EXECUTION,
ON_SUCCESS,
ON_FAILURE,
ON_BACK_TO_SUCCESS,
ON_WARNING,
ON_WAIT_FOR_APPROVE,
ON_TERMINATE
loopstring[]
Names of the variables to loop over (IMAGES, not $IMAGES and not a value). The action runs once for each item of the value, and once for each combination of items when several variables are listed. The variable value is split into items by new lines, or by commas when it has no new lines (a single-line JSON object or key=value pairs stays one item). An item that is a JSON object or key=value pairs also sets one variable per key, named <VARIABLE>_<key>; an item that starts with EXTRACT: sets them as plain <key>.
run_only_on_first_failureboolean
When true, the action runs only on the first failure instead of on each failure. Used only when trigger_time is ON_FAILURE.
disabledboolean
When set to true the action is disabled. By default it is set to false.
timeoutinteger
The timeout in seconds. It cannot exceed the action time limit of the workspace plan; a higher value is rejected.
ignore_errorsboolean
If set to true the execution will proceed, mark action as a warning and jump to the next action. Doesn't apply to deployment actions.
retry_intervalinteger
Delay time between auto retries in seconds.
retry_countinteger
Number of retries if the action fails.

Constraints: ≤ 10

run_nextstring enum
Defines whether the action should run in parallel with the next one.
Allowed enum:
WAIT_ON_SUCCESS,
IN_SOFT_PARALLEL,
IN_HARD_PARALLEL
trigger_conditionsTriggerConditionYaml[]
The list of trigger conditions to meet so that the action can be triggered.
variablesVariableYaml[]
The list of variables you can use in the action.

Outputs for Terraform Drift Detection

OUTPUT VARIABLES
BUDDY_ACTION_TF_DRIFT_OUTPUT_FILE
Path to the main result file of this action, relative to the pipeline filesystem root.

Example: .buddy/output/terraform/drift_12_a1b2c3d.tfplan

BUDDY_ACTION_TF_DRIFT_DETECTED
Whether any resource differs from the Terraform state.

Example: true

BUDDY_ACTION_TF_DRIFT_CHANGE_COUNT
Number of resources changed outside of Terraform.

Example: 3

BUDDY_ACTION_TF_DRIFT_DESTROY_COUNT
Number of resources removed outside of Terraform.

Example: 1

BUDDY_ACTION_TF_DRIFT_TOTAL_COUNT
Number of drifted resources. Resources still matching the state are not counted.

Example: 4

BUDDY_ACTION_TF_DRIFT_SUMMARY
Summary of the detected drift.

Example: 3 drifted, 1 removed

BUDDY_ACTION_TF_DRIFT_RESOURCES
Addresses of all drifted resources, one per line.

Example: aws_instance.web aws_s3_bucket.logs

BUDDY_ACTION_TF_DRIFT_DESTROY_RESOURCES
Addresses of the resources removed outside of Terraform, one per line.

Example: aws_s3_bucket.logs

BUDDY_ACTION_TF_DRIFT_WORKSPACE
Workspace the action ran in.

Example: default

BUDDY_ACTION_TF_DRIFT_TOOL_VERSION
Version of Terraform or OpenTofu that detected the drift.

Example: 1.5.7

BUDDY_ACTION_TF_DRIFT_COST_MONTHLY
Estimated monthly cost after the change, as a decimal number without the currency.

Example: 515.20

BUDDY_ACTION_TF_DRIFT_COST_PAST_MONTHLY
Estimated monthly cost before the change, as a decimal number without the currency.

Example: 420.00

BUDDY_ACTION_TF_DRIFT_COST_DIFF_MONTHLY
Change of the estimated monthly cost, negative when the cost drops. Use it in a VAR_GREATER_THAN trigger condition to require an approval of a cost increase.

Example: 95.20

BUDDY_ACTION_TF_DRIFT_COST_DIFF_PERCENT
Change of the estimated monthly cost in percent of the cost before the change. Not exported when the cost before the change is 0.

Example: 22.7

BUDDY_ACTION_TF_DRIFT_COST_CURRENCY
Currency of the estimated costs.

Example: USD

BUDDY_ACTION_TF_DRIFT_COST_UNPRICED_COUNT
Number of resources Infracost does not support and left out of the estimation.

Example: 2

OUTPUT FILES
.buddy/output/terraform/drift_$BUDDY_RUN_ID_$BUDDY_ACTION_RUN_HASH.tfplan
Binary refresh-only plan file, which a later apply action can use to write the drift into the state.

Last modified on Nov 26, 2026

YAML examples for Terraform Drift Detection

Terraform Drift Detection

yaml
- action: "Detect drift"
  type: "TERRAFORM_DRIFT_DETECTION"
  tool: "OPENTOFU"
  version: "1.9.0"

Terraform Drift Detection reporting the drift without failing

yaml
- action: "Detect drift"
  type: "TERRAFORM_DRIFT_DETECTION"
  tool: "OPENTOFU"
  version: "1.9.0"
  working_directory: "./infrastructure/prod"
  tf_workspace: "production"
  additional_args: "-var-file=prod.tfvars -parallelism=20"
  fail_on_drift: false
  cost_estimation:
    enabled: true
    integration: "infracost"
    fail_on_error: false

Terraform Drift Detection with custom binary

yaml
- action: "Detect drift"
  type: "TERRAFORM_DRIFT_DETECTION"
  tool: "CUSTOM"
  custom_binary_path: "/opt/terraform/bin/terraform"
  docker_image_name: "mycompany/terraform-runner"
  docker_image_tag: "1.9.5"
  working_directory: "./infrastructure/prod"

Terraform Drift Detection with custom image from a private registry

yaml
- action: "Detect drift"
  type: "TERRAFORM_DRIFT_DETECTION"
  tool: "CUSTOM"
  custom_binary_path: "/usr/local/bin/tofu"
  docker_image_name: "mycompany/terraform-runner"
  docker_image_tag: "1.9.5"
  image_location: "PRIVATE_REGISTRY"
  docker_registry: "OTHER"
  registry: "my.registry.com"
  login: "buddyworks"
  password: "${top_secret_password}"
  working_directory: "./infrastructure/prod"

Terraform Drift Detection with state in a Buddy artifact

yaml
- action: "Detect drift"
  type: "TERRAFORM_DRIFT_DETECTION"
  tool: "OPENTOFU"
  version: "1.9.0"
  working_directory: "./infrastructure/prod"
  backend:
    type: "ARTIFACT"
    artifact: "terraform-state"
    artifact_version: "1.0.0"

Terraform Drift Detection with state in Amazon S3

yaml
- action: "Detect drift"
  type: "TERRAFORM_DRIFT_DETECTION"
  tool: "OPENTOFU"
  version: "1.9.0"
  working_directory: "./infrastructure/prod"
  backend:
    type: "AMAZON"
    integration: "amazon-web-services"
    region: "us-east-1"