@@ -16,7 +16,10 @@ import (
16
16
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
17
17
)
18
18
19
- var SLOSupportsMultipleGroupByMinVersion = version .Must (version .NewVersion ("8.14.0" ))
19
+ var (
20
+ SLOSupportsMultipleGroupByMinVersion = version .Must (version .NewVersion ("8.14.0" ))
21
+ SLOSupportsDataViewIDMinVersion = version .Must (version .NewVersion ("8.15.0" ))
22
+ )
20
23
21
24
func ResourceSlo () * schema.Resource {
22
25
return & schema.Resource {
@@ -114,6 +117,11 @@ func getSchema() map[string]*schema.Schema {
114
117
Type : schema .TypeString ,
115
118
Required : true ,
116
119
},
120
+ "data_view_id" : {
121
+ Type : schema .TypeString ,
122
+ Optional : true ,
123
+ Description : "Optional data view id to use for this indicator." ,
124
+ },
117
125
"filter" : {
118
126
Type : schema .TypeString ,
119
127
Optional : true ,
@@ -215,6 +223,11 @@ func getSchema() map[string]*schema.Schema {
215
223
Type : schema .TypeString ,
216
224
Required : true ,
217
225
},
226
+ "data_view_id" : {
227
+ Type : schema .TypeString ,
228
+ Optional : true ,
229
+ Description : "Optional data view id to use for this indicator." ,
230
+ },
218
231
"filter" : {
219
232
Type : schema .TypeString ,
220
233
Optional : true ,
@@ -375,6 +388,11 @@ func getSchema() map[string]*schema.Schema {
375
388
Type : schema .TypeString ,
376
389
Required : true ,
377
390
},
391
+ "data_view_id" : {
392
+ Type : schema .TypeString ,
393
+ Optional : true ,
394
+ Description : "Optional data view id to use for this indicator." ,
395
+ },
378
396
"filter" : {
379
397
Type : schema .TypeString ,
380
398
Optional : true ,
@@ -408,6 +426,11 @@ func getSchema() map[string]*schema.Schema {
408
426
Type : schema .TypeString ,
409
427
Required : true ,
410
428
},
429
+ "data_view_id" : {
430
+ Type : schema .TypeString ,
431
+ Optional : true ,
432
+ Description : "Optional data view id to use for this indicator." ,
433
+ },
411
434
"timestamp_field" : {
412
435
Type : schema .TypeString ,
413
436
Required : true ,
@@ -609,7 +632,8 @@ func getSloFromResourceData(d *schema.ResourceData) (models.Slo, diag.Diagnostic
609
632
IndicatorPropertiesCustomKql : & slo.IndicatorPropertiesCustomKql {
610
633
Type : indicatorAddressToType [indicatorType ],
611
634
Params : slo.IndicatorPropertiesCustomKqlParams {
612
- Index : d .Get (indicatorType + ".0.index" ).(string ),
635
+ Index : d .Get (indicatorType + ".0.index" ).(string ),
636
+ DataViewId : getOrNil [string ](indicatorType + ".0.data_view_id" , d ),
613
637
Filter : transformOrNil [slo.KqlWithFilters ](
614
638
indicatorType + ".0.filter" , d ,
615
639
func (v interface {}) slo.KqlWithFilters {
@@ -666,6 +690,7 @@ func getSloFromResourceData(d *schema.ResourceData) (models.Slo, diag.Diagnostic
666
690
Params : slo.IndicatorPropertiesHistogramParams {
667
691
Filter : getOrNil [string ](indicatorType + ".0.filter" , d ),
668
692
Index : d .Get (indicatorType + ".0.index" ).(string ),
693
+ DataViewId : getOrNil [string ](indicatorType + ".0.data_view_id" , d ),
669
694
TimestampField : d .Get (indicatorType + ".0.timestamp_field" ).(string ),
670
695
Good : slo.IndicatorPropertiesHistogramParamsGood {
671
696
Field : d .Get (indicatorType + ".0.good.0.field" ).(string ),
@@ -714,6 +739,7 @@ func getSloFromResourceData(d *schema.ResourceData) (models.Slo, diag.Diagnostic
714
739
Params : slo.IndicatorPropertiesCustomMetricParams {
715
740
Filter : getOrNil [string ](indicatorType + ".0.filter" , d ),
716
741
Index : d .Get (indicatorType + ".0.index" ).(string ),
742
+ DataViewId : getOrNil [string ](indicatorType + ".0.data_view_id" , d ),
717
743
TimestampField : d .Get (indicatorType + ".0.timestamp_field" ).(string ),
718
744
Good : slo.IndicatorPropertiesCustomMetricParamsGood {
719
745
Equation : d .Get (indicatorType + ".0.good.0.equation" ).(string ),
@@ -769,6 +795,7 @@ func getSloFromResourceData(d *schema.ResourceData) (models.Slo, diag.Diagnostic
769
795
Type : indicatorAddressToType [indicatorType ],
770
796
Params : slo.IndicatorPropertiesTimesliceMetricParams {
771
797
Index : params ["index" ].(string ),
798
+ DataViewId : getOrNil [string ]("timeslice_metric_indicator.0.data_view_id" , d ),
772
799
TimestampField : params ["timestamp_field" ].(string ),
773
800
Filter : getOrNil [string ]("timeslice_metric_indicator.0.filter" , d ),
774
801
Metric : slo.IndicatorPropertiesTimesliceMetricParamsMetric {
@@ -850,6 +877,16 @@ func resourceSloCreate(ctx context.Context, d *schema.ResourceData, meta interfa
850
877
return diags
851
878
}
852
879
880
+ // Version check for data_view_id support
881
+ if ! serverVersion .GreaterThanOrEqual (SLOSupportsDataViewIDMinVersion ) {
882
+ // Check all indicator types that support data_view_id
883
+ for _ , indicatorType := range []string {"metric_custom_indicator" , "histogram_custom_indicator" , "kql_custom_indicator" , "timeslice_metric_indicator" } {
884
+ if v , ok := d .GetOk (indicatorType + ".0.data_view_id" ); ok && v != "" {
885
+ return diag .Errorf ("data_view_id is not supported for %s on Elastic Stack versions < %s" , indicatorType , SLOSupportsDataViewIDMinVersion )
886
+ }
887
+ }
888
+ }
889
+
853
890
supportsMultipleGroupBy := serverVersion .GreaterThanOrEqual (SLOSupportsMultipleGroupByMinVersion )
854
891
if len (slo .GroupBy ) > 1 && ! supportsMultipleGroupBy {
855
892
return diag .Errorf ("multiple group_by fields are not supported in this version of the Elastic Stack. Multiple group_by fields requires %s" , SLOSupportsMultipleGroupByMinVersion )
@@ -882,6 +919,15 @@ func resourceSloUpdate(ctx context.Context, d *schema.ResourceData, meta interfa
882
919
return diags
883
920
}
884
921
922
+ // Version check for data_view_id support
923
+ if ! serverVersion .GreaterThanOrEqual (SLOSupportsDataViewIDMinVersion ) {
924
+ for _ , indicatorType := range []string {"metric_custom_indicator" , "histogram_custom_indicator" , "kql_custom_indicator" , "timeslice_metric_indicator" } {
925
+ if v , ok := d .GetOk (indicatorType + ".0.data_view_id" ); ok && v != "" {
926
+ return diag .Errorf ("data_view_id is not supported for %s on Elastic Stack versions < %s" , indicatorType , SLOSupportsDataViewIDMinVersion )
927
+ }
928
+ }
929
+ }
930
+
885
931
supportsMultipleGroupBy := serverVersion .GreaterThanOrEqual (SLOSupportsMultipleGroupByMinVersion )
886
932
if len (slo .GroupBy ) > 1 && ! supportsMultipleGroupBy {
887
933
return diag .Errorf ("multiple group_by fields are not supported in this version of the Elastic Stack. Multiple group_by fields requires %s" , SLOSupportsMultipleGroupByMinVersion )
@@ -950,13 +996,17 @@ func resourceSloRead(ctx context.Context, d *schema.ResourceData, meta interface
950
996
case s .Indicator .IndicatorPropertiesCustomKql != nil :
951
997
indicatorAddress = indicatorTypeToAddress [s .Indicator .IndicatorPropertiesCustomKql .Type ]
952
998
params := s .Indicator .IndicatorPropertiesCustomKql .Params
953
- indicator = append ( indicator , map [string ]interface {}{
999
+ indicatorMap := map [string ]interface {}{
954
1000
"index" : params .Index ,
955
1001
"filter" : params .Filter .String ,
956
1002
"good" : params .Good .String ,
957
1003
"total" : params .Total .String ,
958
1004
"timestamp_field" : params .TimestampField ,
959
- })
1005
+ }
1006
+ if params .DataViewId != nil {
1007
+ indicatorMap ["data_view_id" ] = * params .DataViewId
1008
+ }
1009
+ indicator = append (indicator , indicatorMap )
960
1010
961
1011
case s .Indicator .IndicatorPropertiesHistogram != nil :
962
1012
indicatorAddress = indicatorTypeToAddress [s .Indicator .IndicatorPropertiesHistogram .Type ]
@@ -975,13 +1025,17 @@ func resourceSloRead(ctx context.Context, d *schema.ResourceData, meta interface
975
1025
"from" : params .Total .From ,
976
1026
"to" : params .Total .To ,
977
1027
}}
978
- indicator = append ( indicator , map [string ]interface {}{
1028
+ indicatorMap := map [string ]interface {}{
979
1029
"index" : params .Index ,
980
1030
"filter" : params .Filter ,
981
1031
"timestamp_field" : params .TimestampField ,
982
1032
"good" : good ,
983
1033
"total" : total ,
984
- })
1034
+ }
1035
+ if params .DataViewId != nil {
1036
+ indicatorMap ["data_view_id" ] = * params .DataViewId
1037
+ }
1038
+ indicator = append (indicator , indicatorMap )
985
1039
986
1040
case s .Indicator .IndicatorPropertiesCustomMetric != nil :
987
1041
indicatorAddress = indicatorTypeToAddress [s .Indicator .IndicatorPropertiesCustomMetric .Type ]
@@ -1012,13 +1066,17 @@ func resourceSloRead(ctx context.Context, d *schema.ResourceData, meta interface
1012
1066
"equation" : params .Total .Equation ,
1013
1067
"metrics" : totalMetrics ,
1014
1068
}}
1015
- indicator = append ( indicator , map [string ]interface {}{
1069
+ indicatorMap := map [string ]interface {}{
1016
1070
"index" : params .Index ,
1017
1071
"filter" : params .Filter ,
1018
1072
"timestamp_field" : params .TimestampField ,
1019
1073
"good" : good ,
1020
1074
"total" : total ,
1021
- })
1075
+ }
1076
+ if params .DataViewId != nil {
1077
+ indicatorMap ["data_view_id" ] = * params .DataViewId
1078
+ }
1079
+ indicator = append (indicator , indicatorMap )
1022
1080
1023
1081
case s .Indicator .IndicatorPropertiesTimesliceMetric != nil :
1024
1082
indicatorAddress = indicatorTypeToAddress [s .Indicator .IndicatorPropertiesTimesliceMetric .Type ]
@@ -1049,12 +1107,16 @@ func resourceSloRead(ctx context.Context, d *schema.ResourceData, meta interface
1049
1107
"comparator" : params .Metric .Comparator ,
1050
1108
"threshold" : params .Metric .Threshold ,
1051
1109
}
1052
- indicator = append ( indicator , map [string ]interface {}{
1110
+ indicatorMap := map [string ]interface {}{
1053
1111
"index" : params .Index ,
1054
1112
"timestamp_field" : params .TimestampField ,
1055
1113
"filter" : params .Filter ,
1056
1114
"metric" : []interface {}{metricBlock },
1057
- })
1115
+ }
1116
+ if params .DataViewId != nil {
1117
+ indicatorMap ["data_view_id" ] = * params .DataViewId
1118
+ }
1119
+ indicator = append (indicator , indicatorMap )
1058
1120
1059
1121
default :
1060
1122
return diag .Errorf ("indicator not set" )
0 commit comments