resources

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MPL-2.0 Imports: 19 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 resources contains helpers that encapsulate the main interactions OpenTofu has with resource instance objects, wrapping the raw provider client calls with certain preprocessing, postprocessing, and validation logic that ought to happen regardless of why OpenTofu is asking each of these questions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataResourceReadRequest added in v0.34.0

type DataResourceReadRequest struct {
	// ResourceAddress is used mostly for diagnostics
	ResourceAddress addrs.AbsResourceInstance

	// ConfigValue is a value representing the configuration for the
	// resource instance, which is typically the result of evaluating the
	// arguments in a block in the configuration.
	ConfigValue cty.Value
}

DataResourceReadRequest is the request type for DataResourceType.Read.

type DataResourceReadResponse added in v0.34.0

type DataResourceReadResponse struct {

	// Result represents the value returned by the provider, or a placeholder
	// result if DelayUntilApply is set. Marks are applied before setting this result.
	Result cty.Value

	// ResultUnmarked represents the raw value returned by the provider, or a placeholder
	// result if DelayUntilApply is set.
	ResultUnmarked cty.Value

	// SensitivePaths is an array of paths to mark as sensitive when decoding.
	SensitivePaths []cty.Path

	// Status represents the "readiness" of the object as of the last time it was updated.
	Status states.ObjectStatus
}

DataResourceReadResponse is the response type for DataResourceType.Read.

type DataResourceType added in v0.34.0

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

DataResourceType represents a named resource type in a specific provider, and also carries a client for interacting with that provider.

Most methods of this type relate to data-resource-related operations in the underlying provider protocol, but also include additional OpenTofu-level logic such as verifying that the provider is correctly implementing the protocol's constraints.

func NewDataResourceType added in v0.34.0

func NewDataResourceType(providerAddr addrs.Provider, typeName string, client providers.Interface) *DataResourceType

NewDataResourceType constructs a new DataResourceType for the given resource type name in the provider whose client is provided.

It's the caller's responsibility to make sure that the given client is actually for the provider indicated.

func (*DataResourceType) EncodeValue added in v0.34.0

func (dt *DataResourceType) EncodeValue(ctx context.Context, value cty.Value, dispAddr addrs.AbsResourceInstanceObject) (encodedVal *EncodedValue, diags tfdiags.Diagnostics)

func (*DataResourceType) LoadSchema added in v0.34.0

LoadSchema implements ResourceType.

func (*DataResourceType) Read added in v0.34.0

Read encapsulates the logic for reading data for a data resource instance.

The caller must ensure that all of the provided values conform to the schema of the named resource type in the given provider, or the results are unspecified. DataResourceType.LoadSchema returns the expected schema.

The dispAddr argument is used only to name the corresponding resource instance object when generating diagnostics. If no diagnostics are returned then that argument is completely ignored. Some of the returned diagnostics can be config-contextual diagnostics expecting to be elaborated by calling tfdiags.Diagnostics.InConfigBody with the configuration body that the desired value was built from, if any.

If the returned diagnostics contains errors then the response object might either be nil or be a partial description of the invalid plan, depending on the nature of the failure. Callers should use defensive programming techniques if interacting with a partial response associated with an error.

func (*DataResourceType) ResourceMode added in v0.34.0

func (dt *DataResourceType) ResourceMode() addrs.ResourceMode

ResourceMode implements ResourceType.

func (*DataResourceType) ResourceTypeName added in v0.34.0

func (dt *DataResourceType) ResourceTypeName() string

ResourceTypeName implements ResourceType.

func (*DataResourceType) UnknownValue added in v0.34.0

func (dt *DataResourceType) UnknownValue(ctx context.Context, unmarkedConfigVal cty.Value) (unknownVal cty.Value, diags tfdiags.Diagnostics)

func (*DataResourceType) ValidateConfig added in v0.34.0

func (dt *DataResourceType) ValidateConfig(ctx context.Context, configVal cty.Value) tfdiags.Diagnostics

ValidateConfig asks the provider whether the given value is valid.

The given value should already conform to the schema of the resource type.

type EncodedValue added in v0.34.0

type EncodedValue struct {
	SchemaVersion uint64
	ValueJSON     []byte
}

type ManagedResourceImportStateRequest added in v0.34.0

type ManagedResourceImportStateRequest struct {
	Target providers.ImportTarget
}

type ManagedResourceMoveStateRequest added in v0.34.0

type ManagedResourceMoveStateRequest struct {
	Provider      addrs.Provider
	ResourceType  string
	SchemaVersion uint64
	ValueJSON     []byte
	Private       []byte
}

type ManagedResourcePlanRequest

