Skip to content

cli: add -json-output and -t flags to nomad job plan#27957

Open
ilya-shevelev wants to merge 1 commit into
hashicorp:mainfrom
ilya-shevelev:feat/job-plan-output-format
Open

cli: add -json-output and -t flags to nomad job plan#27957
ilya-shevelev wants to merge 1 commit into
hashicorp:mainfrom
ilya-shevelev:feat/job-plan-output-format

Conversation

@ilya-shevelev

Copy link
Copy Markdown

Summary

  • Adds -json-output flag to nomad job plan for JSON-formatted output of the plan response
  • Adds -t flag for Go template formatting, consistent with nomad job inspect
  • Preserves the existing -json flag for input parsing (JSON jobfile format) — no conflict
  • Handles both single-region and multi-region plans

Closes #27369

Details

The nomad job plan command previously only supported human-readable output, making it difficult to programmatically parse plan results. This PR adds two new output formatting options:

  • -json-output: Outputs the full api.JobPlanResponse as JSON. Named differently from -json to avoid the existing input flag conflict.
  • -t: Formats output using a Go template (e.g., -t '{{.Diff.ID}}'), consistent with how nomad job inspect works.

Using both flags simultaneously returns an error. When neither flag is specified, the existing human-readable output is preserved.

For multi-region plans, the output is a map[string]*api.JobPlanResponse keyed by region name.

Test plan

  • TestPlanCommand_JsonOutputAndTemplateMutuallyExclusive — verifies error on combined flags
  • TestPlanCommand_JsonOutput — e2e test: plans a job, verifies valid JSON output
  • TestPlanCommand_TemplateOutput — e2e test: plans a job with -t, verifies template renders correctly

Add output formatting options to `nomad job plan` so users can get the
plan result as JSON or formatted via Go templates. The existing `-json`
flag is used for input parsing, so a new `-json-output` flag is
introduced for output formatting to avoid conflicts. The `-t` flag
enables Go template formatting, consistent with other commands like
`nomad job inspect`. Both flags work for single-region and multi-region
plans, and the existing human-readable output remains the default.

Closes hashicorp#27369

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ilya-shevelev ilya-shevelev requested review from a team as code owners May 12, 2026 21:05
@hashicorp-cla-app

Copy link
Copy Markdown

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

@tgross

tgross commented Jun 25, 2026

Copy link
Copy Markdown
Member

Waiting on a CLA signature on this still.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

Provide output formatting options for Nomad job plan CLI

3 participants