Skip to content

Commit 9a6e683

Browse files
modular-magicianJames Edouard
and
James Edouard
authored
Add support for retriggering notifications in AlertPolicy (#7895) (#14563)
Signed-off-by: Modular Magician <[email protected]> Co-authored-by: James Edouard <[email protected]>
1 parent 07b84fb commit 9a6e683

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

.changelog/7895.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:REPLACEME
2+
3+
```

google/resource_monitoring_alert_policy.go

+99
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,32 @@ name is limited to 512 Unicode characters.`,
745745
Optional: true,
746746
Description: `If an alert policy that was active has no data for this long, any open incidents will close.`,
747747
},
748+
"notification_channel_strategy": {
749+
Type: schema.TypeList,
750+
Optional: true,
751+
Description: `Control over how the notification channels in 'notification_channels'
752+
are notified when this alert fires, on a per-channel basis.`,
753+
Elem: &schema.Resource{
754+
Schema: map[string]*schema.Schema{
755+
"notification_channel_names": {
756+
Type: schema.TypeList,
757+
Optional: true,
758+
Description: `The notification channels that these settings apply to. Each of these
759+
correspond to the name field in one of the NotificationChannel objects
760+
referenced in the notification_channels field of this AlertPolicy. The format is
761+
'projects/[PROJECT_ID_OR_NUMBER]/notificationChannels/[CHANNEL_ID]'`,
762+
Elem: &schema.Schema{
763+
Type: schema.TypeString,
764+
},
765+
},
766+
"renotify_interval": {
767+
Type: schema.TypeString,
768+
Optional: true,
769+
Description: `The frequency at which to send reminder notifications for open incidents.`,
770+
},
771+
},
772+
},
773+
},
748774
"notification_rate_limit": {
749775
Type: schema.TypeList,
750776
Optional: true,
@@ -1682,6 +1708,8 @@ func flattenMonitoringAlertPolicyAlertStrategy(v interface{}, d *schema.Resource
16821708
flattenMonitoringAlertPolicyAlertStrategyNotificationRateLimit(original["notificationRateLimit"], d, config)
16831709
transformed["auto_close"] =
16841710
flattenMonitoringAlertPolicyAlertStrategyAutoClose(original["autoClose"], d, config)
1711+
transformed["notification_channel_strategy"] =
1712+
flattenMonitoringAlertPolicyAlertStrategyNotificationChannelStrategy(original["notificationChannelStrategy"], d, config)
16851713
return []interface{}{transformed}
16861714
}
16871715
func flattenMonitoringAlertPolicyAlertStrategyNotificationRateLimit(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
@@ -1705,6 +1733,33 @@ func flattenMonitoringAlertPolicyAlertStrategyAutoClose(v interface{}, d *schema
17051733
return v
17061734
}
17071735

1736+
func flattenMonitoringAlertPolicyAlertStrategyNotificationChannelStrategy(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1737+
if v == nil {
1738+
return v
1739+
}
1740+
l := v.([]interface{})
1741+
transformed := make([]interface{}, 0, len(l))
1742+
for _, raw := range l {
1743+
original := raw.(map[string]interface{})
1744+
if len(original) < 1 {
1745+
// Do not include empty json objects coming back from the api
1746+
continue
1747+
}
1748+
transformed = append(transformed, map[string]interface{}{
1749+
"notification_channel_names": flattenMonitoringAlertPolicyAlertStrategyNotificationChannelStrategyNotificationChannelNames(original["notificationChannelNames"], d, config),
1750+
"renotify_interval": flattenMonitoringAlertPolicyAlertStrategyNotificationChannelStrategyRenotifyInterval(original["renotifyInterval"], d, config),
1751+
})
1752+
}
1753+
return transformed
1754+
}
1755+
func flattenMonitoringAlertPolicyAlertStrategyNotificationChannelStrategyNotificationChannelNames(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1756+
return v
1757+
}
1758+
1759+
func flattenMonitoringAlertPolicyAlertStrategyNotificationChannelStrategyRenotifyInterval(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1760+
return v
1761+
}
1762+
17081763
func flattenMonitoringAlertPolicyUserLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
17091764
return v
17101765
}
@@ -2355,6 +2410,13 @@ func expandMonitoringAlertPolicyAlertStrategy(v interface{}, d tpgresource.Terra
23552410
transformed["autoClose"] = transformedAutoClose
23562411
}
23572412

2413+
transformedNotificationChannelStrategy, err := expandMonitoringAlertPolicyAlertStrategyNotificationChannelStrategy(original["notification_channel_strategy"], d, config)
2414+
if err != nil {
2415+
return nil, err
2416+
} else if val := reflect.ValueOf(transformedNotificationChannelStrategy); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2417+
transformed["notificationChannelStrategy"] = transformedNotificationChannelStrategy
2418+
}
2419+
23582420
return transformed, nil
23592421
}
23602422