type ManagedResourcePlanRequest struct {
	// Current is a value representing the current state of the object, bundled
	// with an arbitrary byte array that was associated with that value by
	// the provider that previously generated it.
	//
	// Providers sometimes use the "private" blob to track additional metadata
	// that is not exposed as part of the value but is still needed to track
	// the object between plan/apply rounds.
	//
	// This field is typically set to the result of "refreshing" the object
	// that was saved at the end of the previous apply phase, in which case
	// the Private field must also match the blob returned from that refresh
	// operation.
	//
	// When planning to create a new object, this should be set to the zero
	// value of [ValueWithPrivate].
	Current ValueWithPrivate

	// DesiredValue is a value representing the desired state for the
	// object, which is typically the result of evaluating the arguments
	// in a block in the configuration.
	//
	// There is no "private" counterpart to this one because it is evaluated
	// fresh from the configuration each time, rather than being generated
	// by a provider.
	//
	// This field is typically set to a value obtained by evaluating a resource
	// block in the configuration. When planning to destroy an existing object,
	// this should be set to the zero value of [cty.Value], which is
	// [cty.NilVal].
	DesiredValue cty.Value

	IgnoreChangesPaths []cty.Path
}

ManagedResourcePlanRequest is the request type for ManagedResourceType.PlanChanges.

type ManagedResourcePlanResponse

type ManagedResourcePlanResponse struct {

	// Current echoes back the value given in the corresponding request field,
	// possibly with some normalization such as transforming an absent value
	// into null.
	Current ValueWithPrivate

	// DesiredValue echoes back the value  given in the corresponding request
	// field, possibly with some normalization such as transforming an absent
	// value into null.
	DesiredValue cty.Value

	// Planned has a prediction for what value will be associated with
	// this resource instance object after applying the planned change, along
	// with an optional opaque byte array that must be sent back to the
	// provider verbatim if this planned change is applied.
	//
	// The value typically includes unknown values as placeholders for specific
	// values that the provider cannot predict, such as opaque unique
	// identifiers selected by the remote system only once an object has
	// been created.
	//
	// Any part of the value that is not unknown is required to be identical
	// in the final object returned after applying the planned change, and so
	// it's reasonable to use this value when evaluating downstream expressions
	// that refer to a symbol representing this resource instance object.
	//
	// If the plan is to destroy the object, this is set to the zero value of
	// [ValueWithPrivate]. Otherwise, the caller must compare the value with
	// the request's "Current" value to determine whether any changes are
	// actually needed, taking no action at all if this value equals the
	// current value.
	Planned ValueWithPrivate

	// RequiresReplace describes paths within the planned value whose changes
	// require this change to be handled as a "replace" rather than as an
	// in-place update.
	//
	// If this collection is not empty then this change must be applied across
	// two separate [ApplyManagedResourceChange] calls, where one destroys the
	// prior object and the other creates a new object using the value from the
	// Planned field.
	//
	// If this collection is zero-length then this change should instead be
	// applied with only a single call to [ApplyManagedResourceChange].
	RequiresReplace cty.PathSet
}

ManagedResourcePlanResponse is the response type for ManagedResourceType.PlanChanges.

type ManagedResourceStateWithIdentity added in v0.34.0

type ManagedResourceStateWithIdentity struct {
	ValueWithPrivate
	Identity cty.Value
}

type ManagedResourceType

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

ManagedResourceType represents a named resource type in a specific provider, and also carries a client for interacting with that provider.

Most methods of this type relate to managed-resource-related operations in the underlying provider protocol, but also include additional OpenTofu-level logic such as verifying that the provider is correctly implementing the protocol's constraints on how objects are allowed to change.

func NewManagedResourceType

func NewManagedResourceType(providerAddr addrs.Provider, typeName string, client providers.Interface) *ManagedResourceType

NewManagedResourceType constructs a new ManagedResourceType for the given resource type name in the provider whose client is provided.

It's the caller's responsibility to make sure that the given client is actually for the provider indicated.

func (*ManagedResourceType) EncodeValue added in v0.34.0

func (*ManagedResourceType) GenerateConfigFor added in v0.34.0

func (rt *ManagedResourceType) GenerateConfigFor(ctx context.Context, value cty.Value, providerInstance addrs.AbsProviderInstanceCorrect, dispAddr addrs.AbsResourceInstance) (string, tfdiags.Diagnostics)

func (*ManagedResourceType) LoadSchema

LoadSchema loads the schema for this resource type from its provider.

This method performs no direct caching of the result, so the underlying provider client (originally passed to NewManagedResourceType) should provide its own caching.

func (*ManagedResourceType) MoveState added in v0.34.0

func (*ManagedResourceType) NullValue added in v0.34.0

func (*ManagedResourceType) PlanChanges

PlanChanges encapsulates the logic for deciding what changes, if any, to make to a managed resource instance object by comparing its current and desired states.

