Terraform Plan Pack
URL slug: terraform-plan
The pack reads the text output of terraform plan and turns each resource change into its own
analysis unit. The input can be one stack, or a Terramate run that prints several stacks one after
the other. This page is for engineers who send plans to OpenTremor and want to know what each unit
holds.
How the pack splits a plan
Section titled “How the pack splits a plan”parse_plan (opentremor_pack_terraform_plan/parser.py) works in two steps:
- It finds every resource header and its stack. A header is a comment line
# <address> <action wording>whose wording is one of Terraform’s action phrases (table below). The same pass readsterramate: Entering stack in <path>lines, so each header knows its stack (group_path). - It cuts the body of each unit. A body runs from its header line to the next header. A
Plan: N to add...summary line ends it earlier, because that line closes the stack’s section. A header with an empty body gives no unit.
One table answers both “is this line a header?” and “which action is it?”. The two answers cannot drift apart.
Action wording
Section titled “Action wording”| Phrase in the header | action |
|---|---|
will be created | create |
will be destroyed | destroy |
will be updated in-place | update |
will be replaced / must be replaced | replace |
is tainted, so must be replaced | replace |
will be read during apply | read |
has moved to <address> | move |
Type and name
Section titled “Type and name”type and name come from the address in the header, not from the resource body. The parser
takes the last <type>.<name> of the address, after any module.<name> prefix and data.. Data
sources and resources inside modules need no special handling:
| Address | type | name |
|---|---|---|
aws_security_group.web | aws_security_group | web |
module.network.aws_subnet.private | aws_subnet | private |
data.aws_ami.latest | aws_ami | latest |
module.buckets["logs.eu"].aws_s3_bucket.this | aws_s3_bucket | this |
aws_iam_user.users["ops.team"] | aws_iam_user | users["ops.team"] |
Terramate stacks
Section titled “Terramate stacks”In a multi-stack Terramate output, each header gets the stack of the last
terramate: Entering stack in <path> line above it. That path is its group_path.
terramate: Entering stack in /infra/network/staging/eu-west-1terramate: Executing command "terraform show -no-color tfplan"
Terraform will perform the following actions:
# aws_iam_role.ci_deploy must be replaced ...
Plan: 1 to add, 0 to change, 1 to destroy.terramate: Entering stack in /infra/network/prod/global...
# aws_iam_user.service_account will be created ...
Plan: 2 to add, 0 to change, 0 to destroy.terramate: Entering stack in /infra/tooling/staging/eu-west-1...
No changes. Your infrastructure matches the configuration.This output gives one unit per header shown: one from the first stack and one from the second. The third stack has no changes, so it gives no unit.
What a unit holds
Section titled “What a unit holds”{ "hash": "<sha256 of the normalised body>", "type": "aws_security_group", "name": "web", "action": "update", "body": " # aws_security_group.web will be updated in-place\n ~ resource ...", "metadata": { "generated_at_utc": "2026-04-28T10:30:00Z", "source_path": null, "group_path": "/infra/network/dev/eu-west-1" }}group_path is null for plain terraform plan output, without Terramate.
How the hash is computed
Section titled “How the hash is computed”The hash comes from OpenTremor Core’s libs/hash.py. Before hashing, core trims each line, drops
blank lines, and drops every line that holds one of Terraform’s placeholders (case-insensitive):
| Line dropped when it contains | Example |
|---|---|
(known after apply) | id = (known after apply) |
(sensitive value) | password = (sensitive value) |
(will be computed) | arn = (will be computed) |
So a second run of the same plan gets the same hashes, and OpenTremor reuses the earlier analysis instead of calling the LLM again. Two identical resource bodies in different stacks also share one stored analysis. This is on purpose: the stack path is not part of the body.
Rulesets
Section titled “Rulesets”The rules are Markdown files in the package’s opentremor_pack_terraform_plan/rules/ folder:
| File | Served at |
|---|---|
generic-rules.md | GET /v1/terraform-plan/rules |
aws-rules.md | GET /v1/terraform-plan/rules?rule_type=aws |
To add a variant, add a {type}-rules.md file. The pack finds it on its own; there is nothing to
register.
The aws variant suggestion
Section titled “The aws variant suggestion”When most resources in a repository’s plan come from the AWS provider (aws_*, including
resources in modules and data sources), the pack suggests the aws variant for that repository.
The suggestion appears on the repository’s page in the dashboard. A person applies or dismisses
it; the pack never changes the rules on its own. A plan split evenly between two providers gets no
suggestion. Neither does a plan whose main provider has no rules here, such as Google or Azure.
See OpenTremor-core#0024.
Stack paths in reports
Section titled “Stack paths in reports”Core’s Markdown and HTML reports show group_path when it is set:
- Resources are grouped by stack, and each resource section shows a
Stack: /infra/...line. - The findings summary table gets a Stack column when at least one resource has a path. Single-stack plans have no such column.
Examples
Section titled “Examples”A single-stack plan
Section titled “A single-stack plan”Terraform will perform the following actions:
# aws_db_instance.orders will be created + resource "aws_db_instance" "orders" { + identifier = "orders-primary" + storage_encrypted = false }
Plan: 1 to add, 0 to change, 0 to destroy.This gives one unit with group_path: null:
{ "hash": "d4e8b1...", "type": "aws_db_instance", "name": "orders", "action": "create", "body": "...", "metadata": { "generated_at_utc": "...", "source_path": null, "group_path": null }}A Terramate run
Section titled “A Terramate run”terramate run terraform show -no-color tfplan > full_plan.txtSend full_plan.txt as it is; it needs no preprocessing. You get one unit per changed resource
across all stacks, each with its stack path.