diff --git a/CHANGELOG.md b/CHANGELOG.md index 77f88e222..91197a939 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ - Add support for `timeslice_metric_indicator` in `elasticstack_kibana_slo` ([#1195](https://github.com/elastic/terraform-provider-elasticstack/pull/1195)) - Add `elasticstack_elasticsearch_ingest_processor_reroute` data source ([#678](https://github.com/elastic/terraform-provider-elasticstack/issues/678)) +- Add support for `supports_agentless` to `elasticstack_fleet_agent_policy` ([#1197](https://github.com/elastic/terraform-provider-elasticstack/pull/1197)) +- Ignore `master_timeout` when targeting Serverless projects ([#1207](https://github.com/elastic/terraform-provider-elasticstack/pull/1207)) ## [0.11.16] - 2025-07-09 diff --git a/docs/resources/fleet_agent_policy.md b/docs/resources/fleet_agent_policy.md index 0420a8c33..9eb4d4ea7 100644 --- a/docs/resources/fleet_agent_policy.md +++ b/docs/resources/fleet_agent_policy.md @@ -56,6 +56,7 @@ resource "elasticstack_fleet_agent_policy" "test_policy" { - `monitoring_output_id` (String) The identifier for monitoring output. - `policy_id` (String) Unique identifier of the agent policy. - `skip_destroy` (Boolean) Set to true if you do not wish the agent policy to be deleted at destroy time, and instead just remove the agent policy from the Terraform state. +- `supports_agentless` (Boolean) Set to true to enable agentless data collection. - `sys_monitoring` (Boolean) Enable collection of system logs and metrics. ### Read-Only diff --git a/internal/clients/api_client.go b/internal/clients/api_client.go index 6653d7fdd..d2cdee505 100644 --- a/internal/clients/api_client.go +++ b/internal/clients/api_client.go @@ -33,6 +33,8 @@ type CompositeId struct { ResourceId string } +const ServerlessFlavor = "serverless" + func CompositeIdFromStr(id string) (*CompositeId, diag.Diagnostics) { var diags diag.Diagnostics idParts := strings.Split(id, "/") @@ -352,6 +354,24 @@ func (a *ApiClient) serverInfo(ctx context.Context) (*models.ClusterInfo, diag.D return &info, diags } +func (a *ApiClient) EnforceMinVersion(ctx context.Context, minVersion *version.Version) (bool, diag.Diagnostics) { + flavor, diags := a.ServerFlavor(ctx) + if diags.HasError() { + return false, diags + } + + if flavor == ServerlessFlavor { + return true, nil + } + + serverVersion, diags := a.ServerVersion(ctx) + if diags.HasError() { + return false, diags + } + + return serverVersion.GreaterThanOrEqual(minVersion), nil +} + func (a *ApiClient) ServerVersion(ctx context.Context) (*version.Version, diag.Diagnostics) { if a.elasticsearch != nil { return a.versionFromElasticsearch(ctx) diff --git a/internal/elasticsearch/index/index/models.go b/internal/elasticsearch/index/index/models.go index d776f09f4..e4b018ee5 100644 --- a/internal/elasticsearch/index/index/models.go +++ b/internal/elasticsearch/index/index/models.go @@ -289,7 +289,7 @@ func (model tfModel) toPutIndexParams(serverFlavor string) models.PutIndexParams Timeout: timeout, } - if serverFlavor != "serverless" { + if serverFlavor != clients.ServerlessFlavor { params.MasterTimeout = masterTimeout params.WaitForActiveShards = model.WaitForActiveShards.ValueString() } diff --git a/internal/elasticsearch/index/index/models_test.go b/internal/elasticsearch/index/index/models_test.go index d91398799..376113af8 100644 --- a/internal/elasticsearch/index/index/models_test.go +++ b/internal/elasticsearch/index/index/models_test.go @@ -7,6 +7,7 @@ import ( fuzz "github.com/google/gofuzz" + "github.com/elastic/terraform-provider-elasticstack/internal/clients" "github.com/elastic/terraform-provider-elasticstack/internal/models" "github.com/elastic/terraform-provider-elasticstack/internal/utils/customtypes" "github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes" @@ -363,7 +364,7 @@ func Test_tfModel_toPutIndexParams(t *testing.T) { flavor := "not_serverless" if isServerless { - flavor = "serverless" + flavor = clients.ServerlessFlavor expectedParams.WaitForActiveShards = "" expectedParams.MasterTimeout = 0 } diff --git a/internal/fleet/agent_policy/create.go b/internal/fleet/agent_policy/create.go index b07b6a607..aaa7996a3 100644 --- a/internal/fleet/agent_policy/create.go +++ b/internal/fleet/agent_policy/create.go @@ -22,12 +22,13 @@ func (r *agentPolicyResource) Create(ctx context.Context, req resource.CreateReq return } - sVersion, e := r.client.ServerVersion(ctx) - if e != nil { + feat, diags := r.buildFeatures(ctx) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { return } - body, diags := planModel.toAPICreateModel(ctx, sVersion) + body, diags := planModel.toAPICreateModel(ctx, feat) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { return diff --git a/internal/fleet/agent_policy/models.go b/internal/fleet/agent_policy/models.go index 6ff4b7b81..1fddf95cd 100644 --- a/internal/fleet/agent_policy/models.go +++ b/internal/fleet/agent_policy/models.go @@ -8,13 +8,17 @@ import ( "github.com/elastic/terraform-provider-elasticstack/generated/kbapi" "github.com/elastic/terraform-provider-elasticstack/internal/utils" - "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/types" ) +type features struct { + SupportsGlobalDataTags bool + SupportsSupportsAgentless bool +} + type globalDataTagsItemModel struct { StringValue types.String `tfsdk:"string_value"` NumberValue types.Float32 `tfsdk:"number_value"` @@ -34,6 +38,7 @@ type agentPolicyModel struct { MonitorMetrics types.Bool `tfsdk:"monitor_metrics"` SysMonitoring types.Bool `tfsdk:"sys_monitoring"` SkipDestroy types.Bool `tfsdk:"skip_destroy"` + SupportsAgentless types.Bool `tfsdk:"supports_agentless"` GlobalDataTags types.Map `tfsdk:"global_data_tags"` //> globalDataTagsModel } @@ -67,6 +72,7 @@ func (model *agentPolicyModel) populateFromAPI(ctx context.Context, data *kbapi. model.MonitoringOutputId = types.StringPointerValue(data.MonitoringOutputId) model.Name = types.StringValue(data.Name) model.Namespace = types.StringValue(data.Namespace) + model.SupportsAgentless = types.BoolPointerValue(data.SupportsAgentless) if utils.Deref(data.GlobalDataTags) != nil { diags := diag.Diagnostics{} var map0 = make(map[string]globalDataTagsItemModel) @@ -99,18 +105,18 @@ func (model *agentPolicyModel) populateFromAPI(ctx context.Context, data *kbapi. // convertGlobalDataTags converts the global data tags from terraform model to API model // and performs version validation -func (model *agentPolicyModel) convertGlobalDataTags(ctx context.Context, serverVersion *version.Version) (*[]kbapi.AgentPolicyGlobalDataTagsItem, diag.Diagnostics) { +func (model *agentPolicyModel) convertGlobalDataTags(ctx context.Context, feat features) (*[]kbapi.AgentPolicyGlobalDataTagsItem, diag.Diagnostics) { var diags diag.Diagnostics if len(model.GlobalDataTags.Elements()) == 0 { - if serverVersion.GreaterThanOrEqual(MinVersionGlobalDataTags) { + if feat.SupportsGlobalDataTags { emptyList := make([]kbapi.AgentPolicyGlobalDataTagsItem, 0) return &emptyList, diags } return nil, diags } - if serverVersion.LessThan(MinVersionGlobalDataTags) { + if !feat.SupportsGlobalDataTags { diags.AddError("global_data_tags ES version error", fmt.Sprintf("Global data tags are only supported in Elastic Stack %s and above", MinVersionGlobalDataTags)) return nil, diags } @@ -146,7 +152,7 @@ func (model *agentPolicyModel) convertGlobalDataTags(ctx context.Context, server return &itemsList, diags } -func (model *agentPolicyModel) toAPICreateModel(ctx context.Context, serverVersion *version.Version) (kbapi.PostFleetAgentPoliciesJSONRequestBody, diag.Diagnostics) { +func (model *agentPolicyModel) toAPICreateModel(ctx context.Context, feat features) (kbapi.PostFleetAgentPoliciesJSONRequestBody, diag.Diagnostics) { monitoring := make([]kbapi.PostFleetAgentPoliciesJSONBodyMonitoringEnabled, 0, 2) if model.MonitorLogs.ValueBool() { @@ -156,6 +162,16 @@ func (model *agentPolicyModel) toAPICreateModel(ctx context.Context, serverVersi monitoring = append(monitoring, kbapi.PostFleetAgentPoliciesJSONBodyMonitoringEnabledMetrics) } + if utils.IsKnown(model.SupportsAgentless) && !feat.SupportsSupportsAgentless { + return kbapi.PostFleetAgentPoliciesJSONRequestBody{}, diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("supports_agentless"), + "Unsupported Elasticsearch version", + fmt.Sprintf("Supports agentless is only supported in Elastic Stack %s and above", MinSupportsAgentlessVersion), + ), + } + } + body := kbapi.PostFleetAgentPoliciesJSONRequestBody{ DataOutputId: model.DataOutputId.ValueStringPointer(), Description: model.Description.ValueStringPointer(), @@ -166,9 +182,10 @@ func (model *agentPolicyModel) toAPICreateModel(ctx context.Context, serverVersi MonitoringOutputId: model.MonitoringOutputId.ValueStringPointer(), Name: model.Name.ValueString(), Namespace: model.Namespace.ValueString(), + SupportsAgentless: model.SupportsAgentless.ValueBoolPointer(), } - tags, diags := model.convertGlobalDataTags(ctx, serverVersion) + tags, diags := model.convertGlobalDataTags(ctx, feat) if diags.HasError() { return kbapi.PostFleetAgentPoliciesJSONRequestBody{}, diags } @@ -177,7 +194,7 @@ func (model *agentPolicyModel) toAPICreateModel(ctx context.Context, serverVersi return body, nil } -func (model *agentPolicyModel) toAPIUpdateModel(ctx context.Context, serverVersion *version.Version) (kbapi.PutFleetAgentPoliciesAgentpolicyidJSONRequestBody, diag.Diagnostics) { +func (model *agentPolicyModel) toAPIUpdateModel(ctx context.Context, feat features) (kbapi.PutFleetAgentPoliciesAgentpolicyidJSONRequestBody, diag.Diagnostics) { monitoring := make([]kbapi.PutFleetAgentPoliciesAgentpolicyidJSONBodyMonitoringEnabled, 0, 2) if model.MonitorLogs.ValueBool() { monitoring = append(monitoring, kbapi.Logs) @@ -186,6 +203,16 @@ func (model *agentPolicyModel) toAPIUpdateModel(ctx context.Context, serverVersi monitoring = append(monitoring, kbapi.Metrics) } + if utils.IsKnown(model.SupportsAgentless) && !feat.SupportsSupportsAgentless { + return kbapi.PutFleetAgentPoliciesAgentpolicyidJSONRequestBody{}, diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("supports_agentless"), + "Unsupported Elasticsearch version", + fmt.Sprintf("Supports agentless is only supported in Elastic Stack %s and above", MinSupportsAgentlessVersion), + ), + } + } + body := kbapi.PutFleetAgentPoliciesAgentpolicyidJSONRequestBody{ DataOutputId: model.DataOutputId.ValueStringPointer(), Description: model.Description.ValueStringPointer(), @@ -195,9 +222,10 @@ func (model *agentPolicyModel) toAPIUpdateModel(ctx context.Context, serverVersi MonitoringOutputId: model.MonitoringOutputId.ValueStringPointer(), Name: model.Name.ValueString(), Namespace: model.Namespace.ValueString(), + SupportsAgentless: model.SupportsAgentless.ValueBoolPointer(), } - tags, diags := model.convertGlobalDataTags(ctx, serverVersion) + tags, diags := model.convertGlobalDataTags(ctx, feat) if diags.HasError() { return kbapi.PutFleetAgentPoliciesAgentpolicyidJSONRequestBody{}, diags } diff --git a/internal/fleet/agent_policy/resource.go b/internal/fleet/agent_policy/resource.go index 917bec042..34e4a3cf4 100644 --- a/internal/fleet/agent_policy/resource.go +++ b/internal/fleet/agent_policy/resource.go @@ -5,7 +5,9 @@ import ( "fmt" "github.com/elastic/terraform-provider-elasticstack/internal/clients" + "github.com/elastic/terraform-provider-elasticstack/internal/utils" "github.com/hashicorp/go-version" + "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" ) @@ -16,7 +18,10 @@ var ( _ resource.ResourceWithImportState = &agentPolicyResource{} ) -var MinVersionGlobalDataTags = version.Must(version.NewVersion("8.15.0")) +var ( + MinVersionGlobalDataTags = version.Must(version.NewVersion("8.15.0")) + MinSupportsAgentlessVersion = version.Must(version.NewVersion("8.15.0")) +) // NewResource is a helper function to simplify the provider implementation. func NewResource() resource.Resource { @@ -40,3 +45,20 @@ func (r *agentPolicyResource) Metadata(ctx context.Context, req resource.Metadat func (r *agentPolicyResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { resource.ImportStatePassthroughID(ctx, path.Root("policy_id"), req, resp) } + +func (r *agentPolicyResource) buildFeatures(ctx context.Context) (features, diag.Diagnostics) { + supportsGDT, diags := r.client.EnforceMinVersion(ctx, MinVersionGlobalDataTags) + if diags.HasError() { + return features{}, utils.FrameworkDiagsFromSDK(diags) + } + + supportsSupportsAgentless, diags := r.client.EnforceMinVersion(ctx, MinSupportsAgentlessVersion) + if diags.HasError() { + return features{}, utils.FrameworkDiagsFromSDK(diags) + } + + return features{ + SupportsGlobalDataTags: supportsGDT, + SupportsSupportsAgentless: supportsSupportsAgentless, + }, nil +} diff --git a/internal/fleet/agent_policy/resource_test.go b/internal/fleet/agent_policy/resource_test.go index a8b183123..e45ab4812 100644 --- a/internal/fleet/agent_policy/resource_test.go +++ b/internal/fleet/agent_policy/resource_test.go @@ -10,6 +10,7 @@ import ( "github.com/elastic/terraform-provider-elasticstack/internal/acctest" "github.com/elastic/terraform-provider-elasticstack/internal/clients" "github.com/elastic/terraform-provider-elasticstack/internal/clients/fleet" + "github.com/elastic/terraform-provider-elasticstack/internal/fleet/agent_policy" "github.com/elastic/terraform-provider-elasticstack/internal/utils" "github.com/elastic/terraform-provider-elasticstack/internal/versionutils" "github.com/hashicorp/go-version" @@ -19,7 +20,6 @@ import ( ) var minVersionAgentPolicy = version.Must(version.NewVersion("8.6.0")) -var minVersionGlobalDataTags = version.Must(version.NewVersion("8.15.0")) func TestAccResourceAgentPolicyFromSDK(t *testing.T) { policyName := sdkacctest.RandStringFromCharSet(22, sdkacctest.CharSetAlphaNum) @@ -95,6 +95,27 @@ func TestAccResourceAgentPolicy(t *testing.T) { }), ), }, + { + SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionAgentPolicy), + Config: testAccResourceAgentPolicyCreate(policyName, false), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "name", fmt.Sprintf("Policy %s", policyName)), + resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "namespace", "default"), + resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "description", "Test Agent Policy"), + resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "monitor_logs", "true"), + resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "monitor_metrics", "false"), + resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "skip_destroy", "false"), + resource.TestCheckResourceAttrWith("elasticstack_fleet_agent_policy.test_policy", "policy_id", func(value string) error { + originalPolicyId = value + + if len(value) == 0 { + return errors.New("expected policy_id to be non empty") + } + + return nil + }), + ), + }, { SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionAgentPolicy), Config: testAccResourceAgentPolicyUpdate(policyName, false), @@ -123,7 +144,7 @@ func TestAccResourceAgentPolicy(t *testing.T) { ImportStateVerifyIgnore: []string{"skip_destroy"}, }, { - SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionGlobalDataTags), + SkipFunc: versionutils.CheckIfVersionIsUnsupported(agent_policy.MinVersionGlobalDataTags), Config: testAccResourceAgentPolicyCreateWithGlobalDataTags(policyNameGlobalDataTags, false), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "name", fmt.Sprintf("Policy %s", policyNameGlobalDataTags)), @@ -137,7 +158,7 @@ func TestAccResourceAgentPolicy(t *testing.T) { ), }, { - SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionGlobalDataTags), + SkipFunc: versionutils.CheckIfVersionIsUnsupported(agent_policy.MinVersionGlobalDataTags), Config: testAccResourceAgentPolicyUpdateWithGlobalDataTags(policyNameGlobalDataTags, false), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "name", fmt.Sprintf("Updated Policy %s", policyNameGlobalDataTags)), @@ -151,7 +172,7 @@ func TestAccResourceAgentPolicy(t *testing.T) { ), }, { - SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionGlobalDataTags), + SkipFunc: versionutils.CheckIfVersionIsUnsupported(agent_policy.MinVersionGlobalDataTags), Config: testAccResourceAgentPolicyUpdateWithNoGlobalDataTags(policyNameGlobalDataTags, false), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "name", fmt.Sprintf("Updated Policy %s", policyNameGlobalDataTags)), @@ -163,6 +184,19 @@ func TestAccResourceAgentPolicy(t *testing.T) { resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "global_data_tags.#", "0"), ), }, + { + SkipFunc: versionutils.CheckIfNotServerless(), + Config: testAccResourceAgentPolicyUpdateWithSupportsAgentless(policyNameGlobalDataTags, false), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "name", fmt.Sprintf("Updated Policy %s", policyNameGlobalDataTags)), + resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "namespace", "default"), + resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "description", "This policy was updated with supports_agentless"), + resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "monitor_logs", "false"), + resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "monitor_metrics", "true"), + resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "skip_destroy", "false"), + resource.TestCheckResourceAttr("elasticstack_fleet_agent_policy.test_policy", "supports_agentless", "true"), + ), + }, }, }) } @@ -199,7 +233,7 @@ func TestAccResourceAgentPolicyWithBadGlobalDataTags(t *testing.T) { ProtoV6ProviderFactories: acctest.Providers, Steps: []resource.TestStep{ { - SkipFunc: versionutils.CheckIfVersionIsUnsupported(minVersionGlobalDataTags), + SkipFunc: versionutils.CheckIfVersionIsUnsupported(agent_policy.MinVersionGlobalDataTags), Config: testAccResourceAgentPolicyCreateWithBadGlobalDataTags(policyName, true), ExpectError: regexp.MustCompile(".*Error: Invalid Attribute Combination.*"), }, @@ -229,6 +263,7 @@ data "elasticstack_fleet_enrollment_tokens" "test_policy" { `, fmt.Sprintf("Policy %s", id), skipDestroy) } + func testAccResourceAgentPolicyCreateWithGlobalDataTags(id string, skipDestroy bool) string { return fmt.Sprintf(` provider "elasticstack" { @@ -337,6 +372,29 @@ data "elasticstack_fleet_enrollment_tokens" "test_policy" { `, fmt.Sprintf("Updated Policy %s", id), skipDestroy) } +func testAccResourceAgentPolicyUpdateWithSupportsAgentless(id string, skipDestroy bool) string { + return fmt.Sprintf(` +provider "elasticstack" { + elasticsearch {} + kibana {} +} + +resource "elasticstack_fleet_agent_policy" "test_policy" { + name = "%s" + namespace = "default" + description = "This policy was updated with supports_agentless" + monitor_logs = false + monitor_metrics = true + skip_destroy = %t + supports_agentless = true +} + +data "elasticstack_fleet_enrollment_tokens" "test_policy" { + policy_id = elasticstack_fleet_agent_policy.test_policy.policy_id +} +`, fmt.Sprintf("Updated Policy %s", id), skipDestroy) +} + func testAccResourceAgentPolicyUpdate(id string, skipDestroy bool) string { return fmt.Sprintf(` provider "elasticstack" { diff --git a/internal/fleet/agent_policy/schema.go b/internal/fleet/agent_policy/schema.go index c6fc0b812..f1c531a29 100644 --- a/internal/fleet/agent_policy/schema.go +++ b/internal/fleet/agent_policy/schema.go @@ -86,6 +86,10 @@ func getSchema() schema.Schema { Description: "Set to true if you do not wish the agent policy to be deleted at destroy time, and instead just remove the agent policy from the Terraform state.", Optional: true, }, + "supports_agentless": schema.BoolAttribute{ + Description: "Set to true to enable agentless data collection.", + Optional: true, + }, "sys_monitoring": schema.BoolAttribute{ Description: "Enable collection of system logs and metrics.", Optional: true, diff --git a/internal/fleet/agent_policy/update.go b/internal/fleet/agent_policy/update.go index 9f26c58ad..2eba03ec4 100644 --- a/internal/fleet/agent_policy/update.go +++ b/internal/fleet/agent_policy/update.go @@ -22,15 +22,13 @@ func (r *agentPolicyResource) Update(ctx context.Context, req resource.UpdateReq return } - sVersion, e := r.client.ServerVersion(ctx) - if e != nil { - for _, a := range e { - resp.Diagnostics.AddError(a.Summary, a.Detail) - } + feat, diags := r.buildFeatures(ctx) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { return } - body, diags := planModel.toAPIUpdateModel(ctx, sVersion) + body, diags := planModel.toAPIUpdateModel(ctx, feat) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { diff --git a/internal/versionutils/testutils.go b/internal/versionutils/testutils.go index 22167dc6d..e2aec0438 100644 --- a/internal/versionutils/testutils.go +++ b/internal/versionutils/testutils.go @@ -37,3 +37,18 @@ func CheckIfVersionMeetsConstraints(constraints version.Constraints) func() (boo return !constraints.Check(serverVersion), nil } } + +func CheckIfNotServerless() func() (bool, error) { + return func() (b bool, err error) { + client, err := clients.NewAcceptanceTestingClient() + if err != nil { + return false, err + } + serverFlavor, diags := client.ServerFlavor(context.Background()) + if diags.HasError() { + return false, fmt.Errorf("failed to get the elasticsearch flavor %v", diags) + } + + return serverFlavor != clients.ServerlessFlavor, nil + } +}