Documentation
¶
Overview ¶
Package entitycore provides a shared embedded core for Plugin Framework entities: ResourceBase centralizes resource.ResourceWithConfigure Configure wiring, the Metadata method required by resource.Resource, and stores the configured *clients.ProviderClientFactory for use via ResourceBase.Client. Data sources use envelope generics.
Data source patterns ¶
Plugin Framework data sources use **envelope generics** — NewKibanaDataSource or NewElasticsearchDataSource — which eliminate Read orchestration boilerplate. The constructor owns config decode, scoped client resolution, and state persistence. The concrete package provides only a schema factory (without connection blocks), a model that embeds KibanaConnectionField or ElasticsearchConnectionField, and a pure read function that performs the entity-specific API call and model mapping.
Example envelope data source:
type myModel struct {
entitycore.KibanaConnectionField
ID types.String `tfsdk:"id"`
}
func readMyEntity(ctx context.Context, client *clients.KibanaScopedClient, model myModel) (myModel, diag.Diagnostics) {
// API call and model population …
return model, nil
}
func NewDataSource() datasource.DataSource {
return entitycore.NewKibanaDataSource[myModel](
entitycore.ComponentKibana,
"my_entity",
getDataSourceSchema, // func(ctx context.Context) datasource.Schema, without kibana_connection block
readMyEntity,
)
}
Resource patterns ¶
Resources have three patterns:
**Struct-based embedding** — embed *ResourceBase and implement resource.Resource directly. This is the right choice when Create and Update flows diverge significantly from a uniform shape.
**Elasticsearch resource envelope** — use NewElasticsearchResource for Elasticsearch-backed CRUD resources whose lifecycle matches the envelope's shape (decode → client → version checks → callback → read-after-write → optional post-read). The model must satisfy ElasticsearchResourceModel; callbacks and options live on ElasticsearchResourceOptions. Resources that still override Create or Update may pass PlaceholderElasticsearchWriteCallback until their logic is migrated into envelope callbacks. The envelope does not implement ImportState; concrete resources add that when needed. See type docs in resource_envelope.go for the full contract.
**Kibana resource envelope** — use NewKibanaResource for Kibana-backed resources whose Create, Read, Update, and Delete flows match a common shape. The model must satisfy KibanaResourceModel (value-receiver GetID for composite or plain state ID, GetResourceID for the write key such as name or API-assigned UUID, GetSpaceID for the Kibana space, and GetKibanaConnection). Supply a schema factory (without kibana_connection block), and callbacks via KibanaResourceOptions (read, delete, create, update, optional post-read). The envelope injects the kibana_connection block, resolves resource identity via composite-ID-or-fallback for Read, Update, and Delete, validates spaceID for Create and Update, resolves the scoped Kibana client, enforces read-after-write on Create and Update, and owns state persistence. Write callbacks receive KibanaWriteRequest (plan, prior, config, write ID, space ID); inspect Prior == nil to detect Create. It does not implement ImportState; concrete resources add that when needed. Resources that override Create or Update may pass PlaceholderKibanaWriteCallback until their logic is migrated into envelope callbacks. Constructor shape and callback types are defined on NewKibanaResource in kibana_resource_envelope.go.
Ephemeral resource patterns ¶
Ephemeral resources use **envelope generics** — NewElasticsearchEphemeralResource or NewKibanaEphemeralResource — which eliminate Open/Close orchestration boilerplate. The constructor owns config decode, scoped client resolution, version-requirement enforcement, connection-block injection, and private-state round-tripping between Open and Close. Concrete packages supply a schema factory (without connection blocks), a model embedding ElasticsearchConnectionField or KibanaConnectionField, a plain-Go close-state type S, and Open/Close callbacks.
The close-state type parameter S must contain only plain Go types (string, int, bool, slices, maps, embedded structs). It must not use terraform-plugin-framework types such as types.String; the constructor enforces this at construction time via reflection and panics with a precise field path if violated.
Open() is invoked by Terraform during terraform plan as well as terraform apply. Resource authors should document this in generated resource documentation when Open performs side effects (for example creating an API key).
Close() is not guaranteed to run if Terraform is interrupted between Open and Close. Design close-time behavior accordingly (for example optional invalidation).
Example ephemeral resource (see internal/elasticsearch/security/apikey/ephemeral):
type tfModel struct {
entitycore.ElasticsearchConnectionField
Name types.String `tfsdk:"name"`
// … computed result attributes …
}
type closeState struct {
KeyID string
InvalidateOnClose bool
}
func NewResource() ephemeral.EphemeralResource {
return entitycore.NewElasticsearchEphemeralResource[tfModel, closeState](
"security_api_key",
entitycore.ElasticsearchEphemeralOptions[tfModel, closeState]{
Schema: getSchema,
Open: openAPIKey,
Close: closeAPIKey,
},
)
}
Action patterns ¶
Provider-defined actions (Terraform 1.14+) use **envelope generics** — NewElasticsearchAction or NewKibanaAction — which eliminate Configure, Metadata, Schema, and Invoke prelude boilerplate. The constructor owns config decode, scoped client resolution, optional version-requirement enforcement, automatic injection of the connection block (`elasticsearch_connection` or `kibana_connection`) and the `timeouts` block, and applies the configured invoke timeout to ctx via context.WithTimeout. The concrete package supplies a schema factory (without those two blocks), a model embedding ElasticsearchConnectionField or KibanaConnectionField plus ActionTimeoutsField, and a single ActionInvokeFunc callback.
Every action MUST expose both the connection block and the `timeouts` block. The envelope enforces this by injecting them unconditionally; concrete actions MUST NOT declare blocks under those keys.
Example action:
type Model struct {
entitycore.ElasticsearchConnectionField
entitycore.ActionTimeoutsField
Repository types.String `tfsdk:"repository"`
// … entity-specific attributes …
}
func invokeMyAction(ctx context.Context, client *clients.ElasticsearchScopedClient, req entitycore.ActionRequest[Model]) diag.Diagnostics {
// ctx already has the configured timeout applied.
// … API call and diagnostics …
return nil
}
func NewMyAction() action.Action {
return entitycore.NewElasticsearchAction[Model]("my_action", entitycore.ElasticsearchActionOptions[Model]{
Schema: getSchema, // without timeouts or elasticsearch_connection
Invoke: invokeMyAction,
DefaultInvokeTimeout: 30 * time.Minute, // optional; defaults to entitycore.DefaultActionInvokeTimeout
})
}
Component is a typed Terraform resource type-name namespace segment (for example "elasticsearch", "kibana"). It is not a client-resolution kind: the same API family can use different component strings for Terraform naming, such as APM resources using the "apm" segment while calling Kibana APIs.
The resourceName argument to NewResourceBase is the final literal suffix segment in the Terraform type name, joined without normalization. Callers must preserve existing spellings for compatibility (for example "agentbuilder_tool" versus "agent_builder_tool").
Index ¶
- Constants
- func EnforceVersionRequirements(ctx context.Context, client MinVersionClient, model any) diag.Diagnostics
- func NewElasticsearchAction[T ElasticsearchActionModel](name string, opts ElasticsearchActionOptions[T]) action.Action
- func NewElasticsearchDataSource[T ElasticsearchDataSourceModel](component Component, name string, ...) datasource.DataSource
- func NewElasticsearchEphemeralResource[T ElasticsearchEphemeralModel, S any](name string, opts ElasticsearchEphemeralOptions[T, S]) ephemeral.EphemeralResource
- func NewKibanaAction[T KibanaActionModel](name string, opts KibanaActionOptions[T]) action.Action
- func NewKibanaDataSource[T KibanaDataSourceModel](component Component, name string, ...) datasource.DataSource
- func NewKibanaEphemeralResource[T KibanaEphemeralModel, S any](name string, opts KibanaEphemeralOptions[T, S]) ephemeral.EphemeralResource
- type ActionBase
- type ActionInvokeFunc
- type ActionRequest
- type ActionTimeoutsField
- type CloseRequest
- type CloseResponse
- type Component
- type DataSourceBase
- type ElasticsearchActionModel
- type ElasticsearchActionOptions
- type ElasticsearchConnectionField
- type ElasticsearchDataSourceModel
- type ElasticsearchEphemeralCloseFunc
- type ElasticsearchEphemeralModel
- type ElasticsearchEphemeralOpenFunc
- type ElasticsearchEphemeralOptions
- type ElasticsearchEphemeralResource
- type ElasticsearchResource
- func (r *ElasticsearchResource[T]) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse)
- func (r *ElasticsearchResource[T]) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse)
- func (r *ElasticsearchResource[T]) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse)
- func (r *ElasticsearchResource[T]) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse)
- func (r *ElasticsearchResource[T]) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse)
- type ElasticsearchResourceModel
- type ElasticsearchResourceOptions
- type EphemeralBase
- type KibanaActionModel
- type KibanaActionOptions
- type KibanaConnectionField
- type KibanaDataSourceModel
- type KibanaEphemeralCloseFunc
- type KibanaEphemeralModel
- type KibanaEphemeralOpenFunc
- type KibanaEphemeralOptions
- type KibanaEphemeralResource
- type KibanaPostReadFunc
- type KibanaResource
- func (r *KibanaResource[T]) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse)
- func (r *KibanaResource[T]) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse)
- func (r *KibanaResource[T]) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse)
- func (r *KibanaResource[T]) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse)
- func (r *KibanaResource[T]) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse)
- type KibanaResourceModel
- type KibanaResourceOptions
- type KibanaUnscopedSpace
- type KibanaWriteFunc
- type KibanaWriteRequest
- type KibanaWriteResult
- type MinVersionClient
- type OpenRequest
- type OpenResult
- type PostReadFunc
- type PrivateStateStorage
- type ResourceBase
- type VersionRequirement
- type WithActionTimeouts
- type WithOptionalWriteIdentity
- type WithReadResourceID
- type WithVersionRequirements
- type WriteFunc
- type WriteRequest
- type WriteResult
Constants ¶
const DefaultActionInvokeTimeout = 20 * time.Minute
DefaultActionInvokeTimeout is used when an [ActionOptions] entry leaves DefaultInvokeTimeout zero. It is generous because actions typically wrap long-running imperative operations (snapshot, restore, reindex).
Variables ¶
This section is empty.
Functions ¶
func EnforceVersionRequirements ¶ added in v0.15.2
func EnforceVersionRequirements(ctx context.Context, client MinVersionClient, model any) diag.Diagnostics
EnforceVersionRequirements checks whether model implements WithVersionRequirements and, if so, evaluates each requirement against the scoped client. It returns any diagnostics produced. Entity envelopes call this automatically; concrete resources whose Create/Update bypass the envelope can invoke it directly to honor the model's declared requirements.
func NewElasticsearchAction ¶ added in v0.16.1
func NewElasticsearchAction[T ElasticsearchActionModel]( name string, opts ElasticsearchActionOptions[T], ) action.Action
NewElasticsearchAction returns an action.Action that owns Metadata, Configure, Schema (with `elasticsearch_connection` and `timeouts` block injection), and the Invoke prelude for the Elasticsearch namespace. The concrete action only needs to supply a schema factory (without those two blocks) and an invoke callback.
Example:
type Model struct {
entitycore.ElasticsearchConnectionField
entitycore.ActionTimeoutsField
Repository types.String `tfsdk:"repository"`
// …
}
func NewMyAction() action.Action {
return entitycore.NewElasticsearchAction[Model]("my_action", entitycore.ElasticsearchActionOptions[Model]{
Schema: getSchema,
Invoke: invokeMyAction,
DefaultInvokeTimeout: 30 * time.Minute,
})
}
func NewElasticsearchDataSource ¶
func NewElasticsearchDataSource[T ElasticsearchDataSourceModel]( component Component, name string, schemaFactory func(context.Context) dsschema.Schema, readFunc func(context.Context, *clients.ElasticsearchScopedClient, T) (T, diag.Diagnostics), ) datasource.DataSource
NewElasticsearchDataSource returns a datasource.DataSource that wraps the provided schema and read function with automatic elasticsearch_connection block injection, config decode, scoped client resolution, and state persistence.
The concrete model T must embed ElasticsearchConnectionField.
func NewElasticsearchEphemeralResource ¶ added in v0.16.0
func NewElasticsearchEphemeralResource[T ElasticsearchEphemeralModel, S any]( name string, opts ElasticsearchEphemeralOptions[T, S], ) ephemeral.EphemeralResource
NewElasticsearchEphemeralResource returns an ephemeral.EphemeralResource that owns Metadata, Configure, Schema (with elasticsearch_connection block injection), Open, and Close for the Elasticsearch namespace.
func NewKibanaAction ¶ added in v0.16.1
func NewKibanaAction[T KibanaActionModel]( name string, opts KibanaActionOptions[T], ) action.Action
NewKibanaAction returns an action.Action that owns Metadata, Configure, Schema (with `kibana_connection` and `timeouts` block injection), and the Invoke prelude for the Kibana namespace.
func NewKibanaDataSource ¶
func NewKibanaDataSource[T KibanaDataSourceModel]( component Component, name string, schemaFactory func(context.Context) dsschema.Schema, readFunc func(context.Context, *clients.KibanaScopedClient, T) (T, diag.Diagnostics), ) datasource.DataSource
NewKibanaDataSource returns a datasource.DataSource that wraps the provided schema and read function with automatic kibana_connection block injection, config decode, scoped client resolution, and state persistence.
The concrete model T must embed KibanaConnectionField so that the connection block can be decoded alongside entity attributes.
Example usage (package doc):
type myModel struct {
entitycore.KibanaConnectionField
ID types.String `tfsdk:"id"`
}
func NewDataSource() datasource.DataSource {
return entitycore.NewKibanaDataSource[myModel](
entitycore.ComponentKibana,
"my_entity",
getDataSourceSchema, // func(ctx context.Context) datasource.Schema, without kibana_connection block
readMyEntity,
)
}
func NewKibanaEphemeralResource ¶ added in v0.16.0
func NewKibanaEphemeralResource[T KibanaEphemeralModel, S any]( name string, opts KibanaEphemeralOptions[T, S], ) ephemeral.EphemeralResource
NewKibanaEphemeralResource returns an ephemeral.EphemeralResource that owns Metadata, Configure, Schema (with kibana_connection block injection), Open, and Close for the Kibana namespace.
Types ¶
type ActionBase ¶ added in v0.16.1
type ActionBase struct {
// contains filtered or unexported fields
}
ActionBase holds shared Plugin Framework action wiring: typed naming parts and the provider client factory from Configure. It is the action analogue of ResourceBase / DataSourceBase / EphemeralBase.
func NewActionBase ¶ added in v0.16.1
func NewActionBase(component Component, actionName string) *ActionBase
NewActionBase returns an ActionBase for the given namespace segment and literal action name suffix. actionName is not normalized; see package documentation.
func (*ActionBase) Client ¶ added in v0.16.1
func (a *ActionBase) Client() *clients.ProviderClientFactory
Client returns the client factory from the last successful ActionBase.Configure assignment, or nil if none has been stored yet.
func (*ActionBase) Configure ¶ added in v0.16.1
func (a *ActionBase) Configure(_ context.Context, req action.ConfigureRequest, resp *action.ConfigureResponse)
Configure implements action.ActionWithConfigure, converting provider data with clients.ConvertProviderDataToFactory and appending diagnostics. If the response has error diagnostics it returns without assigning a new factory, leaving any prior successful client unchanged. ProviderData == nil is permitted because the framework calls Configure twice (once before provider config and once after) and we must not surface a spurious error during the early call.
func (*ActionBase) Metadata ¶ added in v0.16.1
func (a *ActionBase) Metadata(_ context.Context, req action.MetadataRequest, resp *action.MetadataResponse)
Metadata implements the Metadata method of action.Action, setting the Terraform type name to "<providerTypeName>_<component>_<actionName>".
type ActionInvokeFunc ¶ added in v0.16.1
type ActionInvokeFunc[T any, Client MinVersionClient] func( ctx context.Context, client Client, req ActionRequest[T], ) diag.Diagnostics
ActionInvokeFunc performs the action's work after the envelope has decoded the configuration, resolved the scoped client, evaluated optional version requirements, and applied the invoke timeout to ctx via context.WithTimeout. The callback returns diagnostics; the envelope appends them to the framework response.
type ActionRequest ¶ added in v0.16.1
type ActionRequest[T any] struct { Config T SendProgress func(action.InvokeProgressEvent) }
ActionRequest is passed to action Invoke callbacks. Config is the decoded model from the Terraform configuration. SendProgress mirrors action.InvokeResponse.SendProgress so callbacks can stream progress events to Terraform without holding a reference to the framework response struct.
type ActionTimeoutsField ¶ added in v0.16.1
type ActionTimeoutsField struct {
Timeouts actiontimeouts.Value `tfsdk:"timeouts"`
}
ActionTimeoutsField is an embeddable struct that provides the action `timeouts` block field for action models used with NewElasticsearchAction or NewKibanaAction. Embedding it satisfies WithActionTimeouts without requiring the concrete model to redeclare the framework type.
func (ActionTimeoutsField) GetTimeouts ¶ added in v0.16.1
func (f ActionTimeoutsField) GetTimeouts() actiontimeouts.Value
GetTimeouts returns the timeouts block value.
type CloseRequest ¶ added in v0.16.0
type CloseRequest[S any] struct { State S }
CloseRequest is passed to ephemeral Close callbacks.
type CloseResponse ¶ added in v0.16.0
type CloseResponse struct{}
CloseResponse is returned by ephemeral Close callbacks.
type Component ¶
type Component string
Component is a Terraform type-name namespace segment used when building the full resource type name. See package documentation.
const ( ComponentElasticsearch Component = "elasticsearch" ComponentKibana Component = "kibana" ComponentFleet Component = "fleet" ComponentAPM Component = "apm" )
Well-known Terraform type-name namespace segments for ResourceBase.Metadata.
type DataSourceBase ¶ added in v0.15.2
type DataSourceBase struct {
// contains filtered or unexported fields
}
DataSourceBase holds shared Plugin Framework data source wiring: typed naming parts and the provider client factory from Configure. Embed *DataSourceBase in concrete data sources to reuse Configure, Metadata, and Client.
func NewDataSourceBase ¶ added in v0.15.2
func NewDataSourceBase(component Component, dataSourceName string) *DataSourceBase
NewDataSourceBase returns a DataSourceBase for the given namespace segment and literal data source name suffix. dataSourceName is not normalized; see package documentation.
func (*DataSourceBase) Client ¶ added in v0.15.2
func (d *DataSourceBase) Client() *clients.ProviderClientFactory
Client returns the client factory from the last successful Configure call, or nil if none has been stored yet. A nil *DataSourceBase returns nil so callers can surface diagnostics instead of panicking.
func (*DataSourceBase) Configure ¶ added in v0.15.2
func (d *DataSourceBase) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse)
Configure implements datasource.DataSourceWithConfigure, converting provider data with clients.ConvertProviderDataToFactory and appending diagnostics. If the response has error diagnostics, it returns without assigning a new factory, leaving any prior successful client unchanged.
func (*DataSourceBase) Metadata ¶ added in v0.15.2
func (d *DataSourceBase) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse)
Metadata implements the Metadata method of datasource.DataSource, setting the Terraform type name to "<providerTypeName>_<component>_<dataSourceName>".
type ElasticsearchActionModel ¶ added in v0.16.1
type ElasticsearchActionModel interface {
GetElasticsearchConnection() types.List
WithActionTimeouts
}
ElasticsearchActionModel is the type constraint for models passed to NewElasticsearchAction. Concrete types satisfy it by embedding both ElasticsearchConnectionField and ActionTimeoutsField.
type ElasticsearchActionOptions ¶ added in v0.16.1
type ElasticsearchActionOptions[T ElasticsearchActionModel] struct { Schema func(context.Context) actionschema.Schema Invoke ActionInvokeFunc[T, *clients.ElasticsearchScopedClient] DefaultInvokeTimeout time.Duration }
ElasticsearchActionOptions configures NewElasticsearchAction. Schema and Invoke must be non-nil or the constructor panics. DefaultInvokeTimeout is used when the configuration omits `timeouts.invoke`; zero falls back to DefaultActionInvokeTimeout.
type ElasticsearchConnectionField ¶
type ElasticsearchConnectionField struct {
ElasticsearchConnection types.List `tfsdk:"elasticsearch_connection"`
}
ElasticsearchConnectionField is an embeddable struct that provides the elasticsearch_connection block field for data source models used with NewElasticsearchDataSource.
func (ElasticsearchConnectionField) GetElasticsearchConnection ¶
func (f ElasticsearchConnectionField) GetElasticsearchConnection() types.List
GetElasticsearchConnection returns the elasticsearch_connection block value.
type ElasticsearchDataSourceModel ¶
ElasticsearchDataSourceModel is the type constraint for models passed to NewElasticsearchDataSource. It is satisfied by any struct that embeds ElasticsearchConnectionField (or otherwise provides a GetElasticsearchConnection method).
type ElasticsearchEphemeralCloseFunc ¶ added in v0.16.0
type ElasticsearchEphemeralCloseFunc[S any] func( context.Context, *clients.ElasticsearchScopedClient, CloseRequest[S], ) (CloseResponse, diag.Diagnostics)
type ElasticsearchEphemeralModel ¶ added in v0.16.0
ElasticsearchEphemeralModel is the type constraint for models passed to NewElasticsearchEphemeralResource. Concrete types must provide GetElasticsearchConnection, typically by embedding ElasticsearchConnectionField.
type ElasticsearchEphemeralOpenFunc ¶ added in v0.16.0
type ElasticsearchEphemeralOpenFunc[T ElasticsearchEphemeralModel, S any] func( context.Context, *clients.ElasticsearchScopedClient, OpenRequest[T], ) (OpenResult[T, S], diag.Diagnostics)
type ElasticsearchEphemeralOptions ¶ added in v0.16.0
type ElasticsearchEphemeralOptions[T ElasticsearchEphemeralModel, S any] struct { Schema func(context.Context) eschema.Schema Open ElasticsearchEphemeralOpenFunc[T, S] Close ElasticsearchEphemeralCloseFunc[S] }
ElasticsearchEphemeralOptions configures NewElasticsearchEphemeralResource. Schema, Open, and Close must be non-nil or the constructor panics.
type ElasticsearchEphemeralResource ¶ added in v0.16.0
type ElasticsearchEphemeralResource[T ElasticsearchEphemeralModel, S any] = genericEphemeralResource[T, S, *clients.ElasticsearchScopedClient]
ElasticsearchEphemeralResource implements ephemeral.EphemeralResource and related interfaces for Elasticsearch-backed ephemeral resources.
type ElasticsearchResource ¶
type ElasticsearchResource[T ElasticsearchResourceModel] struct { *ResourceBase // contains filtered or unexported fields }
ElasticsearchResource implements resource.Resource and related interfaces for Elasticsearch-backed resources. It embeds *ResourceBase to reuse Configure, Metadata, and Client.
The envelope owns Schema (with elasticsearch_connection block injection), Create, Read, Update, and Delete. Concrete resources may override Create or Update when their lifecycle does not fit the callback contract, and may choose to implement ImportState.
func NewElasticsearchResource ¶
func NewElasticsearchResource[T ElasticsearchResourceModel](name string, opts ElasticsearchResourceOptions[T]) *ElasticsearchResource[T]
NewElasticsearchResource returns an *ElasticsearchResource that owns Schema, Create, Read, Update, and Delete for the Elasticsearch namespace. Concrete resources supply callbacks in opts; Schema, Read, Delete, Create, and Update must be non-nil or the envelope surfaces configuration error diagnostics instead of invoking nil callbacks.
func (*ElasticsearchResource[T]) Create ¶
func (r *ElasticsearchResource[T]) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse)
Create implements resource.Resource: decode plan, resolve client, invoke the create callback, read-after-write, then persist state from readFunc.
func (*ElasticsearchResource[T]) Delete ¶
func (r *ElasticsearchResource[T]) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse)
Delete implements resource.Resource with the standard prelude, then delegates to the concrete deleteFunc.
func (*ElasticsearchResource[T]) Read ¶
func (r *ElasticsearchResource[T]) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse)
Read implements resource.Resource with the standard prelude: deserialize prior state into the generic model T, resolve read identity from the model and/or composite ID, resolve the scoped Elasticsearch client, enforce optional version requirements when the model reports requirement diagnostics with an error severity (matching Kibana envelope semantics), then delegate to the concrete readFunc.
func (*ElasticsearchResource[T]) Schema ¶
func (r *ElasticsearchResource[T]) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse)
Schema implements resource.Resource, injecting the elasticsearch_connection block into the schema returned by the concrete schema factory.
func (*ElasticsearchResource[T]) Update ¶
func (r *ElasticsearchResource[T]) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse)
Update implements resource.Resource with the same prelude as Create, additionally decoding prior state for the update callback.
type ElasticsearchResourceModel ¶
type ElasticsearchResourceModel interface {
GetID() types.String
// GetResourceID returns the plan-safe write identity (for example name or
// username). Create and Update use this instead of GetID because computed
// id values may be unknown in create plans.
GetResourceID() types.String
GetElasticsearchConnection() types.List
}
ElasticsearchResourceModel is the type constraint for models passed to NewElasticsearchResource. Concrete types must provide value-receiver methods GetID, GetResourceID, and GetElasticsearchConnection.
type ElasticsearchResourceOptions ¶ added in v0.15.2
type ElasticsearchResourceOptions[T ElasticsearchResourceModel] struct { Schema func(context.Context) rschema.Schema Read elasticsearchReadFunc[T] Delete elasticsearchDeleteFunc[T] Create WriteFunc[T] Update WriteFunc[T] PostRead PostReadFunc[T] }
ElasticsearchResourceOptions configures NewElasticsearchResource. PostRead is optional; Schema, Read, Delete, Create, and Update must be non-nil or the envelope surfaces configuration diagnostics instead of invoking nil callbacks. Create and Update share the WriteFunc type so callers may pass the same function for both when the logic is identical.
type EphemeralBase ¶ added in v0.16.0
type EphemeralBase struct {
// contains filtered or unexported fields
}
EphemeralBase holds shared Plugin Framework ephemeral resource wiring: typed naming parts and the provider client factory from Configure.
func NewEphemeralBase ¶ added in v0.16.0
func NewEphemeralBase(component Component, ephemeralName string) *EphemeralBase
NewEphemeralBase returns an EphemeralBase for the given namespace segment and literal ephemeral resource name suffix.
func (*EphemeralBase) Client ¶ added in v0.16.0
func (e *EphemeralBase) Client() *clients.ProviderClientFactory
Client returns the client factory from the last successful Configure call, or nil if none has been stored yet.
func (*EphemeralBase) Metadata ¶ added in v0.16.0
func (e *EphemeralBase) Metadata(providerTypeName string) string
Metadata sets the Terraform type name to "<providerTypeName>_<component>_<ephemeralName>".
func (*EphemeralBase) SetClient ¶ added in v0.16.0
func (e *EphemeralBase) SetClient(factory *clients.ProviderClientFactory)
SetClient assigns the configured client factory when Configure succeeds.
type KibanaActionModel ¶ added in v0.16.1
type KibanaActionModel interface {
GetKibanaConnection() types.List
WithActionTimeouts
}
KibanaActionModel is the type constraint for models passed to NewKibanaAction. Concrete types satisfy it by embedding both KibanaConnectionField and ActionTimeoutsField.
type KibanaActionOptions ¶ added in v0.16.1
type KibanaActionOptions[T KibanaActionModel] struct { Schema func(context.Context) actionschema.Schema Invoke ActionInvokeFunc[T, *clients.KibanaScopedClient] DefaultInvokeTimeout time.Duration }
KibanaActionOptions configures NewKibanaAction. Schema and Invoke must be non-nil or the constructor panics. DefaultInvokeTimeout is used when the configuration omits `timeouts.invoke`; zero falls back to DefaultActionInvokeTimeout.
type KibanaConnectionField ¶
KibanaConnectionField is an embeddable struct that provides the kibana_connection block field for Kibana entity models used with NewKibanaDataSource or NewKibanaResource.
func (KibanaConnectionField) GetKibanaConnection ¶
func (f KibanaConnectionField) GetKibanaConnection() types.List
GetKibanaConnection returns the kibana_connection block value.
type KibanaDataSourceModel ¶
KibanaDataSourceModel is the type constraint for models passed to NewKibanaDataSource. It is satisfied by any struct that embeds KibanaConnectionField (or otherwise provides a GetKibanaConnection method).
type KibanaEphemeralCloseFunc ¶ added in v0.16.0
type KibanaEphemeralCloseFunc[S any] func( context.Context, *clients.KibanaScopedClient, CloseRequest[S], ) (CloseResponse, diag.Diagnostics)
type KibanaEphemeralModel ¶ added in v0.16.0
KibanaEphemeralModel is the type constraint for models passed to NewKibanaEphemeralResource. Concrete types must provide GetKibanaConnection, typically by embedding KibanaConnectionField.
type KibanaEphemeralOpenFunc ¶ added in v0.16.0
type KibanaEphemeralOpenFunc[T KibanaEphemeralModel, S any] func( context.Context, *clients.KibanaScopedClient, OpenRequest[T], ) (OpenResult[T, S], diag.Diagnostics)
type KibanaEphemeralOptions ¶ added in v0.16.0
type KibanaEphemeralOptions[T KibanaEphemeralModel, S any] struct { Schema func(context.Context) eschema.Schema Open KibanaEphemeralOpenFunc[T, S] Close KibanaEphemeralCloseFunc[S] }
KibanaEphemeralOptions configures NewKibanaEphemeralResource. Schema, Open, and Close must be non-nil or the constructor panics.
type KibanaEphemeralResource ¶ added in v0.16.0
type KibanaEphemeralResource[T KibanaEphemeralModel, S any] = genericEphemeralResource[T, S, *clients.KibanaScopedClient]
KibanaEphemeralResource implements ephemeral.EphemeralResource and related interfaces for Kibana-backed ephemeral resources.
type KibanaPostReadFunc ¶ added in v0.16.0
type KibanaPostReadFunc[T KibanaResourceModel] func( ctx context.Context, client *clients.KibanaScopedClient, model T, privateState any, ) diag.Diagnostics
KibanaPostReadFunc runs after a successful read that persisted state, including read-after-write refresh. It is optional. The privateState argument is the framework response Private field (typically *internal/privatestate.ProviderData).
type KibanaResource ¶
type KibanaResource[T KibanaResourceModel] struct { *ResourceBase // contains filtered or unexported fields }
KibanaResource implements resource.Resource and related interfaces for Kibana-backed resources. It embeds *ResourceBase to reuse Configure, Metadata, and Client.
The envelope owns Schema (with kibana_connection block injection), Create, Read, Update, and Delete. Concrete resources may override Create or Update when their lifecycle does not fit the callback contract, and may choose to implement ImportState.
func NewKibanaResource ¶
func NewKibanaResource[T KibanaResourceModel]( component Component, name string, opts KibanaResourceOptions[T], ) *KibanaResource[T]
NewKibanaResource returns an *KibanaResource that owns Schema, Create, Read, Update, and Delete. Concrete resources supply callbacks in opts; Schema, Read, Delete, Create, and Update must be non-nil or the envelope surfaces configuration error diagnostics instead of invoking nil callbacks.
func (*KibanaResource[T]) Create ¶
func (r *KibanaResource[T]) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse)
Create implements resource.Resource: decode plan and config, validate spaceID, resolve client, invoke the create callback, read-after-write, then persist state.
func (*KibanaResource[T]) Delete ¶
func (r *KibanaResource[T]) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse)
Delete implements resource.Resource with the standard prelude, then delegates to the concrete deleteFunc.
func (*KibanaResource[T]) Read ¶
func (r *KibanaResource[T]) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse)
Read implements resource.Resource with the standard prelude: decode state, resolve identity via composite-ID-or-fallback, validate resourceID, resolve scoped Kibana client, then delegate to the concrete readFunc. When readFunc reports found==true, the returned model is persisted via resp.State.Set; when found==false, the resource is removed from state.
func (*KibanaResource[T]) Schema ¶
func (r *KibanaResource[T]) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse)
Schema implements resource.Resource, injecting the kibana_connection block into the schema returned by the concrete schema factory.
func (*KibanaResource[T]) Update ¶
func (r *KibanaResource[T]) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse)
Update implements resource.Resource: decode plan, prior state, and config, validate identity and spaceID, resolve client, invoke the update callback, read-after-write, then persist state.
type KibanaResourceModel ¶
type KibanaResourceModel interface {
GetID() types.String
// GetResourceID returns the plan-safe write identity (for example name or
// API-assigned UUID). Read, Update, and Delete use this when the state ID
// is not a composite.
GetResourceID() types.String
GetSpaceID() types.String
GetKibanaConnection() types.List
}
KibanaResourceModel is the type constraint for models passed to NewKibanaResource. Concrete types must provide value-receiver methods GetID, GetResourceID, GetSpaceID, and GetKibanaConnection.
type KibanaResourceOptions ¶ added in v0.16.0
type KibanaResourceOptions[T KibanaResourceModel] struct { Schema func(context.Context) rschema.Schema Read kibanaReadFunc[T] Delete kibanaDeleteFunc[T] Create KibanaWriteFunc[T] Update KibanaWriteFunc[T] PostRead KibanaPostReadFunc[T] }
KibanaResourceOptions configures NewKibanaResource. PostRead is optional; Schema, Read, Delete, Create, and Update must be non-nil or the envelope surfaces configuration diagnostics instead of invoking nil callbacks.
type KibanaUnscopedSpace ¶ added in v0.15.2
type KibanaUnscopedSpace interface {
IsUnscopedSpace() bool
}
KibanaUnscopedSpace is implemented by KibanaResourceModel values whose Kibana API is not space-scoped. Only these models may use an empty space identifier on Create; others still require a non-empty, known space ID.
type KibanaWriteFunc ¶ added in v0.16.0
type KibanaWriteFunc[T KibanaResourceModel] func( context.Context, *clients.KibanaScopedClient, KibanaWriteRequest[T], ) (KibanaWriteResult[T], diag.Diagnostics)
KibanaWriteFunc performs Create or Update after the envelope decodes the plan (and prior state for Update), validates spaceID, resolves the scoped Kibana client, and evaluates optional version requirements. Inspect req.Prior == nil to detect Create when sharing a single function for both Create and Update.
func PlaceholderKibanaWriteCallback ¶ added in v0.16.0
func PlaceholderKibanaWriteCallback[T KibanaResourceModel]() KibanaWriteFunc[T]
PlaceholderKibanaWriteCallback returns a write callback that fails if invoked. Use for both Create and Update when a concrete resource type still defines its own Create and Update methods that override the envelope so Terraform never calls the placeholder.
type KibanaWriteRequest ¶ added in v0.16.0
type KibanaWriteRequest[T KibanaResourceModel] struct { Plan T Prior *T Config T WriteID string SpaceID string }
KibanaWriteRequest is passed to KibanaWriteFunc. Config is the Terraform configuration decoded into T by the envelope before the callback is invoked. Prior is non-nil only for Update; Create receives Prior == nil.
type KibanaWriteResult ¶ added in v0.16.0
type KibanaWriteResult[T KibanaResourceModel] struct { Model T }
KibanaWriteResult is returned by write callbacks; the envelope read-after-write flow uses Model when resolving refresh identity and calling readFunc.
type MinVersionClient ¶ added in v0.15.2
type MinVersionClient interface {
EnforceMinVersion(ctx context.Context, minVersion *version.Version) (bool, diag.Diagnostics)
}
MinVersionClient is implemented by scoped API clients used by entity envelopes for minimum server version checks.
type OpenRequest ¶ added in v0.16.0
type OpenRequest[T any] struct { Config T }
OpenRequest is passed to ephemeral Open callbacks.
type OpenResult ¶ added in v0.16.0
OpenResult is returned by ephemeral Open callbacks.
type PostReadFunc ¶ added in v0.15.2
type PostReadFunc[T ElasticsearchResourceModel] func( ctx context.Context, client *clients.ElasticsearchScopedClient, model T, privateState any, ) diag.Diagnostics
PostReadFunc runs after a successful read that persisted state, including read-after-write refresh. It is optional. The privateState argument is the framework response Private field (typically *internal/privatestate.ProviderData).
type PrivateStateStorage ¶ added in v0.16.1
type PrivateStateStorage interface {
GetKey(ctx context.Context, key string) ([]byte, diag.Diagnostics)
SetKey(ctx context.Context, key string, value []byte) diag.Diagnostics
}
PrivateStateStorage is the subset of Terraform resource private state used by envelope write callbacks.
type ResourceBase ¶
type ResourceBase struct {
// contains filtered or unexported fields
}
ResourceBase holds shared Plugin Framework resource wiring: typed naming parts and the provider client factory from Configure. Embed *ResourceBase in concrete resources to reuse Configure, Metadata, and Client.
func NewResourceBase ¶
func NewResourceBase(component Component, resourceName string) *ResourceBase
NewResourceBase returns a ResourceBase for the given namespace segment and literal resource name suffix. resourceName is not normalized; see package documentation.
func (*ResourceBase) Client ¶
func (c *ResourceBase) Client() *clients.ProviderClientFactory
Client returns the client factory from the last successful ResourceBase.Configure assignment, or nil if none has been stored yet. A nil *ResourceBase (e.g. a partially constructed embed) returns nil so callers can surface diagnostics instead of panicking.
func (*ResourceBase) Configure ¶
func (c *ResourceBase) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse)
Configure implements resource.ResourceWithConfigure, converting provider data with clients.ConvertProviderDataToFactory and appending diagnostics. If the response has error diagnostics, it returns without assigning a new factory, leaving any prior successful client unchanged (same pattern as resources such as fleet integration and kibana agent builder tool).
func (*ResourceBase) Metadata ¶
func (c *ResourceBase) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse)
Metadata implements the Metadata method of resource.Resource, setting the Terraform type name to "<providerTypeName>_<component>_<resourceName>".
type VersionRequirement ¶ added in v0.15.2
type VersionRequirement struct {
// MinVersion is the minimum server version required.
MinVersion version.Version
// ErrorMessage is the human-readable detail added to the
// "Unsupported server version" diagnostic when the server does not
// satisfy MinVersion.
ErrorMessage string
}
VersionRequirement describes a minimum server version that an entity model requires before the envelope invokes the concrete lifecycle callback.
type WithActionTimeouts ¶ added in v0.16.1
type WithActionTimeouts interface {
GetTimeouts() actiontimeouts.Value
}
WithActionTimeouts is the timeouts portion of the action model contract. Concrete action models satisfy it by embedding ActionTimeoutsField (or by declaring an equivalent field plus method).
type WithOptionalWriteIdentity ¶ added in v0.16.1
type WithOptionalWriteIdentity interface {
AllowsEmptyWriteIdentityOnCreate() bool
}
WithOptionalWriteIdentity marks models whose write identity (GetResourceID) may be empty on Create when the API auto-generates an identifier (for example POST /_connector without a connector_id).
type WithReadResourceID ¶ added in v0.15.2
type WithReadResourceID interface {
GetReadResourceID() string
}
WithReadResourceID is an optional interface for models that need a stable read identity distinct from the composite state ID segment used as the default.
type WithVersionRequirements ¶
type WithVersionRequirements interface {
GetVersionRequirements() ([]VersionRequirement, diag.Diagnostics)
}
WithVersionRequirements is an optional interface that entity models may implement to declare server version requirements. When a decoded model satisfies this interface, Kibana and Elasticsearch envelopes evaluate the requirements after scoped client resolution and before invoking the concrete lifecycle callback.
type WriteFunc ¶ added in v0.15.2
type WriteFunc[T ElasticsearchResourceModel] func( context.Context, *clients.ElasticsearchScopedClient, WriteRequest[T], ) (WriteResult[T], diag.Diagnostics)
WriteFunc performs Create or Update after the envelope decodes the plan (and prior state for Update), validates the write identity, resolves the scoped Elasticsearch client, and evaluates optional version requirements. Inspect req.Prior == nil to detect Create when sharing a single function for both Create and Update.
func PlaceholderElasticsearchWriteCallback ¶ added in v0.15.2
func PlaceholderElasticsearchWriteCallback[T ElasticsearchResourceModel]() WriteFunc[T]
func UpdateNotSupportedWriteCallback ¶ added in v0.16.0
func UpdateNotSupportedWriteCallback[T ElasticsearchResourceModel]() WriteFunc[T]
UpdateNotSupportedWriteCallback returns a write callback that always returns an error diagnostic. Use for resources where all mutable attributes carry RequiresReplace, so Terraform never reaches an in-place update.
type WriteRequest ¶ added in v0.15.2
type WriteRequest[T ElasticsearchResourceModel] struct { Plan T Prior *T Config T WriteID string // Private is the framework response Private field (typically // *internal/privatestate.Data). Nil when the callback does not need it. Private PrivateStateStorage }
WriteRequest is passed to WriteFunc. Config is the Terraform configuration decoded into T by the envelope before the callback is invoked. Prior is non-nil only for Update; Create receives Prior == nil. The same WriteRequest type is shared by Create and Update so a single function can serve both when the logic does not differ.
type WriteResult ¶ added in v0.15.2
type WriteResult[T ElasticsearchResourceModel] struct { Model T }
WriteResult is returned by write callbacks; the envelope read-after-write flow uses Model when resolving refresh identity and calling readFunc.
Source Files
¶
- action_envelope.go
- constants.go
- data_source_envelope.go
- doc.go
- elasticsearch_ephemeral_envelope.go
- ephemeral_close_state.go
- ephemeral_connection_snapshot.go
- ephemeral_envelope.go
- ephemeral_envelope_test_helpers.go
- kibana_ephemeral_envelope.go
- kibana_resource_envelope.go
- kibana_unscoped_space.go
- resource_base.go
- resource_envelope.go
- version_requirements.go
- write_invocation.go