provider

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 New

func New(name, description, version string) (*Manager, error)

func (*Manager) Close

func (m *Manager) Close(ctx context.Context) error

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

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

func (m *Manager) Description() string

Description returns a human-readable summary of the provider.

func (*Manager) DestroyResourceInstance

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

ListResources returns metadata for every registered resource type (optionally filtered by type name) with their instances.

func (*Manager) Name

func (m *Manager) Name() string

Name returns the unique name for the provider

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

func (m *Manager) RegisterResource(r schema.Resource) error

RegisterResource registers a resource type with the provider. It returns an error if a resource with the same name is already registered.

func (*Manager) Resources

func (m *Manager) Resources() []schema.Resource

Resources returns the set of resources this provider can manage

func (*Manager) UpdateResourceInstance

UpdateResourceInstance validates and plans the named instance. When req.Apply is true the plan is also applied and the resulting state stored.

func (*Manager) Version

func (m *Manager) Version() string

Version returns the semver of the provider.

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

type ResourceInstance[C schema.Resource] struct {
	// contains filtered or unexported fields
}

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 (b *ResourceInstance[C]) ApplyConfig(ctx context.Context, v any, fn func(context.Context, *C) error) error

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

func (b *ResourceInstance[C]) Plan(ctx context.Context, v any) (schema.Plan, error)

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 (b *ResourceInstance[C]) PlanConfig(ctx context.Context, v any, fn func(context.Context, []schema.Change) error) (schema.Plan, error)

func (*ResourceInstance[C]) Read

func (b *ResourceInstance[C]) Read(_ context.Context) (schema.State, error)

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.

Jump to

Keyboard shortcuts

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