Skip to content

Commit 0a82d10

Browse files
authored
Only set kql custom indicator filter if it exists (#1354)
* Only set kql custom indicator filter if it exists * Update changelog
1 parent 89b2281 commit 0a82d10

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## [Unreleased]
22

33
- Fix provider crash with `elasticstack_kibana_action_connector` when `config` or `secrets` was unset in 0.11.17 ([#1355](https://github.com/elastic/terraform-provider-elasticstack/pull/1355))
4+
- Fixes provider crash with `elasticstack_kibana_slo` when using `kql_custom_indicator` with no `filter` set.
45

56
## [0.11.18] - 2025-10-10
67

internal/kibana/slo.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,11 +1019,15 @@ func resourceSloRead(ctx context.Context, d *schema.ResourceData, meta interface
10191019
params := s.Indicator.IndicatorPropertiesCustomKql.Params
10201020
indicatorMap := map[string]interface{}{
10211021
"index": params.Index,
1022-
"filter": params.Filter.String,
10231022
"good": params.Good.String,
10241023
"total": params.Total.String,
10251024
"timestamp_field": params.TimestampField,
10261025
}
1026+
1027+
if params.Filter != nil && params.Filter.String != nil {
1028+
indicatorMap["filter"] = params.Filter.String
1029+
}
1030+
10271031
if params.DataViewId != nil {
10281032
indicatorMap["data_view_id"] = *params.DataViewId
10291033
}

internal/kibana/slo_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,58 @@ func TestAccResourceSloValidation(t *testing.T) {
736736
})
737737
}
738738

739+
func TestAccResourceSlo_kql_custom_indicator_basic(t *testing.T) {
740+
sloName := sdkacctest.RandStringFromCharSet(22, sdkacctest.CharSetAlphaNum)
741+
resource.Test(t, resource.TestCase{
742+
PreCheck: func() { acctest.PreCheck(t) },
743+
CheckDestroy: checkResourceSloDestroy,
744+
Steps: []resource.TestStep{
745+
{
746+
ProtoV6ProviderFactories: acctest.Providers,
747+
SkipFunc: versionutils.CheckIfVersionIsUnsupported(sloTimesliceMetricsMinVersion),
748+
Config: fmt.Sprintf(`
749+
provider "elasticstack" {
750+
elasticsearch {}
751+
kibana {}
752+
}
753+
754+
resource "elasticstack_elasticsearch_index" "my_index" {
755+
name = "my-index-%s"
756+
deletion_protection = false
757+
}
758+
resource "elasticstack_kibana_slo" "test_slo" {
759+
name = "%s"
760+
description = "basic kql indicator"
761+
kql_custom_indicator {
762+
index = "my-index-%s"
763+
good = "latency < 300"
764+
total = "*"
765+
timestamp_field = "custom_timestamp"
766+
}
767+
budgeting_method = "timeslices"
768+
objective {
769+
target = 0.95
770+
timeslice_target = 0.95
771+
timeslice_window = "5m"
772+
}
773+
time_window {
774+
duration = "7d"
775+
type = "rolling"
776+
}
777+
depends_on = [elasticstack_elasticsearch_index.my_index]
778+
}
779+
`, sloName, sloName, sloName),
780+
Check: resource.ComposeTestCheckFunc(
781+
resource.TestCheckResourceAttr("elasticstack_kibana_slo.test_slo", "kql_custom_indicator.0.index", "my-index-"+sloName),
782+
resource.TestCheckResourceAttr("elasticstack_kibana_slo.test_slo", "kql_custom_indicator.0.good", "latency < 300"),
783+
resource.TestCheckResourceAttr("elasticstack_kibana_slo.test_slo", "kql_custom_indicator.0.total", "*"),
784+
resource.TestCheckResourceAttr("elasticstack_kibana_slo.test_slo", "kql_custom_indicator.0.timestamp_field", "custom_timestamp"),
785+
),
786+
},
787+
},
788+
})
789+
}
790+
739791
func TestSloIdValidation(t *testing.T) {
740792
resource := kibanaresource.ResourceSlo()
741793
sloIdSchema := resource.Schema["slo_id"]

0 commit comments

Comments
 (0)