plan

package
v0.44.1 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package plan parses a Terraform plan JSON document into a RawStack: reduced action counts plus the set of affected attributes for each change action.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RawAttr

type RawAttr struct {
	Name            string
	Before          any
	After           any
	Sensitive       bool // the WHOLE attribute is sensitive (marker is a bare `true`)
	Unknown         bool // known after apply
	BeforeSensitive any  // carry Terraform's per-path sensitivity tree
	AfterSensitive  any  // for this attribute when it is a nested map/list (not a bare bool)
	SensitivityOnly bool
}

RawAttr is one changed attribute, pre-rendering.

type RawChange

type RawChange struct {
	Address         string
	Type            string
	Actions         []string // raw tf actions, e.g. ["update"] or ["delete","create"]
	Action          model.Action
	Attrs           []RawAttr // populated for create/delete/update/replace/forget
	SensitivityOnly bool

	Name          string
	ModuleAddress string
	ProviderName  string

	// Raw holds top-level scalar attributes (string/number/bool), after over
	// before, sensitive values skipped. Retained for classification attribute
	// extraction, which must see attributes even when they did not change.
	Raw map[string]any

	Moved           bool
	MoveDirection   string
	PreviousAddress string
	Imported        bool
	ImportID        string
}

RawChange is one resource change with its raw Terraform actions retained (classify needs them) alongside the reduced bucket.

type RawStack

type RawStack struct {
	Name    string
	Counts  model.Counts
	Changes []RawChange
}

RawStack is a parsed plan for one stack (no-ops excluded).

func Parse

func Parse(name string, data []byte) (RawStack, error)

Parse reads a `terraform show -json` plan document.

func (*RawStack) ApplyStateMoves added in v0.5.9

func (rs *RawStack) ApplyStateMoves(targets moveset.Set) int

ApplyStateMoves reclassifies every change whose address is a pending cross-state move-target (from the --state-moves manifest) as a MOVE rather than the create/update/destroy terraform plans it as. A cross-state move lands the resource in a fresh destination state, so terraform shows it as a create (dest) or destroy (source) with no PreviousAddress; --state-moves is the out-of-band knowledge that it is really a relocation. After this overlay such a change is indistinguishable from an in-stack `moved`: its mutating count is removed (it makes no apply-time provider write), Counts.Move is incremented, Action becomes Noop (so classification skips it — no IAM gate) and Moved is set (so it renders with the move glyph, not a create). Returns the number of changes reclassified so the caller can surface a non-gating "move" category.

An empty target set is a no-op (the fail-safe when --state-moves is absent).

Note on the Moved guard: a resource in the SOURCE stack can appear with Moved=true when a same-plan `moved {}` block renames it (e.g. module.agent → module.agent[0]) while simultaneously count=0 destroys the new address. In that case Action is ActionDestroy, not ActionNoop, so we must still reclassify it. We only skip when Action is already ActionNoop — meaning it's a pure same-stack rename with no real provider write.

Jump to

Keyboard shortcuts

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