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 CompositeIDForWrite[T ElasticsearchResourceModel](ctx context.Context, client *clients.ElasticsearchScopedClient, ...) (types.String, diag.Diagnostics)
- func EnforceVersionRequirements(ctx context.Context, client MinVersionClient, model any) diag.Diagnostics
- func IDAttribute() schema.StringAttribute
- func KibanaResourceID(spaceID, resourceID string) types.String
- 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
- func ParseCompositeID(req resource.ImportStateRequest, resp *resource.ImportStateResponse) (*clients.CompositeID, bool)
- func PreserveStringFromPriorIfUnknown(out, prior types.String) types.String
- func RequireNonNilKibanaWriteResponse[T any](diags *diag.Diagnostics, resp *T, verb, noun string) bool
- type ActionBase
- type ActionInvokeFunc
- type ActionRequest
- type ActionTimeoutsField
- type CloseRequest
- type CloseResponse
- type Component
- type CompositeIDImporter
- type DataSourceBase
- type ElasticsearchActionModel
- type ElasticsearchActionOptions
- type ElasticsearchConnectionField
- type ElasticsearchDataSourceModel
- type ElasticsearchEphemeralCloseFunc
- type ElasticsearchEphemeralModel
- type ElasticsearchEphemeralOpenFunc
- type ElasticsearchEphemeralOptions
- type ElasticsearchEphemeralResource
- type ElasticsearchPostReadRequest
- type ElasticsearchResource
- func (r *ElasticsearchResource[T]) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse)
- func (b *ElasticsearchResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse)
- func (b *ElasticsearchResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse)
- func (b *ElasticsearchResource) 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 KibanaDeleteFunc
- type KibanaEphemeralCloseFunc
- type KibanaEphemeralModel
- type KibanaEphemeralOpenFunc
- type KibanaEphemeralOptions
- type KibanaEphemeralResource
- type KibanaPostReadFunc
- type KibanaPostReadRequest
- type KibanaReadFunc
- type KibanaResource
- func (r *KibanaResource[T]) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse)
- func (b *KibanaResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse)
- func (b *KibanaResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse)
- func (b *KibanaResource) 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 KibanaSpaceImporter
- func (s *KibanaSpaceImporter) DefaultSpaceID(spaceID string) *KibanaSpaceImporter
- func (s *KibanaSpaceImporter) ImportState(ctx context.Context, req resource.ImportStateRequest, ...)
- func (s *KibanaSpaceImporter) RequireSpaceID(summary, detail string) *KibanaSpaceImporter
- func (s *KibanaSpaceImporter) SeedState(ctx context.Context, resp *resource.ImportStateResponse, importID string, ...)
- type KibanaUnscopedSpace
- type KibanaWriteFunc
- func PlaceholderKibanaWriteCallback[T KibanaResourceModel]() KibanaWriteFunc[T]
- func SimpleKibanaCreate[T KibanaResourceModel, Body any, R any](toBody func(plan T, ctx context.Context) (Body, diag.Diagnostics), ...) KibanaWriteFunc[T]
- func SimpleKibanaUpdate[T KibanaResourceModel, Body any, R any](...) KibanaWriteFunc[T]
- type KibanaWriteRequest
- type KibanaWriteResult
- type MinVersionClient
- type OpenRequest
- type OpenResult
- type PostReadFunc
- type PrivateStateStorage
- type ResourceBase
- type ResourceTimeouts
- type ResourceTimeoutsField
- type SpaceImporter
- type VersionCheck
- type VersionRequirement
- func NewAttributeVersionCheckRequirement(attr path.Path, check VersionCheck, errorMessage string) VersionRequirement
- func NewAttributeVersionRequirement(attr path.Path, minVersion version.Version, errorMessage string) VersionRequirement
- func SingleVersionRequirement(minVersion version.Version, errorMessage string) []VersionRequirement
- type WithActionTimeouts
- type WithOptionalWriteIdentity
- type WithReadResourceID
- type WithResourceTimeouts
- type WithVersionRequirements
- type WriteFunc
- type WriteRequest
- type WriteResult
Constants ¶
const ( DefaultResourceCreateTimeout = 20 * time.Minute DefaultResourceReadTimeout = 5 * time.Minute DefaultResourceUpdateTimeout = 20 * time.Minute DefaultResourceDeleteTimeout = 20 * time.Minute )
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 CompositeIDForWrite ¶ added in v0.16.4
func CompositeIDForWrite[T ElasticsearchResourceModel]( ctx context.Context, client *clients.ElasticsearchScopedClient, req WriteRequest[T], ) (types.String, diag.Diagnostics)
CompositeIDForWrite returns the composite resource ID to persist after a write.
On Create (req.Prior == nil) it computes the ID from the live cluster UUID via client.ID.
On Update it never calls client.ID, so a stale cluster-UUID prefix in state (for example after a cluster recreation behind the same endpoint) is preserved and UseStateForUnknown on id is not violated. The write-identity segment is taken from req.WriteID:
- If the prior id's resource segment equals req.WriteID, the prior id is returned unchanged. Safe for RequiresReplace identity keys (role name, watch_id, datafeed_id) and for in-place updates that do not change name.
- If the prior id's resource segment differs from req.WriteID, the returned id is <prior cluster UUID>/<WriteID>. This keeps Read/Delete targeting the new name after an in-place name change (data_stream_lifecycle).
- If the prior id is not a valid composite id, the prior id is returned unchanged rather than inventing a cluster UUID.
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 IDAttribute ¶ added in v0.16.5
func IDAttribute() schema.StringAttribute
IDAttribute returns the computed "id" string attribute shared by resource schemas across the provider: an internal identifier that is pinned to its prior state value via UseStateForUnknown so unrelated attribute changes don't show it as unknown in the plan.
func KibanaResourceID ¶ added in v0.16.4
KibanaResourceID builds the `<spaceID>/<resourceID>` composite Terraform resource ID shared by space-scoped Kibana list and exception-list resources, wrapping clients.CompositeID with the types.StringValue conversion every Create callback needs.
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.
func ParseCompositeID ¶ added in v0.16.5
func ParseCompositeID(req resource.ImportStateRequest, resp *resource.ImportStateResponse) (*clients.CompositeID, bool)
ParseCompositeID parses req.ID as a "<cluster_uuid>/<resource_id>" composite ID, appending an error diagnostic to resp and returning ok=false if req.ID is not a valid composite ID.
Use this directly (rather than CompositeIDImporter) when a resource's ImportState needs to do more than set idField/resourceIDFields verbatim, e.g. splitting the resource-ID portion further or normalizing it via a live client call, while still sharing the parse+bail-out boilerplate.
func PreserveStringFromPriorIfUnknown ¶ added in v0.16.4
PreserveStringFromPriorIfUnknown returns prior when out is Unknown in the plan and prior holds a known value. Used when SkipReadAfterWrite persists the write callback model without a read refresh (server-computed fields stay Unknown in the plan but must not be written as Unknown to state).
func RequireNonNilKibanaWriteResponse ¶ added in v0.16.4
func RequireNonNilKibanaWriteResponse[T any](diags *diag.Diagnostics, resp *T, verb, noun string) bool
RequireNonNilKibanaWriteResponse appends the standard "Failed to <verb> <noun>" / "API returned empty response" error diagnostic when resp is nil. This wording and nil-check repeats verbatim across the Kibana list and exception-list Create/Update callbacks (securitylist, securitylistitem, securityexceptionlist, securityexceptionitem). It reports whether resp was nil so callers can return immediately:
createdList, d := kibanaoapi.CreateList(ctx, oapiClient, req.SpaceID, *createReq)
diags.Append(d...)
if diags.HasError() {
return entitycore.KibanaWriteResult[Model]{}, diags
}
if entitycore.RequireNonNilKibanaWriteResponse(&diags, createdList, "create", "security list") {
return entitycore.KibanaWriteResult[Model]{}, diags
}
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 CompositeIDImporter ¶ added in v0.16.5
type CompositeIDImporter struct {
// contains filtered or unexported fields
}
CompositeIDImporter is an embeddable struct that provides a generic ImportState implementation for Elasticsearch resources with a required "<cluster_uuid>/<resource_id>" composite state ID: idField is set to the raw import ID and each of resourceIDFields is set to the resource-ID portion of the composite ID.
When embedded in a resource struct, Go promotes the ImportState method, satisfying resource.ResourceWithImportState without an explicit method.
Usage:
type myResource struct {
*entitycore.ElasticsearchResource[TFModel]
*entitycore.CompositeIDImporter
}
func newMyResource() *myResource {
return &myResource{
ElasticsearchResource: ...,
CompositeIDImporter: entitycore.NewCompositeIDImporter(path.Root("id"), path.Root("resource_id")),
}
}
Resources that need to derive additional state from the resource-ID portion (for example splitting it further, or normalizing it via a live client call) should use ParseCompositeID directly instead.
func NewCompositeIDImporter ¶ added in v0.16.5
func NewCompositeIDImporter(idField path.Path, resourceIDFields ...path.Path) *CompositeIDImporter
NewCompositeIDImporter constructs a CompositeIDImporter that sets idField to the raw import ID and each of resourceIDFields to the resource-ID portion of the composite import ID. At least one resourceIDField is required.
func (*CompositeIDImporter) ImportState ¶ added in v0.16.5
func (c *CompositeIDImporter) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse)
ImportState handles import for resources with a required "<cluster_uuid>/<resource_id>" composite ID.
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 ElasticsearchPostReadRequest ¶ added in v0.16.2
type ElasticsearchPostReadRequest[T ElasticsearchResourceModel] struct { Client *clients.ElasticsearchScopedClient Prior T State T Private PrivateStateStorage }
ElasticsearchPostReadRequest is passed to PostReadFunc. Prior is the model before the read (plan on write path, prior state on plain Read path). State is the freshly-read model returned by the read callback.
type ElasticsearchResource ¶
type ElasticsearchResource[T ElasticsearchResourceModel] struct { // contains filtered or unexported fields }
ElasticsearchResource implements resource.Resource and related interfaces for Elasticsearch-backed resources. It embeds [baseResourceEnvelope] to reuse Configure, Metadata, Client, Schema, Read, and Delete.
The envelope owns Schema (with elasticsearch_connection block and timeouts attribute 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) Delete ¶
func (b *ElasticsearchResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse)
Delete implements resource.Resource.
func (*ElasticsearchResource) Read ¶
func (b *ElasticsearchResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse)
Read implements resource.Resource. Nil read callbacks surface a configuration diagnostic; this guard prevents nil-dereference panics when a resource type intentionally omits Read (e.g. import-only resources).
func (*ElasticsearchResource) Schema ¶
func (b *ElasticsearchResource) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse)
Schema implements resource.Resource, injecting the connection block and the `timeouts` attribute into the schema returned by the concrete schema factory. A pre-existing `timeouts` attribute in the factory output is silently replaced.
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
WithResourceTimeouts
}
ElasticsearchResourceModel is the type constraint for models passed to NewElasticsearchResource. Concrete types must provide value-receiver methods GetID, GetResourceID, GetElasticsearchConnection, and WithResourceTimeouts (typically by embedding ResourceTimeoutsField).
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] Timeouts ResourceTimeouts // SkipReadAfterWrite, when true, persists the write callback's WriteResult.Model // to state directly instead of re-reading via the read callback after Create/Update. // Use for resources whose write already returns the authoritative post-write state // and where a generic re-read would lose information (e.g. a transient state that the // write path detected but a subsequent read cannot reconstruct). The read callback is // still used for Read/refresh. SkipReadAfterWrite bool }
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.
Timeouts supplies per-operation default durations when configuration omits `timeouts.<op>`; zero fields fall back to DefaultResourceCreateTimeout, DefaultResourceReadTimeout, DefaultResourceUpdateTimeout, and DefaultResourceDeleteTimeout. Concrete schema factories MUST NOT include a `timeouts` attribute; the envelope injects it and silently overwrites any factory-supplied attribute with the same key.
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 KibanaDeleteFunc ¶ added in v0.16.4
type KibanaDeleteFunc[T KibanaResourceModel] func( context.Context, *clients.KibanaScopedClient, string, string, T, ) diag.Diagnostics
func SimpleKibanaDelete ¶ added in v0.16.4
func SimpleKibanaDelete[T KibanaResourceModel]( apiDelete func(ctx context.Context, client *kibanaoapi.Client, spaceID, resourceID string) diag.Diagnostics, ) KibanaDeleteFunc[T]
SimpleKibanaDelete returns a KibanaDeleteFunc that resolves the scoped Kibana OAPI client and delegates directly to apiDelete. Use for resources whose delete callback needs nothing beyond client, spaceID, and resourceID, for example:
Delete: entitycore.SimpleKibanaDelete[agentModel](kibanaoapi.DeleteAgent),
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, req KibanaPostReadRequest[T], ) (T, diag.Diagnostics)
KibanaPostReadFunc runs after a successful read and before state is persisted, including read-after-write refresh. It is optional.
type KibanaPostReadRequest ¶ added in v0.16.2
type KibanaPostReadRequest[T KibanaResourceModel] struct { Client *clients.KibanaScopedClient Prior T State T Private PrivateStateStorage }
KibanaPostReadRequest is passed to KibanaPostReadFunc. Prior is the model before the read (plan on write path, prior state on plain Read path). State is the freshly-read model returned by the read callback.
type KibanaReadFunc ¶ added in v0.16.4
type KibanaReadFunc[T KibanaResourceModel] func( context.Context, *clients.KibanaScopedClient, string, string, T, ) (T, bool, diag.Diagnostics)
func SimpleKibanaRead ¶ added in v0.16.4
func SimpleKibanaRead[T KibanaResourceModel, R any]( apiGet func(ctx context.Context, client *kibanaoapi.Client, spaceID, resourceID string) (*R, diag.Diagnostics), populate func(model *T, ctx context.Context, spaceID string, data *R) diag.Diagnostics, ) KibanaReadFunc[T]
SimpleKibanaRead returns a KibanaReadFunc for the common fetch-then-populate shape shared by simple Kibana resources: call apiGet for resourceID in spaceID, treat a nil result as "not found", and otherwise apply populate to the prior model. Use for resources whose read callback needs nothing beyond that shape; resources with extra logic (retries, derived fields not sourced from the API payload) should keep a hand-written read callback. populate is typically a populateFromAPI method expression:
Read: entitycore.SimpleKibanaRead[agentModel, models.Agent](kibanaoapi.GetAgent, (*agentModel).populateFromAPI),
type KibanaResource ¶
type KibanaResource[T KibanaResourceModel] struct { // contains filtered or unexported fields }
KibanaResource implements resource.Resource and related interfaces for Kibana-backed resources. It embeds [baseResourceEnvelope] to reuse Configure, Metadata, Client, Schema, Read, and Delete.
The envelope owns Schema (with kibana_connection block and timeouts attribute 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) Delete ¶
func (b *KibanaResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse)
Delete implements resource.Resource.
func (*KibanaResource) Read ¶
func (b *KibanaResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse)
Read implements resource.Resource. Nil read callbacks surface a configuration diagnostic; this guard prevents nil-dereference panics when a resource type intentionally omits Read (e.g. import-only resources).
func (*KibanaResource) Schema ¶
func (b *KibanaResource) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse)
Schema implements resource.Resource, injecting the connection block and the `timeouts` attribute into the schema returned by the concrete schema factory. A pre-existing `timeouts` attribute in the factory output is silently replaced.
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
WithResourceTimeouts
}
KibanaResourceModel is the type constraint for models passed to NewKibanaResource. Concrete types must provide value-receiver methods GetID, GetResourceID, GetSpaceID, GetKibanaConnection, and WithResourceTimeouts (typically by embedding ResourceTimeoutsField).
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] Timeouts ResourceTimeouts }
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.
Timeouts supplies per-operation default durations when configuration omits `timeouts.<op>`; zero fields fall back to DefaultResourceCreateTimeout, DefaultResourceReadTimeout, DefaultResourceUpdateTimeout, and DefaultResourceDeleteTimeout. Concrete schema factories MUST NOT include a `timeouts` attribute; the envelope injects it and silently overwrites any factory-supplied attribute with the same key.
type KibanaSpaceImporter ¶ added in v0.16.4
type KibanaSpaceImporter struct {
// contains filtered or unexported fields
}
KibanaSpaceImporter is an embeddable struct that provides a generic ImportState implementation for Kibana resources that support space-aware composite IDs and expose the space as a singular "space_id" string attribute, rather than Fleet's "space_ids" list.
Unlike SpaceImporter, the import ID is always required to be a composite "<space_id>/<resource_id>" string; a diagnostic is added and no attributes are set if it is not.
Usage:
type myResource struct {
*entitycore.KibanaSpaceImporter
// ...
}
func newMyResource() *myResource {
return &myResource{
KibanaSpaceImporter: entitycore.NewKibanaSpaceImporter(
path.Root("id"), path.Root("space_id"), path.Root("rule_id"),
),
}
}
func NewKibanaSpaceImporter ¶ added in v0.16.4
func NewKibanaSpaceImporter(idField, spaceIDField path.Path, resourceIDFields ...path.Path) *KibanaSpaceImporter
NewKibanaSpaceImporter constructs a KibanaSpaceImporter that will set idField to the full import ID, spaceIDField to the space-ID portion of the composite ID, and each of resourceIDFields to the resource-ID portion. At least one resourceIDField is required.
By default, a composite ID whose space portion is empty (e.g. "/my-id") results in spaceIDField being set to an empty string. Use RequireSpaceID or DefaultSpaceID to customize that behavior. RequireSpaceID and DefaultSpaceID are mutually exclusive.
func (*KibanaSpaceImporter) DefaultSpaceID ¶ added in v0.16.4
func (s *KibanaSpaceImporter) DefaultSpaceID(spaceID string) *KibanaSpaceImporter
DefaultSpaceID configures the importer to fall back to the given space ID instead of an empty string when the composite import ID omits a space. When the fallback is applied, idField is set to the canonical "<defaultSpaceID>/<resource_id>" form rather than the raw import ID.
Panics if spaceID is empty or RequireSpaceID has already been configured.
func (*KibanaSpaceImporter) ImportState ¶ added in v0.16.4
func (s *KibanaSpaceImporter) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse)
ImportState handles import for Kibana resources with required space-aware composite IDs in the format "<space_id>/<resource_id>".
func (*KibanaSpaceImporter) RequireSpaceID ¶ added in v0.16.4
func (s *KibanaSpaceImporter) RequireSpaceID(summary, detail string) *KibanaSpaceImporter
RequireSpaceID configures the importer to add an error diagnostic (using the given summary and detail) instead of setting spaceIDField to an empty string when the composite import ID omits a space.
Panics if DefaultSpaceID has already been configured.
func (*KibanaSpaceImporter) SeedState ¶ added in v0.16.4
func (s *KibanaSpaceImporter) SeedState(ctx context.Context, resp *resource.ImportStateResponse, importID string, composite *clients.CompositeID)
SeedState applies empty-space policy and sets idField, spaceIDField, and resourceIDFields from an already-parsed composite ID. Callers that need validation before any attributes are written should parse and validate first, then call SeedState.
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.
func SimpleKibanaCreate ¶ added in v0.16.5
func SimpleKibanaCreate[T KibanaResourceModel, Body any, R any]( toBody func(plan T, ctx context.Context) (Body, diag.Diagnostics), apiCreate func(ctx context.Context, client *kibanaoapi.Client, spaceID string, body Body) (*R, diag.Diagnostics), populate func(plan *T, ctx context.Context, spaceID string, resp *R) diag.Diagnostics, ) KibanaWriteFunc[T]
SimpleKibanaCreate returns a KibanaWriteFunc for the common plan -> body -> API create -> populate shape shared by simple Kibana write callbacks: convert the plan to Body via toBody, call apiCreate for req.SpaceID, then apply populate to the plan (typically setting SpaceID, plus any response-derived fields) before wrapping it in KibanaWriteResult. Use for resources whose create callback needs nothing beyond that shape; resources with extra steps (version gates, generated-ID capture) should wrap this in a small function instead of hand-rolling the tail, for example:
func createAgent(ctx context.Context, client *clients.KibanaScopedClient, req entitycore.KibanaWriteRequest[agentModel]) (entitycore.KibanaWriteResult[agentModel], diag.Diagnostics) {
supportsSkillIDs, diags := client.EnforceMinVersion(ctx, agentbuilder.MinExtendedAPIVersion)
if diags.HasError() {
return entitycore.KibanaWriteResult[agentModel]{}, diags
}
return entitycore.SimpleKibanaCreate[agentModel, kbapi.PostAgentBuilderAgentsJSONRequestBody, models.Agent](
func(plan agentModel, ctx context.Context) (kbapi.PostAgentBuilderAgentsJSONRequestBody, diag.Diagnostics) {
return plan.toAPICreateModel(ctx, supportsSkillIDs)
},
kibanaoapi.CreateAgent,
setAgentWriteSpaceID,
)(ctx, client, req)
}
toBody is typically a toAPICreateModel method expression:
Skill.toAPICreateModel
func SimpleKibanaUpdate ¶ added in v0.16.5
func SimpleKibanaUpdate[T KibanaResourceModel, Body any, R any]( toBody func(plan T, ctx context.Context, writeID string) (Body, diag.Diagnostics), apiUpdate func(ctx context.Context, client *kibanaoapi.Client, spaceID, writeID string, body Body) (*R, diag.Diagnostics), populate func(plan *T, ctx context.Context, spaceID string, resp *R) diag.Diagnostics, ) KibanaWriteFunc[T]
SimpleKibanaUpdate is SimpleKibanaCreate's counterpart for Update: it calls apiUpdate with req.SpaceID and req.WriteID instead of apiCreate with req.SpaceID alone, and it passes req.WriteID through to toBody as well, since update bodies commonly need to embed the resource ID being updated. See SimpleKibanaCreate for the shared shape and usage pattern.
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 // SkipReadAfterWrite, when true, persists Model to state without invoking // the read callback after Create/Update and without invoking PostRead. // Use when the write path performed no backend mutation that read-after-write // would reflect (for example a provider-side-only config change). Defaults to // false so normal writes still follow the provider rule that final state comes // from a read request. The envelope still applies timeout preservation on the // committed model (see preserveModelTimeouts). SkipReadAfterWrite bool }
KibanaWriteResult is returned by write callbacks; the envelope read-after-write flow uses Model when resolving refresh identity and calling read.
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, req ElasticsearchPostReadRequest[T], ) (T, diag.Diagnostics)
PostReadFunc runs after a successful read and before state is persisted, including read-after-write refresh. It is optional.
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 ResourceTimeouts ¶ added in v0.16.2
type ResourceTimeouts struct {
Create time.Duration
Read time.Duration
Update time.Duration
Delete time.Duration
}
ResourceTimeouts holds per-operation default durations passed via ElasticsearchResourceOptions or KibanaResourceOptions. Each field that is zero falls back to the matching package constant at envelope call sites: DefaultResourceCreateTimeout, DefaultResourceReadTimeout, DefaultResourceUpdateTimeout, or DefaultResourceDeleteTimeout.
func (ResourceTimeouts) CreateOrDefault ¶ added in v0.16.2
func (rt ResourceTimeouts) CreateOrDefault() time.Duration
CreateOrDefault returns the configured create timeout, or the package default when it is unset (zero). The Read/Update/Delete variants behave identically for their respective operations.
func (ResourceTimeouts) DeleteOrDefault ¶ added in v0.16.2
func (rt ResourceTimeouts) DeleteOrDefault() time.Duration
func (ResourceTimeouts) ReadOrDefault ¶ added in v0.16.2
func (rt ResourceTimeouts) ReadOrDefault() time.Duration
func (ResourceTimeouts) UpdateOrDefault ¶ added in v0.16.2
func (rt ResourceTimeouts) UpdateOrDefault() time.Duration
type ResourceTimeoutsField ¶ added in v0.16.2
ResourceTimeoutsField is an embeddable struct that provides the resource `timeouts` attribute for models used with NewElasticsearchResource or NewKibanaResource. Embedding it satisfies WithResourceTimeouts without requiring the concrete model to redeclare the framework type.
func (ResourceTimeoutsField) GetTimeouts ¶ added in v0.16.2
func (f ResourceTimeoutsField) GetTimeouts() timeouts.Value
GetTimeouts returns the timeouts attribute value.
func (*ResourceTimeoutsField) SetTimeouts ¶ added in v0.16.2
func (f *ResourceTimeoutsField) SetTimeouts(value timeouts.Value)
SetTimeouts stores the envelope-owned timeouts value. It is promoted to the pointer of any model embedding ResourceTimeoutsField, letting the envelope restore the value on callback-returned models without reflection.
type SpaceImporter ¶ added in v0.16.4
type SpaceImporter struct {
// contains filtered or unexported fields
}
SpaceImporter is an embeddable struct that provides a generic ImportState implementation for resources that support space-aware composite IDs and expose the space as a "space_ids" list attribute (the Fleet convention).
When embedded in a resource struct, Go promotes the ImportState method, satisfying resource.ResourceWithImportState without an explicit method.
Usage:
type myResource struct {
*entitycore.SpaceImporter
// ...
}
func newMyResource() *myResource {
return &myResource{
SpaceImporter: entitycore.NewSpaceImporter(path.Root("resource_id")),
}
}
func NewSpaceImporter ¶ added in v0.16.4
func NewSpaceImporter(fields ...path.Path) *SpaceImporter
NewSpaceImporter constructs a SpaceImporter that will set each of the given fields to the resource ID on import. At least one field is required.
func (*SpaceImporter) ImportState ¶ added in v0.16.4
func (s *SpaceImporter) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse)
ImportState handles import for resources with optional space-aware composite IDs.
The import ID may be either:
- A plain resource ID (e.g. "my-policy-id") — sets all idFields to the ID; space_ids is NOT set.
- A composite ID (e.g. "my-space/my-policy-id") — sets all idFields to the resource ID portion and sets space_ids to [spaceID].
type VersionCheck ¶ added in v0.16.4
VersionCheck reports whether a server version satisfies a requirement.
type VersionRequirement ¶ added in v0.15.2
type VersionRequirement struct {
// MinVersion is the minimum server version required. It is ignored when
// VersionCheck is set.
MinVersion version.Version
// VersionCheck supports requirements that cannot be expressed as a single
// minimum version, such as features available in 8.19.x and 9.1.0+ but not
// 9.0.x.
VersionCheck VersionCheck
// AttributePath scopes an unsupported-version diagnostic to the configured
// Terraform attribute. A nil path produces a resource-level diagnostic.
AttributePath *path.Path
// ErrorMessage is the human-readable diagnostic detail.
ErrorMessage string
}
VersionRequirement describes a server version that an entity model requires before the envelope invokes the concrete lifecycle callback.
func NewAttributeVersionCheckRequirement ¶ added in v0.16.4
func NewAttributeVersionCheckRequirement(attr path.Path, check VersionCheck, errorMessage string) VersionRequirement
NewAttributeVersionCheckRequirement creates an attribute-scoped requirement evaluated by check.
func NewAttributeVersionRequirement ¶ added in v0.16.4
func NewAttributeVersionRequirement(attr path.Path, minVersion version.Version, errorMessage string) VersionRequirement
NewAttributeVersionRequirement creates an attribute-scoped minimum-version requirement.
func SingleVersionRequirement ¶ added in v0.16.5
func SingleVersionRequirement(minVersion version.Version, errorMessage string) []VersionRequirement
SingleVersionRequirement builds a one-element resource-level minimum-version requirement slice, for the common case of a model whose GetVersionRequirements has exactly one resource-level requirement.
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 WithResourceTimeouts ¶ added in v0.16.2
WithResourceTimeouts is the timeouts portion of the resource model contract. Concrete resource models satisfy it by embedding ResourceTimeoutsField (or by declaring an equivalent field plus method).
type WithVersionRequirements ¶
type WithVersionRequirements interface {
GetVersionRequirements(ctx context.Context) ([]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
- base_envelope.go
- composite_id.go
- composite_id_importer.go
- computed_state.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
- generic_resource_write.go
- id_attribute.go
- kibana_delete_helpers.go
- kibana_ephemeral_envelope.go
- kibana_read_helpers.go
- kibana_resource_envelope.go
- kibana_unscoped_space.go
- kibana_write_helpers.go
- resource_base.go
- resource_envelope.go
- resource_timeouts.go
- space_importer.go
- version_requirements.go
- write_invocation.go