Documentation
¶
Index ¶
- Variables
- type Manager
- func (m *Manager) Close(ctx context.Context) error
- func (m *Manager) CreateResourceInstance(ctx context.Context, req schema.CreateResourceInstanceRequest) (*schema.CreateResourceInstanceResponse, error)
- func (m *Manager) Description() string
- func (m *Manager) DestroyResourceInstance(ctx context.Context, req schema.DestroyResourceInstanceRequest) (*schema.DestroyResourceInstanceResponse, error)
- func (m *Manager) GetResourceInstance(ctx context.Context, name string) (*schema.GetResourceInstanceResponse, error)
- func (m *Manager) ListResources(ctx context.Context, req schema.ListResourcesRequest) (*schema.ListResourcesResponse, error)
- func (m *Manager) Name() string
- func (m *Manager) New(resource, label string) (schema.ResourceInstance, error)
- func (m *Manager) RegisterReadonlyInstance(ctx context.Context, resource schema.Resource, label string, ...) (schema.ResourceInstance, error)
- func (m *Manager) RegisterResource(r schema.Resource) error
- func (m *Manager) Resources() []schema.Resource
- func (m *Manager) UpdateResourceInstance(ctx context.Context, name string, req schema.UpdateResourceInstanceRequest) (*schema.UpdateResourceInstanceResponse, error)
- func (m *Manager) Version() string
- type Observable
- type ObserverFunc
- type ResourceInstance
- func (b *ResourceInstance[C]) AddObserver(id string, fn ObserverFunc)
- func (b *ResourceInstance[C]) Apply(ctx context.Context, v any) error
- func (b *ResourceInstance[C]) ApplyConfig(ctx context.Context, v any, fn func(context.Context, *C) error) error
- func (b *ResourceInstance[C]) Destroy(_ context.Context) error
- func (b *ResourceInstance[C]) Name() string
- func (b *ResourceInstance[C]) Plan(ctx context.Context, v any) (schema.Plan, error)
- func (b *ResourceInstance[C]) PlanConfig(ctx context.Context, v any, fn func(context.Context, []schema.Change) error) (schema.Plan, error)
- func (b *ResourceInstance[C]) Read(_ context.Context) (schema.State, error)
- func (b *ResourceInstance[C]) References() []string
- func (b *ResourceInstance[C]) RemoveObserver(id string)
- func (b *ResourceInstance[C]) Resource() schema.Resource
- func (b *ResourceInstance[C]) SetState(c *C, source schema.ResourceInstance)
- func (b *ResourceInstance[C]) State() *C
- func (b *ResourceInstance[C]) Validate(_ context.Context, state schema.State, resolve schema.Resolver) (any, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrBadRequest = httpresponse.ErrBadRequest ErrNotFound = httpresponse.ErrNotFound ErrConflict = httpresponse.ErrConflict )
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
sync.RWMutex // Guard for instances
// contains filtered or unexported fields
}
func (*Manager) Close ¶
Close destroys all instances and removes them from the manager, respecting dependency order (dependents are destroyed before their dependencies). It returns all errors encountered but continues destroying remaining instances.
func (*Manager) CreateResourceInstance ¶
func (m *Manager) CreateResourceInstance(ctx context.Context, req schema.CreateResourceInstanceRequest) (*schema.CreateResourceInstanceResponse, error)
CreateResourceInstance creates a new instance from the named resource type and stores it in the manager. The instance is not yet validated or applied; call [UpdateResourceInstance] to plan or apply it.
func (*Manager) Description ¶
Description returns a human-readable summary of the provider.
func (*Manager) DestroyResourceInstance ¶
func (m *Manager) DestroyResourceInstance(ctx context.Context, req schema.DestroyResourceInstanceRequest) (*schema.DestroyResourceInstanceResponse, error)
DestroyResourceInstance tears down the named instance and removes it from the manager. When req.Cascade is true, all instances that (transitively) depend on the target are destroyed first, in topological order.
func (*Manager) GetResourceInstance ¶
func (m *Manager) GetResourceInstance(ctx context.Context, name string) (*schema.GetResourceInstanceResponse, error)
GetResourceInstance returns the metadata for a single named instance.
func (*Manager) ListResources ¶
func (m *Manager) ListResources(ctx context.Context, req schema.ListResourcesRequest) (*schema.ListResourcesResponse, error)
ListResources returns metadata for every registered resource type (optionally filtered by type name) with their instances.
func (*Manager) New ¶
func (m *Manager) New(resource, label string) (schema.ResourceInstance, error)
New creates a resource instance from the given resource type with the specified label. The instance name will be "resource.label". The returned resource is not yet applied; call ResourceInstance.Apply to materialise it.
func (*Manager) RegisterReadonlyInstance ¶
func (m *Manager) RegisterReadonlyInstance(ctx context.Context, resource schema.Resource, label string, state schema.State) (schema.ResourceInstance, error)
RegisterReadonlyInstance creates a new instance of the given resource type with a deterministic label, validates and applies the given state, and stores the result as a read-only (data) instance. The instance name is "{resource}.{label}". If the resource type is not yet registered it is registered automatically. It returns the created schema.ResourceInstance so the caller can type-assert to the concrete object (e.g. *httpserver.Server).
func (*Manager) RegisterResource ¶
RegisterResource registers a resource type with the provider. It returns an error if a resource with the same name is already registered.
func (*Manager) UpdateResourceInstance ¶
func (m *Manager) UpdateResourceInstance(ctx context.Context, name string, req schema.UpdateResourceInstanceRequest) (*schema.UpdateResourceInstanceResponse, error)
UpdateResourceInstance validates and plans the named instance. When req.Apply is true the plan is also applied and the resulting state stored.
type Observable ¶
type Observable interface {
AddObserver(id string, fn ObserverFunc)
RemoveObserver(id string)
}
Observable is optionally satisfied by resource instances that support state-change observer registration. All types that embed ResourceInstance automatically implement this interface.
type ObserverFunc ¶
type ObserverFunc func(source schema.ResourceInstance)
ObserverFunc is called when the instance's state changes. The source parameter is the concrete schema.ResourceInstance whose state was updated.
type ResourceInstance ¶
ResourceInstance provides common scaffolding for schema.ResourceInstance implementations. The type parameter C is the concrete configuration struct that implements schema.Resource.
Embedding ResourceInstance[C] in a concrete type automatically satisfies the [Name], [Resource], [Plan], and [References] methods of the schema.ResourceInstance interface. Concrete types must still implement [Validate], [Apply], and [Destroy].
func NewResourceInstance ¶
func NewResourceInstance[C schema.Resource](resource C, name string) ResourceInstance[C]
NewResourceInstance returns a ResourceInstance for the given resource type with the supplied name.
func (*ResourceInstance[C]) AddObserver ¶
func (b *ResourceInstance[C]) AddObserver(id string, fn ObserverFunc)
AddObserver registers a callback that will be invoked when this instance's state changes via [SetState]. The id is typically the name of the observing instance; calling AddObserver with an existing id replaces the previous callback.
func (*ResourceInstance[C]) Apply ¶
func (b *ResourceInstance[C]) Apply(ctx context.Context, v any) error
Apply satisfies schema.ResourceInstance. It applies the desired configuration v (which must be *C) to the instance, stores the state, and returns any error.
func (*ResourceInstance[C]) ApplyConfig ¶
func (*ResourceInstance[C]) Destroy ¶
func (b *ResourceInstance[C]) Destroy(_ context.Context) error
Destroy satisfies schema.ResourceInstance. The default implementation is a no-op; concrete types may override it to release resources.
func (*ResourceInstance[C]) Name ¶
func (b *ResourceInstance[C]) Name() string
Name satisfies schema.ResourceInstance.
func (*ResourceInstance[C]) Plan ¶
Plan satisfies schema.ResourceInstance. It computes the diff between the validated configuration v (which must be *C) and the instance's current applied state.
func (*ResourceInstance[C]) PlanConfig ¶
func (*ResourceInstance[C]) Read ¶
Read satisfies schema.ResourceInstance. It returns the live state of the instance by reflecting over the current applied configuration. Concrete types may override this to include computed fields.
func (*ResourceInstance[C]) References ¶
func (b *ResourceInstance[C]) References() []string
References satisfies schema.ResourceInstance. It returns the labels of other resources this instance depends on.
func (*ResourceInstance[C]) RemoveObserver ¶
func (b *ResourceInstance[C]) RemoveObserver(id string)
RemoveObserver unregisters the observer with the given id.
func (*ResourceInstance[C]) Resource ¶
func (b *ResourceInstance[C]) Resource() schema.Resource
Resource satisfies schema.ResourceInstance. It returns the resource type that created this instance.
func (*ResourceInstance[C]) SetState ¶
func (b *ResourceInstance[C]) SetState(c *C, source schema.ResourceInstance)
SetState stores the applied configuration and notifies all registered observers. The source parameter should be the outermost schema.ResourceInstance (typically the concrete type that embeds ResourceInstance). Call this at the end of a successful [Apply].
func (*ResourceInstance[C]) State ¶
func (b *ResourceInstance[C]) State() *C
State returns the last-applied configuration, or nil if the resource has not yet been applied.
func (*ResourceInstance[C]) Validate ¶
func (b *ResourceInstance[C]) Validate(_ context.Context, state schema.State, resolve schema.Resolver) (any, error)
Validate decodes incoming schema.State into a *C, resolves references via resolve, and checks required/type constraints. Concrete Validate methods should call this first, then add resource-specific checks.
Directories
¶
| Path | Synopsis |
|---|---|
|
schematest
Package schematest provides shared mock implementations of schema.Resource and schema.ResourceInstance for use in tests.
|
Package schematest provides shared mock implementations of schema.Resource and schema.ResourceInstance for use in tests. |