Skip to content

filter(terraform): add terraform plan and apply filters #41

@mpecan

Description

@mpecan

Goal

Add filters for terraform plan and terraform apply — two of the highest line-count outputs in the DevOps toolchain.

Background

A terraform plan with 100 managed resources where a single attribute changes generates ~140 lines per resource showing every attribute, whether changed or not. Real-world reports: plans for 1,000-resource infrastructures produce 10,000+ line outputs. Community tools like terraform-plan-filter and tf-summarize exist specifically for this pain point, showing strong demand. The same output is repeated verbatim during terraform apply.

Hashicorp issue #21639 tracks this, open since 2019.

Filters to Add

terraform/plan.tomlterraform plan

  • Skip: resource attribute lines showing unchanged values (lines with = but no +, -, ~, or -> change marker), comment lines noting "# (known after apply)" for unchanged resources
  • Keep:
    • Lines with + (resource creation)
    • Lines with - (resource deletion)
    • Lines with ~ (resource modification)
    • Lines with -> (in-place update of attribute value)
    • # <resource> will be created/destroyed/updated header lines
    • Plan: X to add, Y to change, Z to destroy. summary
    • No changes. output
    • Error lines

terraform/apply.tomlterraform apply

  • Similar to plan.toml for the plan portion
  • Keep all: progress lines during apply (<resource>: Creating..., <resource>: Creation complete after Xs)
  • Keep: Apply complete! Resources: X added, Y changed, Z destroyed.
  • Skip: the verbose attribute echo during apply for unchanged attributes

tofu/plan.toml + tofu/apply.toml

  • OpenTofu fork uses identical output format — add as separate filter files resolving to the same logic (or symlink-equivalent TOML)

Fixture Files Needed

  • tests/fixtures/terraform/plan-changes.txt — plan with a few changed resources in a large state
  • tests/fixtures/terraform/plan-no-changes.txt — no-op plan output
  • tests/fixtures/terraform/apply-success.txt — successful apply with creation output
  • tests/fixtures/terraform/apply-error.txt — apply failure

Acceptance Criteria

  • Unchanged resource attribute lines removed from plan output
  • All +, -, ~ change lines preserved
  • Plan summary line always preserved
  • terraform apply creation progress lines preserved
  • tofu resolves to same filters as terraform
  • Integration tests pass for all fixture files

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions