Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 39 additions & 8 deletions provider/plugin_framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package provider

import (
"context"
"os"

"github.com/elastic/terraform-provider-elasticstack/internal/apm/agent_configuration"
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
Expand Down Expand Up @@ -42,6 +43,8 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource"
)

const IncludeExperimentalEnvVar = "TF_ELASTICSTACK_INCLUDE_EXPERIMENTAL"

// Ensure the implementation satisfies the expected interfaces.
var (
_ fwprovider.Provider = &Provider{}
Expand Down Expand Up @@ -92,18 +95,26 @@ func (p *Provider) Configure(ctx context.Context, req fwprovider.ConfigureReques
}

func (p *Provider) DataSources(ctx context.Context) []func() datasource.DataSource {
return []func() datasource.DataSource{
indices.NewDataSource,
spaces.NewDataSource,
export_saved_objects.NewDataSource,
enrollment_tokens.NewDataSource,
integration_ds.NewDataSource,
enrich.NewEnrichPolicyDataSource,
role_mapping.NewRoleMappingDataSource,
datasources := p.dataSources(ctx)

if os.Getenv(IncludeExperimentalEnvVar) == "true" {
datasources = append(datasources, p.experimentalDataSources(ctx)...)
}

return datasources
}

func (p *Provider) Resources(ctx context.Context) []func() resource.Resource {
resources := p.resources(ctx)

if os.Getenv(IncludeExperimentalEnvVar) == "true" {
resources = append(resources, p.experimentalResources(ctx)...)
}

return resources
}

Copy link

Copilot AI Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The resources method should include a comment explaining that it returns stable/non-experimental resources, distinguishing it from experimentalResources.

Suggested change
// resources returns only stable (non-experimental) resources for the provider.
// Experimental resources are returned separately by experimentalResources.

Copilot uses AI. Check for mistakes.
func (p *Provider) resources(ctx context.Context) []func() resource.Resource {
return []func() resource.Resource{
agent_configuration.NewAgentConfigurationResource,
func() resource.Resource { return &import_saved_objects.Resource{} },
Expand Down Expand Up @@ -132,3 +143,23 @@ func (p *Provider) Resources(ctx context.Context) []func() resource.Resource {
datafeed_state.NewMLDatafeedStateResource,
}
}

Copy link

Copilot AI Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The experimentalResources method should include a comment explaining its purpose and when/how experimental resources should be added. This helps future contributors understand where to add experimental features.

Suggested change
// experimentalResources returns a list of experimental resource constructors.
//
// Experimental resources are features that are not yet considered stable and may change or be removed in future releases.
// To add a new experimental resource, append its constructor to the returned slice.
// These resources will only be included in the provider if the environment variable
// TF_ELASTICSTACK_INCLUDE_EXPERIMENTAL is set to "true".
//
// This method helps contributors isolate experimental features from stable ones.

Copilot uses AI. Check for mistakes.
func (p *Provider) experimentalResources(ctx context.Context) []func() resource.Resource {
return []func() resource.Resource{}
}

Copy link

Copilot AI Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dataSources method should include a comment explaining that it returns stable/non-experimental datasources, distinguishing it from experimentalDataSources.

Suggested change
// dataSources returns the list of stable (non-experimental) datasources for the provider.
// Experimental datasources are returned by experimentalDataSources.

Copilot uses AI. Check for mistakes.
func (p *Provider) dataSources(ctx context.Context) []func() datasource.DataSource {
return []func() datasource.DataSource{
indices.NewDataSource,
spaces.NewDataSource,
export_saved_objects.NewDataSource,
enrollment_tokens.NewDataSource,
integration_ds.NewDataSource,
enrich.NewEnrichPolicyDataSource,
role_mapping.NewRoleMappingDataSource,
}
}

Copy link

Copilot AI Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The experimentalDataSources method should include a comment explaining its purpose and when/how experimental datasources should be added. This helps future contributors understand where to add experimental features.

Suggested change
// experimentalDataSources returns a list of experimental datasource constructors.
// Experimental datasources are features that are not yet stable or officially supported.
// To include experimental datasources in the provider, add their constructors to the returned slice.
// These datasources will only be registered if the environment variable TF_ELASTICSTACK_INCLUDE_EXPERIMENTAL is set to "true".
// Future contributors should add new experimental datasources here before they are promoted to stable.

Copilot uses AI. Check for mistakes.
func (p *Provider) experimentalDataSources(ctx context.Context) []func() datasource.DataSource {
return []func() datasource.DataSource{}
}