Skip to content

Commit

Permalink
fix GH issue 25399
Browse files Browse the repository at this point in the history
  • Loading branch information
sinbai committed Mar 27, 2024
1 parent 7709fe9 commit 6fb6c74
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 6fb6c74

Please sign in to comment.