@@ -2385,6 +2447,43 @@ func expandMonitoringAlertPolicyAlertStrategyAutoClose(v interface{}, d tpgresou
23852447
return v, nil
23862448
}
23872449

2450+
func expandMonitoringAlertPolicyAlertStrategyNotificationChannelStrategy(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2451+
l := v.([]interface{})
2452+
req := make([]interface{}, 0, len(l))
2453+
for _, raw := range l {
2454+
if raw == nil {
2455+
continue
2456+
}
2457+
original := raw.(map[string]interface{})
2458+
transformed := make(map[string]interface{})
2459+
2460+
transformedNotificationChannelNames, err := expandMonitoringAlertPolicyAlertStrategyNotificationChannelStrategyNotificationChannelNames(original["notification_channel_names"], d, config)
2461+
if err != nil {
2462+
return nil, err
2463+
} else if val := reflect.ValueOf(transformedNotificationChannelNames); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2464+
transformed["notificationChannelNames"] = transformedNotificationChannelNames
2465+
}
2466+
2467+
transformedRenotifyInterval, err := expandMonitoringAlertPolicyAlertStrategyNotificationChannelStrategyRenotifyInterval(original["renotify_interval"], d, config)
2468+
if err != nil {
2469+
return nil, err
2470+
} else if val := reflect.ValueOf(transformedRenotifyInterval); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2471+
transformed["renotifyInterval"] = transformedRenotifyInterval
2472+
}
2473+
2474+
req = append(req, transformed)
2475+
}
2476+
return req, nil
2477+
}
2478+
2479+
func expandMonitoringAlertPolicyAlertStrategyNotificationChannelStrategyNotificationChannelNames(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2480+
return v, nil
2481+
}
2482+
2483+
func expandMonitoringAlertPolicyAlertStrategyNotificationChannelStrategyRenotifyInterval(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2484+
return v, nil
2485+
}
2486+
23882487
func expandMonitoringAlertPolicyUserLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
23892488
if v == nil {
23902489
return map[string]string{}, nil

website/docs/r/monitoring_alert_policy.html.markdown

+19
Original file line numberDiff line numberDiff line change
@@ -754,13 +754,32 @@ The following arguments are supported:
754754
(Optional)
755755
If an alert policy that was active has no data for this long, any open incidents will close.
756756

757+
* `notification_channel_strategy` -
758+
(Optional)
759+
Control over how the notification channels in `notification_channels`
760+
are notified when this alert fires, on a per-channel basis.
761+
Structure is [documented below](#nested_notification_channel_strategy).
762+
757763

758764
<a name="nested_notification_rate_limit"></a>The `notification_rate_limit` block supports:
759765

760766
* `period` -
761767
(Optional)
762768
Not more than one notification per period.
763769

770+
<a name="nested_notification_channel_strategy"></a>The `notification_channel_strategy` block supports:
771+
772+
* `notification_channel_names` -
773+
(Optional)
774+
The notification channels that these settings apply to. Each of these
775+
correspond to the name field in one of the NotificationChannel objects
776+
referenced in the notification_channels field of this AlertPolicy. The format is
777+
`projects/[PROJECT_ID_OR_NUMBER]/notificationChannels/[CHANNEL_ID]`
778+
779+
* `renotify_interval` -
780+
(Optional)
781+
The frequency at which to send reminder notifications for open incidents.
782+
764783
<a name="nested_documentation"></a>The `documentation` block supports:
765784

766785
* `content` -

0 commit comments

Comments
 (0)