Documentation
¶
Overview ¶
Package plan parses a `terraform show -json` plan into grouped resource actions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 Policy ¶ added in v1.1.0
Policy marks some resources as protected and lets others out of the risk gate. Patterns are globs: `*` matches any run of characters (dots and brackets included) and `?` matches one character; everything else is literal, so `aws_instance.web[0]` needs no escaping.
A pattern applies to a change when it matches the full address (`module.db.aws_db_instance.main`), the resource type (`aws_db_instance`), or the address inside its module (`aws_db_instance.main`).
type ResourceChange ¶
type ResourceChange struct {
Address string
Type string
Action Action
// Reason is Terraform's action_reason code (for example
// "replace_because_tainted"), empty when the plan gives none.
Reason string
// ReplacePaths are the attribute paths that forced a replacement, such as
// "engine_version" or "ebs_block_device[0].volume_size". They name
// attributes only; no value is ever read.
ReplacePaths []string
// Deposed is set when the change applies to a deposed object (left over
// from a create_before_destroy replacement) rather than the current one.
Deposed bool
// ModuleAddress is the containing module instance (empty in the root
// module); it lets a policy pattern match the address inside the module.
ModuleAddress string
// Protected and RiskIgnored are set by Summary.Apply from a Policy.
Protected bool
RiskIgnored bool
}
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"`
ProtectedDestroy int `json:"protected_destroy"`
ProtectedReplace int `json:"protected_replace"`
HasCriticalRisk bool `json:"has_critical_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 ¶
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) Apply ¶ added in v1.1.0
Apply marks the summary's changes according to the policy. Protection wins over --ignore-risk: a resource matched by both stays protected and risky.
func (Summary) HasCriticalRisk ¶ added in v1.1.0
HasCriticalRisk reports whether the plan destroys or replaces a protected resource.
func (Summary) HasRisk ¶
HasRisk reports whether the plan destroys, replaces, or forgets anything that a policy has not exempted with --ignore-risk.
func (Summary) ProtectedCount ¶ added in v1.1.0
ProtectedCount is the number of protected resources with action a.
func (Summary) RiskCount ¶ added in v1.1.0
RiskCount is the number of changes with action a that still count as risk: the full count minus the changes a policy let out of the gate.
func (Summary) RiskIgnored ¶ added in v1.1.0
RiskIgnored counts the risky changes a policy let out of the gate.