Skip to content

Commit cbbf6e4

Browse files
committed
feat(monitor): add email_subject support to scheduled query rules alert v2
1 parent 6f5f895 commit cbbf6e4

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

internal/services/monitor/monitor_scheduled_query_rules_alert_v2_resource.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type ScheduledQueryRulesAlertV2Model struct {
4848
type ScheduledQueryRulesAlertV2ActionsModel struct {
4949
ActionGroups []string `tfschema:"action_groups"`
5050
CustomProperties map[string]string `tfschema:"custom_properties"`
51+
EmailSubject string `tfschema:"email_subject"`
5152
}
5253

5354
type ScheduledQueryRulesAlertV2CriteriaModel struct {
@@ -294,6 +295,11 @@ func (r ScheduledQueryRulesAlertV2Resource) Arguments() map[string]*pluginsdk.Sc
294295
Type: pluginsdk.TypeString,
295296
},
296297
},
298+
"email_subject": {
299+
Type: pluginsdk.TypeString,
300+
Optional: true,
301+
ValidateFunc: validation.StringIsNotEmpty,
302+
},
297303
},
298304
},
299305
},
@@ -763,6 +769,16 @@ func expandScheduledQueryRulesAlertV2ActionsModel(inputList []ScheduledQueryRule
763769
CustomProperties: &input.CustomProperties,
764770
}
765771

772+
if input.EmailSubject != "" {
773+
m := map[string]string{
774+
"Email.Subject": input.EmailSubject,
775+
}
776+
output.ActionProperties = &m
777+
} else {
778+
m := map[string]string{}
779+
output.ActionProperties = &m
780+
}
781+
766782
return &output
767783
}
768784

@@ -844,6 +860,12 @@ func flattenScheduledQueryRulesAlertV2ActionsModel(input *scheduledqueryrules.Ac
844860
output.CustomProperties = *input.CustomProperties
845861
}
846862

863+
if input.ActionProperties != nil {
864+
if s, ok := (*input.ActionProperties)["Email.Subject"]; ok {
865+
output.EmailSubject = s
866+
}
867+
}
868+
847869
return append(outputList, output)
848870
}
849871

internal/services/monitor/monitor_scheduled_query_rules_alert_v2_resource_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func TestAccMonitorScheduledQueryRulesAlertV2_complete(t *testing.T) {
5555
Config: r.complete(data),
5656
Check: acceptance.ComposeTestCheckFunc(
5757
check.That(data.ResourceName).ExistsInAzure(r),
58+
check.That(data.ResourceName).Key("action.0.email_subject").HasValue("acctest subject v1"),
5859
),
5960
},
6061
data.ImportStep(),
@@ -69,20 +70,23 @@ func TestAccMonitorScheduledQueryRulesAlertV2_update(t *testing.T) {
6970
Config: r.basic(data),
7071
Check: acceptance.ComposeTestCheckFunc(
7172
check.That(data.ResourceName).ExistsInAzure(r),
73+
check.That(data.ResourceName).Key("action.#").HasValue("0"),
7274
),
7375
},
7476
data.ImportStep(),
7577
{
7678
Config: r.complete(data),
7779
Check: acceptance.ComposeTestCheckFunc(
7880
check.That(data.ResourceName).ExistsInAzure(r),
81+
check.That(data.ResourceName).Key("action.0.email_subject").HasValue("acctest subject v1"),
7982
),
8083
},
8184
data.ImportStep(),
8285
{
8386
Config: r.update(data),
8487
Check: acceptance.ComposeTestCheckFunc(
8588
check.That(data.ResourceName).ExistsInAzure(r),
89+
check.That(data.ResourceName).Key("action.0.email_subject").HasValue("acctest subject v2"),
8690
),
8791
},
8892
data.ImportStep(),
@@ -305,6 +309,7 @@ resource "azurerm_monitor_scheduled_query_rules_alert_v2" "test" {
305309
custom_properties = {
306310
key = "value"
307311
}
312+
email_subject = "acctest subject v1"
308313
}
309314
310315
tags = {
@@ -363,6 +368,7 @@ resource "azurerm_monitor_scheduled_query_rules_alert_v2" "test" {
363368
key = "value"
364369
key2 = "value2"
365370
}
371+
email_subject = "acctest subject v2"
366372
}
367373
368374
tags = {

website/docs/r/monitor_scheduled_query_rules_alert_v2.html.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ resource "azurerm_monitor_scheduled_query_rules_alert_v2" "example" {
8787
key = "value"
8888
key2 = "value2"
8989
}
90+
email_subject = "Email Header"
9091
}
9192
9293
identity {
@@ -164,6 +165,8 @@ An `action` block supports the following:
164165

165166
* `custom_properties` - (Optional) Specifies the properties of an alert payload.
166167

168+
* `email_subject` - (Optional) Custom subject override for all email ids in Azure action group.
169+
167170
---
168171

169172
A `criteria` block supports the following:

0 commit comments

Comments
 (0)