@@ -2,6 +2,7 @@ package kibana
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
5
6
6
7
"github.com/elastic/terraform-provider-elasticstack/generated/slo"
7
8
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
@@ -541,34 +542,42 @@ func getSloFromResourceData(d *schema.ResourceData) (models.Slo, diag.Diagnostic
541
542
}
542
543
543
544
case "metric_custom_indicator" :
545
+ goodMetricsRaw := d .Get (indicatorType + ".0.good.0.metrics" ).([]interface {})
546
+ var goodMetrics []slo.IndicatorPropertiesCustomMetricParamsGoodMetricsInner
547
+ for n := range goodMetricsRaw {
548
+ idx := fmt .Sprint (n )
549
+ goodMetrics = append (goodMetrics , slo.IndicatorPropertiesCustomMetricParamsGoodMetricsInner {
550
+ Name : d .Get (indicatorType + ".0.good.0.metrics." + idx + ".name" ).(string ),
551
+ Field : d .Get (indicatorType + ".0.good.0.metrics." + idx + ".field" ).(string ),
552
+ Aggregation : d .Get (indicatorType + ".0.good.0.metrics." + idx + ".aggregation" ).(string ),
553
+ Filter : getOrNilString (indicatorType + ".0.good.0.metrics." + idx + ".filter" , d ),
554
+ })
555
+ }
556
+ totalMetricsRaw := d .Get (indicatorType + ".0.total.0.metrics" ).([]interface {})
557
+ var totalMetrics []slo.IndicatorPropertiesCustomMetricParamsTotalMetricsInner
558
+ for n := range totalMetricsRaw {
559
+ idx := fmt .Sprint (n )
560
+ totalMetrics = append (totalMetrics , slo.IndicatorPropertiesCustomMetricParamsTotalMetricsInner {
561
+ Name : d .Get (indicatorType + ".0.total.0.metrics." + idx + ".name" ).(string ),
562
+ Field : d .Get (indicatorType + ".0.total.0.metrics." + idx + ".field" ).(string ),
563
+ Aggregation : d .Get (indicatorType + ".0.total.0.metrics." + idx + ".aggregation" ).(string ),
564
+ Filter : getOrNilString (indicatorType + ".0.total.0.metrics." + idx + ".filter" , d ),
565
+ })
566
+ }
544
567
indicator = slo.SloResponseIndicator {
545
568
IndicatorPropertiesCustomMetric : & slo.IndicatorPropertiesCustomMetric {
546
569
Type : indicatorAddressToType [indicatorType ],
547
570
Params : slo.IndicatorPropertiesCustomMetricParams {
548
571
Filter : getOrNilString (indicatorType + ".0.filter" , d ),
549
572
Index : d .Get (indicatorType + ".0.index" ).(string ),
550
573
TimestampField : d .Get (indicatorType + ".0.timestamp_field" ).(string ),
551
- Total : slo.IndicatorPropertiesCustomMetricParamsTotal {
552
- Equation : d .Get (indicatorType + ".0.total.0.equation" ).(string ),
553
- Metrics : []slo.IndicatorPropertiesCustomMetricParamsTotalMetricsInner { //are there actually instances where there are more than one 'good' / 'total'? Need to build array if so.
554
- {
555
- Name : d .Get (indicatorType + ".0.total.0.metrics.0.name" ).(string ),
556
- Field : d .Get (indicatorType + ".0.total.0.metrics.0.field" ).(string ),
557
- Aggregation : d .Get (indicatorType + ".0.total.0.metrics.0.aggregation" ).(string ),
558
- Filter : getOrNilString (indicatorType + ".0.total.0.metrics.0.filter" , d ),
559
- },
560
- },
561
- },
562
574
Good : slo.IndicatorPropertiesCustomMetricParamsGood {
563
575
Equation : d .Get (indicatorType + ".0.good.0.equation" ).(string ),
564
- Metrics : []slo.IndicatorPropertiesCustomMetricParamsGoodMetricsInner { //are there actually instances where there are more than one 'good' / 'total'? Need to build array if so.
565
- {
566
- Name : d .Get (indicatorType + ".0.good.0.metrics.0.name" ).(string ),
567
- Field : d .Get (indicatorType + ".0.good.0.metrics.0.field" ).(string ),
568
- Aggregation : d .Get (indicatorType + ".0.good.0.metrics.0.aggregation" ).(string ),
569
- Filter : getOrNilString (indicatorType + ".0.good.0.metrics.0.filter" , d ),
570
- },
571
- },
576
+ Metrics : goodMetrics ,
577
+ },
578
+ Total : slo.IndicatorPropertiesCustomMetricParamsTotal {
579
+ Equation : d .Get (indicatorType + ".0.total.0.equation" ).(string ),
580
+ Metrics : totalMetrics ,
572
581
},
573
582
},
574
583
},
@@ -757,23 +766,31 @@ func resourceSloRead(ctx context.Context, d *schema.ResourceData, meta interface
757
766
case s .Indicator .IndicatorPropertiesCustomMetric != nil :
758
767
indicatorAddress = indicatorTypeToAddress [s .Indicator .IndicatorPropertiesCustomMetric .Type ]
759
768
params := s .Indicator .IndicatorPropertiesCustomMetric .Params
769
+ goodMetrics := []map [string ]interface {}{}
770
+ for _ , m := range params .Good .Metrics {
771
+ goodMetrics = append (goodMetrics , map [string ]interface {}{
772
+ "name" : m .Name ,
773
+ "aggregation" : m .Aggregation ,
774
+ "field" : m .Field ,
775
+ "filter" : m .Filter ,
776
+ })
777
+ }
760
778
good := []map [string ]interface {}{{
761
779
"equation" : params .Good .Equation ,
762
- "metrics" : []map [string ]interface {}{{
763
- "name" : params .Good .Metrics [0 ].Name , //this is only getting the first one? Does this really need to be an array?
764
- "aggregation" : params .Good .Metrics [0 ].Aggregation ,
765
- "field" : params .Good .Metrics [0 ].Field ,
766
- "filter" : params .Good .Metrics [0 ].Filter ,
767
- }},
780
+ "metrics" : goodMetrics ,
768
781
}}
782
+ totalMetrics := []map [string ]interface {}{}
783
+ for _ , m := range params .Total .Metrics {
784
+ totalMetrics = append (totalMetrics , map [string ]interface {}{
785
+ "name" : m .Name ,
786
+ "aggregation" : m .Aggregation ,
787
+ "field" : m .Field ,
788
+ "filter" : m .Filter ,
789
+ })
790
+ }
769
791
total := []map [string ]interface {}{{
770
792
"equation" : params .Total .Equation ,
771
- "metrics" : []map [string ]interface {}{{
772
- "name" : params .Total .Metrics [0 ].Name , //this is only getting the first one? Does this really need to be an array?
773
- "aggregation" : params .Total .Metrics [0 ].Aggregation ,
774
- "field" : params .Total .Metrics [0 ].Field ,
775
- "filter" : params .Total .Metrics [0 ].Filter ,
776
- }},
793
+ "metrics" : totalMetrics ,
777
794
}}
778
795
indicator = append (indicator , map [string ]interface {}{
779
796
"index" : params .Index ,
0 commit comments