plan

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package plan parses a `terraform show -json` plan into grouped resource actions.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAPlan = errors.New("input is not a Terraform plan document: no " +
	`"resource_changes" or "planned_values" key found. Produce it with ` +
	"`terraform plan -out=plan.bin && terraform show -json plan.bin`, not " +
	"`terraform show -json` (which prints state)")

ErrNotAPlan is returned when the input parses as JSON but is not a Terraform plan document.

Order is the display order for actions.

Functions

This section is empty.

Types

type Action

type Action string

Action is the effective change kind for a resource.

const (
	Create  Action = "create"
	Update  Action = "update"
	Replace Action = "replace"
	Destroy Action = "destroy"
	// Forget is Terraform's `removed` block outcome: the object is dropped from
	// state but left running. Nothing is destroyed, yet the resource stops being
	// managed, so it is reported rather than hidden.
	Forget Action = "forget"
	// Unknown is any action combination this version does not recognise (an
	// empty array, or a verb from a newer Terraform). It is surfaced so the
	// summary can never silently under-report a change it did not understand.
	Unknown Action = "unknown"
	NoOp    Action = "no-op"
	Read    Action = "read"
)

type ResourceChange

type ResourceChange struct {
	Address string
	Type    string
	Action  Action
}

ResourceChange is one planned change.

type Stats added in v1.0.0

type Stats struct {
	Create  int  `json:"create"`
	Update  int  `json:"update"`
	Replace int  `json:"replace"`
	Destroy int  `json:"destroy"`
	Forget  int  `json:"forget"`
	Unknown int  `json:"unknown"`
	NoOp    int  `json:"no_op"`
	Read    int  `json:"read"`
	Total   int  `json:"total"`
	HasRisk bool `json:"has_risk"`
}

Stats is the machine-readable form of a Summary, for `--stats-json` and for GitHub Actions step outputs.

type Summary

type Summary struct {
	Changes []ResourceChange
	Counts  map[Action]int
}

Summary is the parsed plan grouped by action.

func Parse

func Parse(data []byte) (Summary, error)

Parse reads plan JSON produced by `terraform show -json plan.bin`.

Input that parses as JSON but carries neither "resource_changes" nor "planned_values" is rejected instead of being reported as an empty plan: a state file, a truncated download, or an unrelated JSON document must never render as "No changes".

func (Summary) HasRisk

func (s Summary) HasRisk() bool

HasRisk reports whether the plan destroys, replaces, or forgets anything.

func (Summary) Stats added in v1.0.0

func (s Summary) Stats() Stats

Stats projects the summary into counts a workflow can gate on.

func (Summary) Total

func (s Summary) Total() int

Total counts the changes that actually modify infrastructure or state (excludes no-op and read).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL