Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
Signed-off-by: SpiritZhou <[email protected]>
  • Loading branch information
SpiritZhou committed Mar 15, 2024
1 parent 1e16d1d commit ed2c9f6
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 0 deletions.
36 changes: 36 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,26 @@ module "azure_servicebus_namespace_alternative" {
tags = local.tags
}

module "azure_servicebus_namespace_event_grid" {
source = "./modules/azure/service-bus"
resource_group_name = var.azure_resource_group_name
unique_project_name = var.unique_project_name
service_bus_suffix = "-event-grid"
service_bus_admin_identities = [
module.azuread_applications.identity_1
]
tags = local.tags
}

module "azurerm_eventgrid_topic" {
source = "./modules/azure/event-grid"
resource_group_name = var.azure_resource_group_name
unique_project_name = var.unique_project_name
service_bus_topic_id = module.azure_servicebus_namespace_event_grid.event_grid_receive_topic_id

tags = local.tags
}

module "azure_storage_account" {
source = "./modules/azure/storage-account"
resource_group_name = var.azure_resource_group_name
Expand Down Expand Up @@ -378,6 +398,22 @@ module "github_secrets" {
name = "TF_AZURE_RABBIT_API_APPLICATION_ID"
value = module.azure_rabbitmq_app_registration.application_id
},
{
name = "TF_AZURE_SERVICE_BUS_EVENTGRID_CONNECTION_STRING"
value = module.azure_servicebus_namespace_event_grid.connection_string
},
{
name = "TF_AZURE_EVENT_GRID_ENDPOINT"
value = module.azurerm_eventgrid_topic.endpoint
},
{
name = "TF_AZURE_EVENT_GRID_KEY"
value = module.azurerm_eventgrid_topic.key
},
{
name = "TF_AZURE_SB_EVENT_GRID_RECEIVE_TOPIC"
value = module.azure_servicebus_namespace_event_grid.event_grid_receive_topic
},
]
}

Expand Down
37 changes: 37 additions & 0 deletions terraform/modules/azure/event-grid/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
provider "azurerm" {
features {}
skip_provider_registration = true
}

locals {
event_grid_name = "${var.unique_project_name}-e2e-event-grid"
event_grid_subscription_name = "${var.unique_project_name}-e2e-event-grid-subscription"
}

data "azurerm_resource_group" "rg" {
name = var.resource_group_name
}

resource "azurerm_eventgrid_topic" "eventgrid" {
name = local.event_grid_name
location = data.azurerm_resource_group.rg.location
resource_group_name = data.azurerm_resource_group.rg.name
input_schema = "CloudEventSchemaV1_0"

tags = var.tags
}

resource "azurerm_eventgrid_event_subscription" "eventsubscription" {
name = local.event_grid_subscription_name
scope = azurerm_eventgrid_topic.eventgrid.id
event_delivery_schema = "CloudEventSchemaV1_0"

service_bus_topic_endpoint_id = var.service_bus_topic_id
}

resource "azurerm_role_assignment" "roles" {
count = length(var.event_grid_admin_identities)
scope = azurerm_eventgrid_topic.eventgrid.id
role_definition_name = "Azure Event Grid Owner"
principal_id = var.event_grid_admin_identities[count.index].principal_id
}
7 changes: 7 additions & 0 deletions terraform/modules/azure/event-grid/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "endpoint" {
value = azurerm_eventgrid_topic.eventgrid.endpoint
}

output "key" {
value = azurerm_eventgrid_topic.eventgrid.primary_access_key
}
25 changes: 25 additions & 0 deletions terraform/modules/azure/event-grid/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
variable "resource_group_name" {
type = string
description = "Resource group name where event hub will be placed"
}

variable "unique_project_name" {
type = string
description = "Value to make unique every resource name generated"
}

variable "service_bus_topic_id" {
type = string
description = "Service bus topic to subscription events"
}

variable "tags" {
type = map(any)
description = "Tags to apply on every resource"
}

variable "event_grid_admin_identities" {
type = list(any)
description = "Azure Service Bus Data Owner identities"
default = []
}
6 changes: 6 additions & 0 deletions terraform/modules/azure/service-bus/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ provider "azurerm" {
locals {
service_bus_namespace_name = "${var.unique_project_name}-e2e-servicebus-namespace${var.service_bus_suffix}"
service_bus_authorization_rule = "${var.unique_project_name}-e2e-manage"
service_bus_topic_name = "${var.unique_project_name}-e2e-receive-event-grid-topic"
}

data "azurerm_resource_group" "rg" {
Expand All @@ -20,6 +21,11 @@ resource "azurerm_servicebus_namespace" "namespace" {
tags = var.tags
}

resource "azurerm_servicebus_topic" "topic" {
name = local.service_bus_topic_name
namespace_id = azurerm_servicebus_namespace.namespace.id
}

resource "azurerm_servicebus_namespace_authorization_rule" "manage" {
name = local.service_bus_authorization_rule
namespace_id = azurerm_servicebus_namespace.namespace.id
Expand Down
8 changes: 8 additions & 0 deletions terraform/modules/azure/service-bus/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
output "connection_string" {
value = azurerm_servicebus_namespace_authorization_rule.manage.primary_connection_string
}

output "event_grid_receive_topic_id" {
value = azurerm_servicebus_topic.topic.id
}

output "event_grid_receive_topic" {
value = azurerm_servicebus_topic.topic.name
}

0 comments on commit ed2c9f6

Please sign in to comment.