The caller must ensure that all of the provided values conform to the schema of the named resource type in the given provider, or the results are unspecified. ManagedResourceType.LoadSchema returns the expected schema.

The dispAddr argument is used only to name the corresponding resource instance object when generating diagnostics. If no diagnostics are returned then that argument is completely ignored. Some of the returned diagnostics can be config-contextual diagnostics expecting to be elaborated by calling tfdiags.Diagnostics.InConfigBody with the configuration body that the desired value was built from, if any.

If the returned diagnostics contains errors then the response object might either be nil or be a partial description of the invalid plan, depending on the nature of the failure. Callers should use defensive programming techniques if interacting with a partial response associated with an error.

func (*ManagedResourceType) RefreshState added in v0.34.0

func (*ManagedResourceType) ResourceMode

func (rt *ManagedResourceType) ResourceMode() addrs.ResourceMode

ResourceMode implements ResourceType.

func (*ManagedResourceType) ResourceTypeName

func (rt *ManagedResourceType) ResourceTypeName() string

ResourceTypeName implements ResourceType.

func (*ManagedResourceType) TestValueConformance added in v0.34.0

func (rt *ManagedResourceType) TestValueConformance(ctx context.Context, value cty.Value, dispAddr addrs.AbsResourceInstanceObject) tfdiags.Diagnostics

func (*ManagedResourceType) UpgradeState added in v0.34.0

func (*ManagedResourceType) ValidateConfig

func (rt *ManagedResourceType) ValidateConfig(ctx context.Context, configVal cty.Value) tfdiags.Diagnostics

ValidateConfig asks the provider whether the given value is valid.

The given value should already conform to the schema of the resource type.

func (*ManagedResourceType) ValidateFinalPlan

func (rt *ManagedResourceType) ValidateFinalPlan(ctx context.Context, initialPlannedValue, finalPlannedValue cty.Value, dispAddr addrs.AbsResourceInstanceObject) tfdiags.Diagnostics

ValidateFinalPlan compares two planned values returned by calls to ManagedResourceType.PlanChanges -- typically comparing the initial plan found during the planning phase with the final plan decided during the apply phase -- and returns diagnostics if the two differ in any way that is not allowed by the resource instance object lifecycle rules.

dispAddr is used only as part of any returned diagnostic messages, to explain which object had an invalid final plan.

type ManagedResourceUpgradeStateRequest added in v0.34.0

type ManagedResourceUpgradeStateRequest struct {
	SchemaVersion uint64
	ValueJSON     []byte
	Private       []byte
}

type ReplaceOrder added in v0.34.0

type ReplaceOrder byte

ReplaceOrder represents potential restrictions on which order the "create" and "delete" actions must be taken when replacing a managed resource instance object.

const (
	// ReplaceAnyOrder means that there is no constraint on which order the
	// "create" and "delete" operations must happen in, and so the order can
	// be selected to suit the constraints of other resource instace objects
	// in a dependency chain.
	//
	// This particular [ReplaceOrder] value is valid only early in the planning
	// phase when each resource instance object is reporting just its own
	// requirements. Part of the work of the planning phase is to decide on a
	// specific order to use for each resource instance object, and so after
	// that step this value is no longer suitable.
	ReplaceAnyOrder ReplaceOrder = iota

	// ReplaceCreateFirst means that a new object must be created before the
	// previous object is deleted.
	//
	// This implies that temporarily there are two objects, with the previous
	// object considered to be "deposed" during the overlap. This isn't possible
	// for all resource instances due to uniqueness constraints in the remote
	// system.
	ReplaceCreateFirst

	// ReplaceDeleteFirst means that the previous object must be deleted before
	// the new object is created.
	//
	// This implies that there will temporarily be no objects at all, but this
	// is sometimes necessary because of uniqueness constraints in the remote
	// system.
	ReplaceDeleteFirst
)

func (ReplaceOrder) String added in v0.34.0

func (i ReplaceOrder) String() string

type ResourceType

type ResourceType interface {
	ResourceMode() addrs.ResourceMode
	ResourceTypeName() string
	LoadSchema(ctx context.Context) (providers.Schema, tfdiags.Diagnostics)
}

ResourceType represents a resource type belonging to a specific provider client.

This interface represents the general operations that are relevant to all resource types regardless of mode, but most callers will want to use a specific implementation of this interface, such as ManagedResourceType.

type ValueWithPrivate

type ValueWithPrivate struct {
	Value   cty.Value
	Private []byte
}

ValueWithPrivate is a cty.Value associated with an arbitrary "private" byte array that is somehow related to it.

Refer to the documentation of any field or argument using this type to learn how the value and the byte array are related. Typically this is used to allow a provider to transfer some additional out-of-band information alongside a value that it will use when the same value is resubmitted to the same provider later.

Jump to

Keyboard shortcuts

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