planning

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MPL-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package planning implements a planning engine for OpenTofu, which takes a prior state and a configuration instance (which can be evaluated to produce a desired state) and proposes a set of changes to make to bring the remote system closer to convergence with the desired state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithTracer

func ContextWithTracer(parent context.Context, tracer *Tracer) context.Context

ContextWithTracer returns a new context derived from parent that carries a Tracer.

Use the resulting context when calling PlanChanges, to get event notification callbacks throughout the planning process.

func PlanChanges

func PlanChanges(ctx context.Context, opts *PlanOpts, prevRoundState *states.State, configInst *eval.ConfigInstance, providers plugins.Providers) (*plans.Plan, tfdiags.Diagnostics)

PlanChanges is the main entry point, taking a state snapshot from the end of the previous plan/apply round and an instantiated configuration (bound to some input variable definitions) and returning a plan containing a set of proposed actions.

Types

type PlanOpts

type PlanOpts struct {
	// Mode is the planning mode to use.
	//
	// Planning modes are mutually-exclusive and each represent significantly
	// different goals for the planning process. Whereas most other options
	// just change specific details of how we plan, a different planning mode
	// has a far more drastic, cross-cutting effect.
	Mode plans.Mode

	ForceReplace []addrs.AbsResourceInstance
}

PlanOpts represents our various "planning options" that can change various details about how we perform the planning phase, and therefore also what actions we might propose to perform during a subsequent applying phase.

type Tracer

type Tracer struct {

	// StartManagedResourceInstanceObjectPlanning and
	// EndManagedResourceInstanceObjectPlanning mark the beginning and end of
	// the overall planning work for the identified managed resource instance
	// object.
	//
	// These events cover the whole planning process for the given resource
	// instance object, including the state upgrade and refresh steps alongside
	// the actual call to ask the provider to determine if any changes are
	// needed. There are other more specific events below, which nest inside
	// this pair of events.
	StartManagedResourceInstanceObjectPlanning func(ctx context.Context, addr addrs.AbsResourceInstanceObject) context.Context
	EndManagedResourceInstanceObjectPlanning   func(ctx context.Context, addr addrs.AbsResourceInstanceObject, diags tfdiags.Diagnostics)

	// StartManagedResourceInstanceObjectUpgrade and
	// EndManagedResourceInstanceObjectUpgrade mark the beginning and end
	// of the "state upgrade" step for the identified managed resource instance
	// object.
	//
	// These events always occur between calls to
	// StartManagedResourceInstanceObjectPlanning and
	// EndManagedResourceInstanceObjectPlanning for the same object address.
	StartManagedResourceInstanceObjectUpgrade func(ctx context.Context, addr addrs.AbsResourceInstanceObject) context.Context
	EndManagedResourceInstanceObjectUpgrade   func(ctx context.Context, addr addrs.AbsResourceInstanceObject, upgradedVal cty.Value, diags tfdiags.Diagnostics)

	// StartManagedResourceInstanceObjectRefresh and
	// EndManagedResourceInstanceObjectRefresh mark the beginning and end
	// of the "refresh" step for the identified managed resource instance
	// object.
	//
	// These events always occur between calls to
	// StartManagedResourceInstanceObjectPlanning and
	// EndManagedResourceInstanceObjectPlanning for the same object address.
	StartManagedResourceInstanceObjectRefresh func(ctx context.Context, addr addrs.AbsResourceInstanceObject, prevRoundVal cty.Value) context.Context
	EndManagedResourceInstanceObjectRefresh   func(ctx context.Context, addr addrs.AbsResourceInstanceObject, prevRoundVal, refreshedVal cty.Value, diags tfdiags.Diagnostics)

	// StartManagedResourceInstanceObjectPlanChanges and
	// EndManagedResourceInstanceObjectPlanChanges mark the beginning and end
	// of the step where we actually ask the provider to plan changes for
	// the identified resource instance object.
	//
	// These events always occur between calls to
	// StartManagedResourceInstanceObjectPlanning and
	// EndManagedResourceInstanceObjectPlanning for the same object address,
	// which act as a container for the upgrade, refresh, and change-planning
	// sequence.
	StartManagedResourceInstanceObjectPlanChanges func(ctx context.Context, addr addrs.AbsResourceInstanceObject, priorVal, configVal cty.Value) context.Context
	EndManagedResourceInstanceObjectPlanChanges   func(ctx context.Context, addr addrs.AbsResourceInstanceObject, action plans.Action, priorVal, plannedVal cty.Value, diags tfdiags.Diagnostics)

	// StartDataResourceInstancePlanning and EndDataResourceInstancePlanning
	// mark the beginning and end of the overall planning work for the
	// identified data resource instance.
	//
	// These events cover the whole planning process for the given resource
	// instance. There are other more specific events below, which nest inside
	// this pair of events.
	StartDataResourceInstancePlanning func(ctx context.Context, addr addrs.AbsResourceInstance) context.Context
	EndDataResourceInstancePlanning   func(ctx context.Context, addr addrs.AbsResourceInstance, diags tfdiags.Diagnostics)

	// StartDataResourceInstanceRead and EndDataResourceInstanceRead mark the
	// beginning and end of the work to read data for the identified data
	// resource instance.
	//
	// These events occur only when the data resource instance is readable
	// during the planning phase. Some data resource instances get delayed until
	// the apply phase because there isn't enough information to read them
	// during the planning phase.
	//
	// These events always occur between calls to
	// StartDataResourceInstancePlanning and EndDataResourceInstancePlanning for
	// the same instance address.
	StartDataResourceInstanceRead func(ctx context.Context, addr addrs.AbsResourceInstance) context.Context
	EndDataResourceInstanceRead   func(ctx context.Context, addr addrs.AbsResourceInstance, resultVal cty.Value, diags tfdiags.Diagnostics)

	// We also embed [shared.Tracer] for some events that are common across
	// plan and apply. [PlanChanges] automatically ensures that this nested
	// tracer reaches the shared codepaths that rely on it.
	shared.Tracer
}

Tracer is a container for various callbacks used to report various events that can occur during a call to PlanChanges.

Pass a pointer to an object of this type to ContextWithTracer to get an annotated context.Context, and then pass it to PlanChanges.

Any fields left as nil will be ignored. Non-nil callbacks will be called whenever the associated event (mentioned in the field's documentation comment) occurs.

Some callback functions come in "Start" and "End" pairs that share a common suffix. In those cases, the Start function is expected to return a context is a child of the one passed to the callback function, possibly annotated with additional information such as OpenTelemetry trace metadata. The returned context is then used for all of the requests that occur between the Start and End calls, and finally the same context is passed to the corresponding End function so that e.g. an OpenTelemetry trace can be closed. Implementations that don't need to preserve additional context can just directly return the provided context without modification.

Jump to

Keyboard shortcuts

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