Skip to content

Commit a4b94bb

Browse files
authored
feat: DTOSS-8458: Create a terraform module for azure action group (#145)
* DTOSS-8458: Create a Terraform module for Azure Action Group * DTOSS-8458: Create a Terraform module for Azure Action Group * Pr changes * Pr changes * Pr changes
1 parent 9ebaa09 commit a4b94bb

File tree

7 files changed

+284
-6
lines changed

7 files changed

+284
-6
lines changed

infrastructure/.gitignore

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
crash.log
1212
crash.*.log
1313

14-
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
15-
# password, private keys, and other secrets. These should not be part of version
16-
# control as they are data points which are potentially sensitive and subject
17-
# to change depending on the environment.
18-
*.tfvars
19-
*.tfvars.json
2014

2115
# Ignore override files as they are usually used to override resources locally and so
2216
# are not checked in
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
regions = {
2+
uksouth = {
3+
is_primary_region = true
4+
address_space = "10.113.0.0/16"
5+
connect_peering = false
6+
subnets = {}
7+
}
8+
}
9+
10+
monitor_action_group = {
11+
12+
action_group_1 = {
13+
short_name = "group1"
14+
email_receiver = {
15+
alert_team = {
16+
name = "email1"
17+
email_address = "alert_team@testing.com"
18+
use_common_alert_schema = false
19+
}
20+
21+
devops = {
22+
name = "email2"
23+
email_address = "devops@testing.com"
24+
use_common_alert_schema = false
25+
}
26+
}
27+
}
28+
29+
action_group_2 = {
30+
short_name = "group2"
31+
webhook_receiver = {
32+
slack_alerts = {
33+
name = "slack_alerts"
34+
service_uri = "http://example.com/alert1"
35+
use_common_alert_schema = false
36+
}
37+
monitoring_alerts = {
38+
name = "webhook2"
39+
service_uri = "http://example.com/slack"
40+
use_common_alert_schema = false
41+
}
42+
}
43+
}
44+
45+
action_group_3 = {
46+
short_name = "group3"
47+
voice_receiver = {
48+
alerts1 = {
49+
name = "voice_alerts"
50+
country_code = "44"
51+
phone_number = "1234567890"
52+
}
53+
}
54+
55+
sms_receiver = {
56+
alerts2 = {
57+
name = "sms_alerts"
58+
country_code = "44"
59+
phone_number = "1234567890"
60+
}
61+
}
62+
}
63+
64+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module "monitor_action_group" {
2+
for_each = local.monitor_action_group_map
3+
4+
source = "../monitor-action-group"
5+
6+
name = "${module.regions_config[each.value.region].names.monitor-action-group}-${lower(each.value.short_name)}"
7+
resource_group_name = azurerm_resource_group.core[each.value.region].name
8+
location = each.value.region
9+
short_name = each.value.short_name
10+
email_receiver = each.value.email_receiver
11+
event_hub_receiver = each.value.event_hub_receiver
12+
sms_receiver = each.value.sms_receiver
13+
voice_receiver = each.value.voice_receiver
14+
webhook_receiver = each.value.webhook_receiver
15+
}
16+
17+
locals {
18+
monitor_action_group_object_list = flatten([
19+
for region in keys(var.regions) : [
20+
for action_group_key, action_group_details in var.monitor_action_group : merge(
21+
{
22+
region = region
23+
action_group_key = action_group_key
24+
},
25+
action_group_details
26+
)
27+
]
28+
])
29+
30+
# ...then project the list of objects into a map with unique keys (combining the iterators), for consumption by a for_each meta argument
31+
monitor_action_group_map = {
32+
for object in local.monitor_action_group_object_list : "${object.action_group_key}-${object.region}" => object
33+
}
34+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
variable "regions" {
2+
type = map(object({
3+
address_space = optional(string)
4+
is_primary_region = bool
5+
connect_peering = optional(bool, false)
6+
subnets = optional(map(object({
7+
cidr_newbits = string
8+
cidr_offset = string
9+
create_nsg = optional(bool, true) # defaults to true
10+
name = optional(string) # Optional name override
11+
delegation_name = optional(string)
12+
service_delegation_name = optional(string)
13+
service_delegation_actions = optional(list(string))
14+
})))
15+
}))
16+
}
17+
18+
variable "monitor_action_group" {
19+
description = "Default configuration for the monitor action groups."
20+
type = map(object({
21+
short_name = string
22+
email_receiver = optional(map(object({
23+
name = string
24+
email_address = string
25+
use_common_alert_schema = optional(bool, false)
26+
})))
27+
event_hub_receiver = optional(map(object({
28+
name = string
29+
event_hub_namespace = string
30+
event_hub_name = string
31+
subscription_id = string
32+
use_common_alert_schema = optional(bool, false)
33+
})))
34+
sms_receiver = optional(map(object({
35+
name = string
36+
country_code = string
37+
phone_number = string
38+
})))
39+
voice_receiver = optional(map(object({
40+
name = string
41+
country_code = string
42+
phone_number = string
43+
})))
44+
webhook_receiver = optional(map(object({
45+
name = string
46+
service_uri = string
47+
use_common_alert_schema = optional(bool, false)
48+
})))
49+
50+
}))
51+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
resource "azurerm_monitor_action_group" "this" {
2+
name = var.name
3+
resource_group_name = var.resource_group_name
4+
short_name = var.short_name
5+
6+
dynamic "email_receiver" {
7+
for_each = var.email_receiver != null ? var.email_receiver : {}
8+
content {
9+
name = email_receiver.value.name
10+
email_address = email_receiver.value.email_address
11+
use_common_alert_schema = email_receiver.value.use_common_alert_schema
12+
}
13+
}
14+
15+
dynamic "event_hub_receiver" {
16+
for_each = var.event_hub_receiver != null ? var.event_hub_receiver : {}
17+
content {
18+
name = event_hub_receiver.value.name
19+
event_hub_namespace = event_hub_receiver.value.event_hub_namespace
20+
event_hub_name = event_hub_receiver.value.event_hub_name
21+
subscription_id = event_hub_receiver.value.subscription_id
22+
use_common_alert_schema = event_hub_receiver.value.use_common_alert_schema
23+
}
24+
}
25+
26+
dynamic "sms_receiver" {
27+
for_each = var.sms_receiver != null ? var.sms_receiver : {}
28+
content {
29+
name = sms_receiver.value.name
30+
country_code = sms_receiver.value.country_code
31+
phone_number = sms_receiver.value.phone_number
32+
}
33+
}
34+
35+
dynamic "voice_receiver" {
36+
for_each = var.voice_receiver != null ? var.voice_receiver : {}
37+
content {
38+
name = voice_receiver.value.name
39+
country_code = voice_receiver.value.country_code
40+
phone_number = voice_receiver.value.phone_number
41+
}
42+
}
43+
44+
dynamic "webhook_receiver" {
45+
for_each = var.webhook_receiver != null ? var.webhook_receiver : {}
46+
content {
47+
name = webhook_receiver.value.name
48+
service_uri = webhook_receiver.value.service_uri
49+
use_common_alert_schema = webhook_receiver.value.use_common_alert_schema
50+
}
51+
}
52+
53+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
variable "name" {
2+
type = string
3+
description = "value of the name of the diagnostic setting"
4+
}
5+
6+
variable "resource_group_name" {
7+
description = "The name of the resource group in which to create the monitor action group."
8+
type = string
9+
}
10+
11+
variable "short_name" {
12+
description = "The short name of the action group. This will be used in SMS messages."
13+
type = string
14+
}
15+
16+
variable "email_receiver" {
17+
description = "Email receiver properties."
18+
type = map(object({
19+
name = string
20+
email_address = string
21+
use_common_alert_schema = optional(bool, false)
22+
}))
23+
default = null
24+
}
25+
26+
variable "event_hub_receiver" {
27+
description = "event hub receiver properties."
28+
type = map(object({
29+
name = string
30+
event_hub_namespace = string
31+
event_hub_name = string
32+
subscription_id = string
33+
use_common_alert_schema = bool
34+
}))
35+
default = null
36+
}
37+
38+
variable "sms_receiver" {
39+
description = "sms receiver properties."
40+
type = map(object({
41+
name = string
42+
country_code = string
43+
phone_number = string
44+
}))
45+
default = null
46+
}
47+
48+
variable "voice_receiver" {
49+
description = "voice receiver properties."
50+
type = map(object({
51+
name = string
52+
country_code = string
53+
phone_number = string
54+
}))
55+
default = null
56+
}
57+
58+
variable "webhook_receiver" {
59+
description = "webhook receiver properties."
60+
type = map(object({
61+
name = string
62+
service_uri = string
63+
use_common_alert_schema = bool
64+
}))
65+
default = null
66+
}
67+
68+
variable "location" {
69+
description = "The location/region where the Event Hub namespace is created."
70+
type = string
71+
validation {
72+
condition = contains(["uksouth", "ukwest"], var.location)
73+
error_message = "The location must be either uksouth or ukwest."
74+
}
75+
}
76+
77+
variable "tags" {
78+
description = "A mapping of tags to assign to the resource."
79+
type = map(string)
80+
default = {}
81+
}

infrastructure/modules/shared-config/output.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ locals {
121121
logic-app = lower("LA-${var.env}-${var.location_map[var.location]}-${var.application}")
122122
managed-devops-pool = lower("private-pool-${var.env}-${var.location_map[var.location]}")
123123
managed-identity = lower("MI-${var.env}-${var.location_map[var.location]}-${var.application}")
124+
monitor-action-group = lower("AG-${var.env}-${var.location_map[var.location]}-${var.application}")
124125
network-interface = upper("${var.env}-${var.location_map[var.location]}-${var.application}")
125126
network-security-group = upper("NSG-${var.env}-${var.location_map[var.location]}-${var.application}")
126127
postgres-sql-server = lower("postgres-${var.application}-${var.env}-${var.location_map[var.location]}")

0 commit comments

Comments
 (0)