Repository navigation
Description
Problem Description
devops tf notify-plan prints a wrong summary for a real plan, and it prints a fixed sample plan when the plan file does not exist.
- The command counts by a fixed text match:
adds = 2 if "2 to add" in raw_text else 0,changes = 1 if "1 to change" in raw_text else 0, anddestroys = 0. A plan with other counts gets+0 ~0 -0. - When
--plan-filenames a path that does not exist, the command prints the sample planPlan: 2 to add, 1 to change, 0 to destroy.and exits 0. The caller does not see that the file is missing.
Source: tf_notify_plan in src/devops_cli/commands/tf.py.
Reproduction Steps
- Write
Plan: 5 to add, 3 to change, 1 to destroy.toplan.txt. - Run
uv run devops tf notify-plan --plan-file plan.txt --json. - Run
uv run devops tf notify-plan --plan-file no-such-file.txt --json.
Expected vs Actual Behavior
Expected: step 2 gives adds 5, changes 3 and destroys 1. Step 3 fails with an error that names the missing file.
Actual: step 2 gives adds 0, changes 0 and destroys 0. Step 3 exits 0 and prints the sample plan with +2 ~1 -0.
Environment Diagnostics
devops-cli at origin/main, 2026-11-12.
Logs, Traces, or Terminal Output
$ devops tf notify-plan --plan-file plan.txt --json
{"pr": null, "adds": 0, "changes": 0, "destroys": 0, ...}
$ devops tf notify-plan --plan-file no-such-file.txt --json
{"pr": null, "adds": 2, "changes": 1, "destroys": 0, ...}
Existing tool considered
tofu show -json <planfile> gives the planned actions of each resource in resource_changes, so the counts can come from OpenTofu and not from a text match. Typer can refuse a path that does not exist (exists=True on the option).
Related
Related: #3644, which makes the words of the command say what it does.
Source: #3644
Alternatives check of 2026-11-15: in-use.
The repository already uses this tool.
Tool: opentofu/opentofu (https://github.com/opentofu/opentofu), MPL-2.0, last activity 2026-11-13, maintained.
Proposed design
Problem statement
The devops tf notify-plan command reports the wrong counts for a real plan and prints a fixed sample plan when the plan file is missing. It counts by a fixed text match, so a plan with other numbers gets +0 ~0 -0. A caller cannot see that the named plan file does not exist.
Acceptance criteria
Requirement: Plan counts from the summary line
The devops tf notify-plan command SHALL read the add, change and destroy counts from the plan text.
Scenario: A plan with five adds, three changes and one destroy
- WHEN the plan file holds
Plan: 5 to add, 3 to change, 1 to destroy.and the caller passes--json - THEN the JSON output holds
"adds": 5,"changes": 3and"destroys": 1.
Requirement: Counts with an import segment
The command MUST read each count from its own N to <action> segment, whatever the number of segments in the summary line.
Scenario: A plan that imports one resource and changes two
- WHEN the plan file holds
Plan: 1 to import, 0 to add, 2 to change, 0 to destroy.and the caller passes--json - THEN the JSON output holds
"adds": 0,"changes": 2and"destroys": 0.
Requirement: A plan with no changes
The command SHALL report zero counts when the plan text holds no change summary.
Scenario: A plan that matches the configuration
- WHEN the plan file holds
No changes. Your infrastructure matches the configuration.and the caller passes--json - THEN the JSON output holds
"adds": 0,"changes": 0and"destroys": 0.
Requirement: A plan file that does not exist
The command MUST stop with a non-zero exit code and an error that names the path when --plan-file names a file that does not exist.
Scenario: A missing plan file
- WHEN the caller runs
devops tf notify-plan --plan-file no-such-file.txt --json - THEN the exit code is not 0, the error text holds
no-such-file.txt, and no plan summary is printed.
Requirement: A plan file is required
The command MUST refuse a call that names no plan file.
Scenario: A call with no plan file
- WHEN the caller runs
devops tf notify-plan --jsonwith no--plan-file - THEN the exit code is not 0 and the error text names
--plan-file.
Requirement: No sample plan in the printed comment
The command SHALL print only the plan text that the named file holds.
Scenario: The table output for a plan with other counts
- WHEN the plan file holds
Plan: 5 to add, 3 to change, 1 to destroy.and the caller runs the command with no--json - THEN the printed comment holds
+5 ~3 -1and holds no+2 ~1 -0.
Existing Tool Considered
OpenTofu (opentofu/opentofu, MPL-2.0, maintained, last activity 2026-11-13) is already in use in the repository, so the verdict is in-use. Its tofu show -json <planfile> renders the planned actions of each resource in resource_changes, so it covers the counting half. It lacks the refusal of a --plan-file path that does not exist; the CLI option gives that refusal with Typer exists=True. It gives no ready-made adds/changes/destroys summary, so the command aggregates the counts and prints its own JSON. It also reads a saved plan file, not the plan output text that this option accepts, so the counts come from the summary line of that text.
Key questions
- Where does the fixed text match live?:
tf_notify_planinsrc/devops_cli/commands/tf.pysetsaddsfrom a fixed text match at line 843 andchangesat line 844, and setsdestroysto 0 at line 845. [sources: src/devops_cli/commands/tf.py:817, src/devops_cli/commands/tf.py:843, src/devops_cli/commands/tf.py:845] - How does the command get the add, change and destroy counts?: Parse the summary line of the plan text with one regular expression for each count, and take the plan text that the named file holds. (best practice) [sources: src/devops_cli/commands/tf.py:817, src/devops_cli/commands/tf.py:843]
- Chosen: Parse each
N to <action>segment of the plan text. The option reads the plan output text, as the reproduction shows, and this covers plans with an import segment and plans with no changes. - Rejected: Run
tofu show -jsonon the plan file.tofu show -jsonreads a saved plan file, not the plan output text that the option accepts, and the command runs under theno-external-requestdry-run class. - Rejected: Keep the fixed text match. It reports 0 for each count unless the plan holds the sample numbers, which is the defect.
- Chosen: Parse each
- How does the command refuse a
--plan-filepath that does not exist?: Declare--plan-fileas aPathoption with Typerexists=True,dir_okay=Falseandreadable=True, so Typer stops the call with exit code 2 and an error that names the path. (best practice) [sources: src/devops_cli/commands/tf.py:817]- Chosen: Typer
exists=Trueon the option. Typer checks the path before the command body runs, names the path in the error, and exits non-zero. - Rejected: A manual
Path.exists()check in the body. It repeats a check that the option type gives, and it needs its own message entry.
- Chosen: Typer
- Is
--plan-filerequired?: Yes. Remove the sample fallback and make the option required, so a call with no plan file stops with a Typer error that names--plan-file. (best practice) [sources: src/devops_cli/commands/tf.py:817, tests/commands/test_tf_notify_plan.py]- Chosen: Require
--plan-file. The sample plan filled the absent-file case; with it gone the command has no input, and Typer names the missing option. - Rejected: Read the plan text from stdin when the option is absent. The issue asks for no new input mode, and it adds a test surface that no requirement covers.
- Rejected: Keep the sample plan for the absent case. It is the fake output that the issue reports.
- Chosen: Require
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 12, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
fixprefix of the title gives the type.tf, and .github/labels.yml declares no scope/tf label. Add the label to the file to give the scope to this item.The command returns wrong counts and hides a missing file, but it does not crash or corrupt data.Users who rely on the summary get incorrect numbers and no error for a missing file.The fix replaces a text match with a JSON parse and adds a file-exists check, both small changes.devops-cli-service commentedon Nov 15, 2026
Alternatives check: in-use
Reason: Searches found no maintained Python library that turns a plan file into an adds/changes/destroys summary; the candidates are Go/TypeScript tools (tfplan2md, terraform-plan-parser) or thin binary wrappers (tofupy). OpenTofu itself, whose
tofu show -jsonthe issue names, already exposes each resource's actions inresource_changes, so it covers the counting half, but the missing-file refusal and the JSON summary of the command remain with the CLI (Typerexists=True).The repository already uses this tool.
Tool: opentofu/opentofu (https://github.com/opentofu/opentofu)
Covers:
tofu show -json <planfile>renders the saved plan as JSON, with each resource's planned actions inresource_changes.Lacks:
--plan-filepath that does not exist; that check has to come from the CLI option (Typerexists=True).Tools considered:
Searches run:
Sources:
Checked on 2026-11-15. A person decides what this means for the item. The check changes no label and closes no issue.
devops-cli-service commentedon Nov 16, 2026
Status set to Ready at fccb781 (see proposed design in issue body).
devops-cli-service commentedon Nov 18, 2026
Released in v0.174.6: https://github.com/dan-petty/devops-cli/releases/tag/v0.174.6
devops-cli-service commentedon Nov 18, 2026
Live since 2026-11-18 02:58 UTC