Documentation
¶
Overview ¶
Package resources contains helpers that encapsulate the main interactions Bogform 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 Bogform is asking each of these questions.
Index ¶
- type EncodedValue
- type ManagedResourceImportStateRequest
- type ManagedResourceMoveStateRequest
- type ManagedResourcePlanRequest
- type ManagedResourcePlanResponse
- type ManagedResourceStateWithIdentity
- type ManagedResourceType
- func (rt *ManagedResourceType) EncodeValue(ctx context.Context, value cty.Value, dispAddr addrs.AbsResourceInstanceObject) (*EncodedValue, tfdiags.Diagnostics)
- func (rt *ManagedResourceType) GenerateConfigFor(ctx context.Context, value cty.Value, ...) (string, tfdiags.Diagnostics)
- func (rt *ManagedResourceType) ImportState(ctx context.Context, req *ManagedResourceImportStateRequest, ...) (*ManagedResourceStateWithIdentity, tfdiags.Diagnostics)
- func (rt *ManagedResourceType) LoadSchema(ctx context.Context) (providers.Schema, tfdiags.Diagnostics)
- func (rt *ManagedResourceType) MoveState(ctx context.Context, req *ManagedResourceMoveStateRequest, ...) (*ValueWithPrivate, tfdiags.Diagnostics)
- func (rt *ManagedResourceType) NullValue(ctx context.Context) (cty.Value, tfdiags.Diagnostics)
- func (rt *ManagedResourceType) PlanChanges(ctx context.Context, req *ManagedResourcePlanRequest, ...) (*ManagedResourcePlanResponse, tfdiags.Diagnostics)
- func (rt *ManagedResourceType) RefreshState(ctx context.Context, req *ManagedResourceStateWithIdentity, ...) (*ManagedResourceStateWithIdentity, tfdiags.Diagnostics)
- func (rt *ManagedResourceType) ResourceMode() addrs.ResourceMode
- func (rt *ManagedResourceType) ResourceTypeName() string
- func (rt *ManagedResourceType) TestValueConformance(ctx context.Context, value cty.Value, dispAddr addrs.AbsResourceInstanceObject) tfdiags.Diagnostics
- func (rt *ManagedResourceType) UpgradeState(ctx context.Context, req *ManagedResourceUpgradeStateRequest, ...) (*ValueWithPrivate, tfdiags.Diagnostics)
- 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 ManagedResourceUpgradeStateRequest
- type ReplaceOrder
- type ResourceType
- type ValueWithPrivate
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EncodedValue ¶
type ManagedResourceImportStateRequest ¶
type ManagedResourceImportStateRequest struct {
Target providers.ImportTarget
}
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 ¶
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 Bogform-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 ¶
func (rt *ManagedResourceType) EncodeValue(ctx context.Context, value cty.Value, dispAddr addrs.AbsResourceInstanceObject) (*EncodedValue, tfdiags.Diagnostics)
func (*ManagedResourceType) GenerateConfigFor ¶
func (rt *ManagedResourceType) GenerateConfigFor(ctx context.Context, value cty.Value, providerInstance addrs.AbsProviderInstanceCorrect, dispAddr addrs.AbsResourceInstance) (string, tfdiags.Diagnostics)
func (*ManagedResourceType) ImportState ¶
func (rt *ManagedResourceType) ImportState(ctx context.Context, req *ManagedResourceImportStateRequest, dispAddr addrs.AbsResourceInstanceObject) (*ManagedResourceStateWithIdentity, tfdiags.Diagnostics)
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) MoveState ¶
func (rt *ManagedResourceType) MoveState(ctx context.Context, req *ManagedResourceMoveStateRequest, dispAddr addrs.AbsResourceInstanceObject) (*ValueWithPrivate, tfdiags.Diagnostics)
func (*ManagedResourceType) NullValue ¶
func (rt *ManagedResourceType) NullValue(ctx context.Context) (cty.Value, tfdiags.Diagnostics)
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) RefreshState ¶
func (rt *ManagedResourceType) RefreshState(ctx context.Context, req *ManagedResourceStateWithIdentity, dispAddr addrs.AbsResourceInstanceObject) (*ManagedResourceStateWithIdentity, tfdiags.Diagnostics)
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 ¶
func (rt *ManagedResourceType) TestValueConformance(ctx context.Context, value cty.Value, dispAddr addrs.AbsResourceInstanceObject) tfdiags.Diagnostics
func (*ManagedResourceType) UpgradeState ¶
func (rt *ManagedResourceType) UpgradeState(ctx context.Context, req *ManagedResourceUpgradeStateRequest, dispAddr addrs.AbsResourceInstanceObject) (*ValueWithPrivate, tfdiags.Diagnostics)
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 ReplaceOrder ¶
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 ¶
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 ¶
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.