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 ¶
- type ManagedResourcePlanRequest
- type ManagedResourcePlanResponse
- type ManagedResourceType
- func (rt *ManagedResourceType) LoadSchema(ctx context.Context) (providers.Schema, tfdiags.Diagnostics)
- func (rt *ManagedResourceType) PlanChanges(ctx context.Context, req *ManagedResourcePlanRequest, ...) (*ManagedResourcePlanResponse, tfdiags.Diagnostics)
- func (rt *ManagedResourceType) ResourceMode() addrs.ResourceMode
- func (rt *ManagedResourceType) ResourceTypeName() string
- func (rt *ManagedResourceType) ValidateConfig(ctx context.Context, configVal cty.Value) tfdiags.Diagnostics
- func (rt *ManagedResourceType) ValidateFinalPlan(ctx context.Context, initialPlannedValue, finalPlannedValue cty.Value, ...) tfdiags.Diagnostics
- type ResourceType
- type ValueWithPrivate
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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
// ProviderMetaValue is an optional value declared in the same module
// where the associated resource was declared, which should be sent
// to the provider as part of any planning request.
//
// This is a rarely-used feature that only really makes sense when a
// module is written by the same entity that owns a provider it uses,
// in which case the module author might want to use the provider as
// a covert channel for collecting usage statistics about the module.
//
// When no metadata was provided for this provider in the current module,
// this should be set to the zero value of [cty.Value], which is
// [cty.NilVal].
ProviderMetaValue 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 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) LoadSchema ¶
func (rt *ManagedResourceType) LoadSchema(ctx context.Context) (providers.Schema, tfdiags.Diagnostics)
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) PlanChanges ¶
func (rt *ManagedResourceType) PlanChanges(ctx context.Context, req *ManagedResourcePlanRequest, dispAddr addrs.AbsResourceInstanceObject) (*ManagedResourcePlanResponse, tfdiags.Diagnostics)
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) ResourceMode ¶
func (rt *ManagedResourceType) ResourceMode() addrs.ResourceMode
ResourceMode implements ResourceType.
func (*ManagedResourceType) ResourceTypeName ¶
func (rt *ManagedResourceType) ResourceTypeName() string
ResourceTypeName implements ResourceType.
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 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 ¶
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.