applying

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MPL-2.0 Imports: 28 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyPlannedChanges

func ApplyPlannedChanges(ctx context.Context, plan *plans.Plan, configInst *eval.ConfigInstance, plugins plugins.Plugins, persistState PersistState, opts *ApplyOpts) (*states.State, tfdiags.Diagnostics)

ApplyPlannedChanges is a temporary placeholder entrypoint for a new approach to applying based on an execution graph generated during the planning phase.

The signature here is a little confusing because we're currently reusing our old-style plan and state models, even though their shape isn't quite right for what we need here. A future version of this function will hopefully have a signature more tailored to the needs of the new apply engine, once we have a stronger understanding of what those needs are.

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 ApplyPlannedChanges, to get event notification callbacks throughout the planning process.

Types

type ApplyOpts added in v0.34.0

type ApplyOpts struct {
	// ConfigValueAdjuster is the ownership-marker seam (#2256 U4): the
	// adjuster [ManagedFinalPlan] applies to the desired configuration value
	// so that the final plan matches the initial one, which the planning
	// engine made from the adjusted value. It is the same value internal/tofu
	// holds as its Context's ConfigValueAdjuster, so the apply-time optional
	// capabilities (AppliedMarkerWriter, AppliedMarkerVerifier) can be found
	// on it with a type assertion.
	ConfigValueAdjuster configadjust.ConfigValueAdjuster

	// InstanceStateUpdate, when set, is called once for each managed
	// resource instance object the engine applies (#2256 U5, #2341). It is
	// internal/tofu's InstanceStateHook (GitHub issue #1944) on this runtime,
	// which a live run uses to write each instance's record as it returns.
	// See [InstanceStateUpdate] and ManagedApply in fork_apply_markers.go
	// for when it runs and what it is given. An error fails that instance's
	// apply step.
	InstanceStateUpdate InstanceStateUpdate

	// InRunEstates is choudoufu fork port (#2370): remove when upstream
	// #4058 lands. Nil is off. See package inrunestates.
	InRunEstates *inrunestates.Port

	// Stopped is choudoufu fork port (#2381): remove when the row closes.
	// Nil is off. See package cancel's Between and fork_cancel.go.
	Stopped func() bool

	// Forget is choudoufu fork port (#2409): remove when upstream #4682
	// lands. Nil is off. See package forget and fork_forget.go.
	Forget *forget.Port
}

ApplyOpts are choudoufu's options for ApplyPlannedChanges. nil means none are set.

type InstanceStateUpdate added in v0.34.0

type InstanceStateUpdate func(addr addrs.AbsResourceInstance, inst *states.ResourceInstance, provider *addrs.AbsProviderConfig) error

