From 6fb6c74cb74169785a5cee4381cb8945486396ae Mon Sep 17 00:00:00 2001 From: "Elena Xin (Centific Technologies Inc)" Date: Tue, 26 Mar 2024 16:52:37 +0800 Subject: [PATCH] fix GH issue 25399 --- .../monitor_alert_prometheus_rule_group_resource.go | 12 ++++++------ ...itor_alert_prometheus_rule_group_resource_test.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/services/monitor/monitor_alert_prometheus_rule_group_resource.go b/internal/services/monitor/monitor_alert_prometheus_rule_group_resource.go index 3c13347436dd..9078b4ee97fd 100644 --- a/internal/services/monitor/monitor_alert_prometheus_rule_group_resource.go +++ b/internal/services/monitor/monitor_alert_prometheus_rule_group_resource.go @@ -293,7 +293,7 @@ func (r AlertPrometheusRuleGroupResource) Create() sdk.ResourceFunc { if _, ok := metadata.ResourceData.GetOk("interval"); ok { properties.Properties.Interval = pointer.To(model.Interval) } - properties.Properties.Rules = expandPrometheusRuleModel(model.Rule) + properties.Properties.Rules = expandPrometheusRuleModel(model.Rule, metadata.ResourceData) if _, err := client.CreateOrUpdate(ctx, id, properties); err != nil { return fmt.Errorf("creating %s: %+v", id, err) @@ -344,7 +344,7 @@ func (r AlertPrometheusRuleGroupResource) Update() sdk.ResourceFunc { properties.Properties.Interval = pointer.To(model.Interval) } if metadata.ResourceData.HasChange("rule") { - properties.Properties.Rules = expandPrometheusRuleModel(model.Rule) + properties.Properties.Rules = expandPrometheusRuleModel(model.Rule, metadata.ResourceData) } if metadata.ResourceData.HasChange("scopes") { properties.Properties.Scopes = model.Scopes @@ -422,10 +422,10 @@ func (r AlertPrometheusRuleGroupResource) Delete() sdk.ResourceFunc { } } -func expandPrometheusRuleModel(inputList []PrometheusRuleModel) []prometheusrulegroups.PrometheusRule { +func expandPrometheusRuleModel(inputList []PrometheusRuleModel, d *schema.ResourceData) []prometheusrulegroups.PrometheusRule { outputList := make([]prometheusrulegroups.PrometheusRule, 0) - for _, v := range inputList { + for i, v := range inputList { output := prometheusrulegroups.PrometheusRule{ Enabled: pointer.To(v.Enabled), Expression: v.Expression, @@ -435,8 +435,8 @@ func expandPrometheusRuleModel(inputList []PrometheusRuleModel) []prometheusrule if v.Alert != "" { output.Actions = expandPrometheusRuleGroupActionModel(v.Action) output.Alert = pointer.To(v.Alert) - if v.Severity != 0 { - output.Severity = pointer.To(int64(v.Severity)) + if v, ok := d.GetOk(fmt.Sprintf("rule.%d.severity", i)); ok { + output.Severity = pointer.To(int64(v.(int))) } output.Annotations = pointer.To(v.Annotations) output.For = pointer.To(v.For) diff --git a/internal/services/monitor/monitor_alert_prometheus_rule_group_resource_test.go b/internal/services/monitor/monitor_alert_prometheus_rule_group_resource_test.go index 7a92781f8830..2fdc40c1e3f9 100644 --- a/internal/services/monitor/monitor_alert_prometheus_rule_group_resource_test.go +++ b/internal/services/monitor/monitor_alert_prometheus_rule_group_resource_test.go @@ -225,7 +225,7 @@ EOF histogram_quantile(0.99, sum(rate(jobs_duration_seconds_bucket{service="billing-processing"}[5m])) by (job_type)) EOF for = "PT5M" - severity = 2 + severity = 0 action { action_group_id = azurerm_monitor_action_group.test.id }