Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Migrate `elasticstack_kibana_action_connector` to the Terraform plugin framework ([#1269](https://github.com/elastic/terraform-provider-elasticstack/pull/1269))
- Migrate `elasticstack_elasticsearch_security_role_mapping` resource and data source to Terraform Plugin Framework ([#1279](https://github.com/elastic/terraform-provider-elasticstack/pull/1279))
- Add support for `inactivity_timeout` in `elasticstack_fleet_agent_policy` ([#641](https://github.com/elastic/terraform-provider-elasticstack/issues/641))
- Add support for `prevent_initial_backfill` to `elasticstack_kibana_slo` ([#1071](https://github.com/elastic/terraform-provider-elasticstack/pull/1071))
- [Refactor] Regenerate the SLO client using the current OpenAPI spec ([#1303](https://github.com/elastic/terraform-provider-elasticstack/pull/1303))
- Add support for `data_view_id` in the `elasticstack_kibana_slo` resource ([#1305](https://github.com/elastic/terraform-provider-elasticstack/pull/1305))
- Add support for `unenrollment_timeout` in `elasticstack_fleet_agent_policy` ([#1169](https://github.com/elastic/terraform-provider-elasticstack/issues/1169))
Expand Down
1 change: 1 addition & 0 deletions docs/resources/kibana_slo.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ Optional:
Optional:

- `frequency` (String)
- `prevent_initial_backfill` (Boolean) Prevents the underlying ES transform from attempting to backfill data on start, which can sometimes be resource-intensive or time-consuming and unnecessary
- `sync_delay` (String)


Expand Down
34 changes: 28 additions & 6 deletions internal/kibana/slo.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import (
)

var (
SLOSupportsMultipleGroupByMinVersion = version.Must(version.NewVersion("8.14.0"))
SLOSupportsDataViewIDMinVersion = version.Must(version.NewVersion("8.15.0"))
SLOSupportsMultipleGroupByMinVersion = version.Must(version.NewVersion("8.14.0"))
SLOSupportsPreventInitialBackfillMinVersion = version.Must(version.NewVersion("8.15.0"))
SLOSupportsDataViewIDMinVersion = version.Must(version.NewVersion("8.15.0"))
)

func ResourceSlo() *schema.Resource {
Expand Down Expand Up @@ -565,6 +566,11 @@ func getSchema() map[string]*schema.Schema {
Optional: true,
Computed: true,
},
"prevent_initial_backfill": {
Description: "Prevents the underlying ES transform from attempting to backfill data on start, which can sometimes be resource-intensive or time-consuming and unnecessary",
Type: schema.TypeBool,
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -824,8 +830,9 @@ func getSloFromResourceData(d *schema.ResourceData) (models.Slo, diag.Diagnostic
}

settings := slo.Settings{
SyncDelay: getOrNil[string]("settings.0.sync_delay", d),
Frequency: getOrNil[string]("settings.0.frequency", d),
SyncDelay: getOrNil[string]("settings.0.sync_delay", d),
Frequency: getOrNil[string]("settings.0.frequency", d),
PreventInitialBackfill: getOrNil[bool]("settings.0.prevent_initial_backfill", d),
}

budgetingMethod := slo.BudgetingMethod(d.Get("budgeting_method").(string))
Expand Down Expand Up @@ -877,6 +884,13 @@ func resourceSloCreate(ctx context.Context, d *schema.ResourceData, meta interfa
return diags
}

// Version check for prevent_initial_backfill
if slo.Settings.PreventInitialBackfill != nil {
if !serverVersion.GreaterThanOrEqual(SLOSupportsPreventInitialBackfillMinVersion) {
return diag.Errorf("The 'prevent_initial_backfill' setting requires Elastic Stack version %s or higher.", SLOSupportsPreventInitialBackfillMinVersion)
}
}

// Version check for data_view_id support
if !serverVersion.GreaterThanOrEqual(SLOSupportsDataViewIDMinVersion) {
// Check all indicator types that support data_view_id
Expand Down Expand Up @@ -919,6 +933,13 @@ func resourceSloUpdate(ctx context.Context, d *schema.ResourceData, meta interfa
return diags
}

// Version check for prevent_initial_backfill
if slo.Settings.PreventInitialBackfill != nil {
if !serverVersion.GreaterThanOrEqual(SLOSupportsPreventInitialBackfillMinVersion) {
return diag.Errorf("The 'prevent_initial_backfill' setting requires Elastic Stack version %s or higher.", SLOSupportsPreventInitialBackfillMinVersion)
}
}

// Version check for data_view_id support
if !serverVersion.GreaterThanOrEqual(SLOSupportsDataViewIDMinVersion) {
for _, indicatorType := range []string{"metric_custom_indicator", "histogram_custom_indicator", "kql_custom_indicator", "timeslice_metric_indicator"} {
Expand Down Expand Up @@ -1149,8 +1170,9 @@ func resourceSloRead(ctx context.Context, d *schema.ResourceData, meta interface

if err := d.Set("settings", []interface{}{
map[string]interface{}{
"sync_delay": s.Settings.SyncDelay,
"frequency": s.Settings.Frequency,
"sync_delay": s.Settings.SyncDelay,
"frequency": s.Settings.Frequency,
"prevent_initial_backfill": s.Settings.PreventInitialBackfill,
},
}); err != nil {
return diag.FromErr(err)
Expand Down
50 changes: 41 additions & 9 deletions internal/kibana/slo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,32 @@ func TestAccResourceSloGroupBy(t *testing.T) {
})
}

func TestAccResourceSloPreventInitialBackfill(t *testing.T) {
sloName := sdkacctest.RandStringFromCharSet(22, sdkacctest.CharSetAlphaNum)
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
CheckDestroy: checkResourceSloDestroy,
ProtoV6ProviderFactories: acctest.Providers,
Steps: []resource.TestStep{
{
SkipFunc: versionutils.CheckIfVersionIsUnsupported(kibanaresource.SLOSupportsPreventInitialBackfillMinVersion),
Config: getSLOConfig(sloVars{
name: sloName,
indicatorType: "metric_custom_indicator",
settingsEnabled: true,
groupBy: []string{"some.field", "some.other.field"},
includePreventInitialBackfill: true,
}),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("elasticstack_kibana_slo.test_slo", "metric_custom_indicator.0.index", "my-index-"+sloName),

resource.TestCheckResourceAttr("elasticstack_kibana_slo.test_slo", "settings.0.prevent_initial_backfill", "true"),
),
},
},
})
}

func TestAccResourceSlo_timeslice_metric_indicator_basic(t *testing.T) {
sloName := sdkacctest.RandStringFromCharSet(22, sdkacctest.CharSetAlphaNum)
resource.Test(t, resource.TestCase{
Expand Down Expand Up @@ -793,24 +819,30 @@ func checkResourceSloDestroy(s *terraform.State) error {
}

type sloVars struct {
name string
indicatorType string
settingsEnabled bool
tags []string
groupBy []string
useSingleElementGroupBy bool
includeDataViewID bool
name string
indicatorType string
settingsEnabled bool
tags []string
groupBy []string
useSingleElementGroupBy bool
includeDataViewID bool
includePreventInitialBackfill bool
}

func getSLOConfig(vars sloVars) string {
var settings string
if vars.settingsEnabled {
settings = `
preventInitialBackfill := ""
if vars.includePreventInitialBackfill {
preventInitialBackfill = "prevent_initial_backfill = true"
}
settings = fmt.Sprintf(`
settings {
sync_delay = "5m"
frequency = "5m"
%s
}
`
`, preventInitialBackfill)
} else {
settings = ""
}
Expand Down