Skip to content

Commit 2ffdeb8

Browse files
authored
feat: dtoss 6235 create terraform module for azure event grid (#87)
* comment out Diagnostic Settings * add in extra output from function app module * moved modules in
1 parent 4f2d931 commit 2ffdeb8

File tree

6 files changed

+132
-0
lines changed

6 files changed

+132
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
resource "azurerm_eventgrid_event_subscription" "eventgrid_event_subscription" {
2+
name = var.subscription_name
3+
scope = var.azurerm_eventgrid_id
4+
5+
dynamic "azure_function_endpoint" {
6+
for_each = var.subscriber_function_details
7+
content {
8+
function_id = azure_function_endpoint.value.function_endpoint
9+
}
10+
}
11+
12+
storage_blob_dead_letter_destination {
13+
storage_account_id = var.dead_letter_storage_account_id
14+
storage_blob_container_name = var.dead_letter_storage_account_container_name
15+
}
16+
17+
# tags = var.tags
18+
}
19+
20+
21+
resource "azurerm_role_assignment" "eventgrid_subscription_role" {
22+
for_each = { for idx, endpoint in var.subscriber_function_details : idx => endpoint }
23+
24+
principal_id = each.value.principal_id
25+
role_definition_name = "EventGrid Data Receiver"
26+
scope = var.azurerm_eventgrid_id
27+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
variable "subscription_name" {
2+
description = "The name of the Event Grid event subscription."
3+
type = string
4+
}
5+
6+
variable "resource_group_name" {
7+
type = string
8+
description = "The name of the resource group in which to create the Event Grid. Changing this forces a new resource to be created."
9+
}
10+
11+
variable "subscriber_function_details" {
12+
type = list(object({
13+
function_endpoint = string
14+
principal_id = string
15+
}))
16+
default = []
17+
}
18+
19+
variable "azurerm_eventgrid_id" {
20+
description = "The azurerm Event Grid id to link to."
21+
type = string
22+
}
23+
24+
variable "tags" {
25+
description = "A mapping of tags to assign to the Event Grid topic."
26+
type = map(string)
27+
default = {}
28+
}
29+
30+
variable "dead_letter_storage_account_container_name" {
31+
description = "The name of storage account container for the Dead Letter queue."
32+
type = string
33+
}
34+
35+
variable "dead_letter_storage_account_id" {
36+
description = "The name of storage account container id for the Dead Letter queue."
37+
type = string
38+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
resource "azurerm_eventgrid_topic" "azurerm_eventgrid" {
2+
name = var.topic_name
3+
resource_group_name = var.resource_group_name
4+
location = var.location
5+
6+
identity {
7+
type = var.identity_type
8+
}
9+
10+
dynamic "inbound_ip_rule" {
11+
for_each = var.inbound_ip_rules
12+
content {
13+
ip_mask = inbound_ip_rule.value["ip_mask"]
14+
action = inbound_ip_rule.value["action"]
15+
}
16+
}
17+
18+
tags = var.tags
19+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "topic_endpoint" {
2+
description = "The event grid topic URL."
3+
value = azurerm_eventgrid_topic.azurerm_eventgrid.endpoint
4+
}
5+
6+
output "id" {
7+
description = "The event grid topic id."
8+
value = azurerm_eventgrid_topic.azurerm_eventgrid.id
9+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
variable "resource_group_name" {
2+
type = string
3+
description = "The name of the resource group in which to create the Event Grid. Changing this forces a new resource to be created."
4+
}
5+
6+
variable "location" {
7+
type = string
8+
description = "The location/region where the Event Grid is created."
9+
}
10+
11+
variable "inbound_ip_rules" {
12+
description = "List of inbound IP rules"
13+
type = list(object({
14+
ip_mask = string
15+
action = string
16+
}))
17+
default = []
18+
}
19+
20+
variable "identity_type" {
21+
type = string
22+
description = "The identity type of the Event Grid."
23+
}
24+
25+
variable "topic_name" {
26+
description = "The name of the Event Grid topic."
27+
type = string
28+
}
29+
30+
variable "tags" {
31+
description = "A mapping of tags to assign to the Event Grid topic."
32+
type = map(string)
33+
default = {}
34+
}

infrastructure/modules/function-app/output.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ output "name" {
33
value = azurerm_linux_function_app.function_app.name
44
}
55

6+
output "function_app_endpoint_name" {
7+
description = "The function app endpoint name."
8+
value = var.function_app_name
9+
}
10+
611
output "id" {
712
description = "The id of the Linux Function App."
813
value = azurerm_linux_function_app.function_app.id

0 commit comments

Comments
 (0)