InstanceStateUpdate is the type of ApplyOpts.InstanceStateUpdate. It is called once for each managed resource instance object the engine applies, after the tracer has reported the apply finished (the Hook API's PostApply), with the instance's state as the apply left it: a copy of its current and deposed objects (nil when the instance is gone) and its resource's provider configuration (nil when the resource is gone).

type PersistState added in v0.34.0

type PersistState func(*states.State) error

type PersistingState added in v0.34.0

type PersistingState struct {
	// contains filtered or unexported fields
}

PersistingState is a wrapper around SyncState that persists the working copy to whatever persistence callback is defined.

Critically, this assumes that the persist callback does not modify the state while the apply engine is running. In the current shims to the local backend, the callback overwrites the StateManager's current state and calls Persist. Nothing else during the apply process reads or modifies the state through the state manager, which means that this approach is safe.

This additional complexity and potential fragility here is in service of preventing as many state.DeepCopy() calls as possible. If we did not share the lock between state sync and persisting below, persist would need to perform it's own deep copy of the state as modifications here proceed.

A potentially better approach would be to share the StateManager from the local backend with this implementation, but that would blur some of the intentional separation of concerns. Ideally, this all goes away once we start work on granular state storage. That will necessitate re-engineering all of these abstractions anyways, and is not worth over-complicating at this point in time.

func NewPersistingState added in v0.34.0

func NewPersistingState(working *states.State, persist PersistState) *PersistingState

func (*PersistingState) Close added in v0.34.0

func (s *PersistingState) Close() *states.State

func (*PersistingState) DeposeResourceInstanceObjectForceKey added in v0.34.0

func (s *PersistingState) DeposeResourceInstanceObjectForceKey(addr addrs.AbsResourceInstance, forcedKey states.DeposedKey) error

func (*PersistingState) MaybeMoveResourceInstance added in v0.34.0

func (s *PersistingState) MaybeMoveResourceInstance(src, dst addrs.AbsResourceInstance) (bool, error)

func (*PersistingState) MaybeRestoreResourceInstanceDeposed added in v0.34.0

func (s *PersistingState) MaybeRestoreResourceInstanceDeposed(addr addrs.AbsResourceInstance, key states.DeposedKey) (bool, error)

func (*PersistingState) RemoveResourceInstanceObjectFull added in v0.34.0

func (s *PersistingState) RemoveResourceInstanceObjectFull(addr addrs.AbsResourceInstanceObject, providerInstAddr addrs.AbsProviderInstanceCorrect) error

func (*PersistingState) SetResourceInstanceObjectFull added in v0.34.0

func (s *PersistingState) SetResourceInstanceObjectFull(addr addrs.AbsResourceInstanceObject, obj *states.ResourceInstanceObjectFullSrc) error

type Tracer

type Tracer struct {

	// StartManagedResourceInstanceObjectFinalPlan and
	// EndManagedResourceInstanceObjectFinalPlan mark the beginning and end of
	// the work to produce the final plan for the identified managed resource
	// instance object.
	StartManagedResourceInstanceObjectFinalPlan func(ctx context.Context, addr addrs.AbsResourceInstanceObject, priorVal, configVal, expectedVal cty.Value) context.Context
	EndManagedResourceInstanceObjectFinalPlan   func(ctx context.Context, addr addrs.AbsResourceInstanceObject, priorVal, plannedVal cty.Value, diags tfdiags.Diagnostics)

	// StartManagedResourceInstanceObjectApply and
	// EndManagedResourceInstanceObjectApply mark the beginning and end of
	// the work to apply the final plan for the identified managed resource
	// instance object.
	StartManagedResourceInstanceObjectApply func(ctx context.Context, addr addrs.AbsResourceInstanceObject, priorVal, plannedVal cty.Value) context.Context
	EndManagedResourceInstanceObjectApply   func(ctx context.Context, addr addrs.AbsResourceInstanceObject, resultVal cty.Value, diags tfdiags.Diagnostics)

	// StartManagedResourceInstanceObjectForget and
	// EndManagedResourceInstanceObjectForget mark the beginning and end of
	// the work to "forget" the identified managed resource/ instance object.
	StartManagedResourceInstanceObjectForget func(ctx context.Context, addr addrs.AbsResourceInstanceObject, priorVal cty.Value) context.Context
	EndManagedResourceInstanceObjectForget   func(ctx context.Context, addr addrs.AbsResourceInstanceObject, diags tfdiags.Diagnostics)

	// Provisioner Hooks for Managed Resources
	StartProvisionInstanceStep func(ctx context.Context, addr addrs.AbsResourceInstance, typeName string) context.Context
	ProvisionOutput            func(ctx context.Context, addr addrs.AbsResourceInstance, typeName string, line string, configMarks cty.ValueMarks)
	StopProvisionInstanceStep  func(ctx context.Context, addr addrs.AbsResourceInstance, typeName string, 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 read was delayed
	// due to there not being enough information to read it during the planning
	// phase.
	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. [ApplyPlannedChanges] automatically ensures that this
	// nested tracer reaches the shared codepaths that rely on it.
	shared.Tracer

	PersistState func(*states.SyncState) error
}

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

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

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