diff --git a/modules/eventhub-namespace/CHANGELOG.md b/modules/eventhub-namespace/CHANGELOG.md new file mode 100644 index 0000000..825c32f --- /dev/null +++ b/modules/eventhub-namespace/CHANGELOG.md @@ -0,0 +1 @@ +# Changelog diff --git a/modules/eventhub-namespace/README.md b/modules/eventhub-namespace/README.md new file mode 100644 index 0000000..58f5b29 --- /dev/null +++ b/modules/eventhub-namespace/README.md @@ -0,0 +1 @@ +# EventHub Namespace diff --git a/modules/eventhub-namespace/VERSION b/modules/eventhub-namespace/VERSION new file mode 100644 index 0000000..d3827e7 --- /dev/null +++ b/modules/eventhub-namespace/VERSION @@ -0,0 +1 @@ +1.0 diff --git a/modules/eventhub-namespace/src/locals.tf b/modules/eventhub-namespace/src/locals.tf new file mode 100644 index 0000000..6a78776 --- /dev/null +++ b/modules/eventhub-namespace/src/locals.tf @@ -0,0 +1,14 @@ +locals { + identifier = replace(lower(var.identifier), "/[^a-z1-9]/", "") + + short_locations = { + "uksouth" = "uks" + "ukwest" = "ukw" + } + + tags = { + Environment = var.environment + Location = var.location + Zone = var.zone + } +} diff --git a/modules/eventhub-namespace/src/main.tf b/modules/eventhub-namespace/src/main.tf new file mode 100644 index 0000000..3f2910b --- /dev/null +++ b/modules/eventhub-namespace/src/main.tf @@ -0,0 +1,52 @@ + +resource "azurerm_eventhub_namespace" "main" { + name = "ehns-${var.zone}-${var.environment}-${lookup(local.short_locations, var.location)}-${local.identifier}" + location = var.location + resource_group_name = var.resource_group_name + + capacity = var.capacity + local_authentication_enabled = var.local_authentication_enabled + public_network_access_enabled = var.public_network_access_enabled + sku = var.sku + zone_redundant = var.zone_redundant + + dynamic "identity" { + for_each = var.identity != null ? [var.identity] : [] + content { + type = identity.value.type + identity_ids = identity.value.identity_ids + } + } + + tags = merge(var.tags, local.tags) +} + +resource "azurerm_monitor_diagnostic_setting" "main" { + name = "log-analytics" + target_resource_id = azurerm_eventhub_namespace.main.id + log_analytics_workspace_id = var.log_analytics_workspace_id + + dynamic "enabled_log" { + for_each = var.log_categories + + content { + category = enabled_log.value + } + } + + dynamic "enabled_log" { + for_each = var.log_category_groups + + content { + category_group = enabled_log.value + } + } + + dynamic "metric" { + for_each = var.metric_categories + + content { + category = metric.value + } + } +} diff --git a/modules/eventhub-namespace/src/outputs.tf b/modules/eventhub-namespace/src/outputs.tf new file mode 100644 index 0000000..9491fc9 --- /dev/null +++ b/modules/eventhub-namespace/src/outputs.tf @@ -0,0 +1,11 @@ +output "id" { + value = azurerm_eventhub_namespace.main.id +} + +output "name" { + value = azurerm_eventhub_namespace.main.name +} + +output "identity" { + value = azurerm_eventhub_namespace.main.identity +} diff --git a/modules/eventhub-namespace/src/terraform.tf b/modules/eventhub-namespace/src/terraform.tf new file mode 100644 index 0000000..762ef2e --- /dev/null +++ b/modules/eventhub-namespace/src/terraform.tf @@ -0,0 +1,10 @@ +terraform { + required_version = "~> 1.5" + + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~> 3.85" + } + } +} diff --git a/modules/eventhub-namespace/src/variables.tf b/modules/eventhub-namespace/src/variables.tf new file mode 100644 index 0000000..809896e --- /dev/null +++ b/modules/eventhub-namespace/src/variables.tf @@ -0,0 +1,84 @@ +variable "capacity" { + type = number + default = 1 +} + +variable "environment" { + type = string +} + +variable "identifier" { + type = string +} + +variable "identity" { + type = object({ + type = string + identity_ids = optional(list(string)) + }) + default = { + type = "SystemAssigned" + identity_ids = [] + } +} + +variable "local_authentication_enabled" { + type = bool + default = false +} + +variable "location" { + type = string +} + +variable "log_analytics_workspace_id" { + type = string +} + +# https://learn.microsoft.com/en-us/azure/azure-monitor/reference/supported-logs/microsoft-eventhub-namespaces-logs +variable "log_categories" { + type = list(string) + default = [ + + ] +} + +variable "log_category_groups" { + type = list(string) + default = [] +} + +variable "metric_categories" { + type = list(string) + default = [ + "AllMetrics", + ] +} + +variable "public_network_access_enabled" { + type = bool + default = false +} + +variable "resource_group_name" { + type = string +} + +variable "sku" { + type = string + default = "Standard" +} + +variable "tags" { + type = map(string) + default = {} +} + +variable "zone" { + type = string +} + +variable "zone_redundant" { + type = bool + default = false +} diff --git a/modules/eventhub-namespace/test/main.tf b/modules/eventhub-namespace/test/main.tf new file mode 100644 index 0000000..a01a58f --- /dev/null +++ b/modules/eventhub-namespace/test/main.tf @@ -0,0 +1,19 @@ +provider "azurerm" { + features {} +} + +module "eventhub_namespace" { + source = "../src" + + environment = "baz" + identifier = "qux" + location = "uksouth" + resource_group_name = "grault" + zone = "waldo" + + log_analytics_workspace_id = "quux" + + tags = { + Foo = "Bar" + } +} diff --git a/modules/eventhub-namespace/test/terraform.tf b/modules/eventhub-namespace/test/terraform.tf new file mode 100644 index 0000000..762ef2e --- /dev/null +++ b/modules/eventhub-namespace/test/terraform.tf @@ -0,0 +1,10 @@ +terraform { + required_version = "~> 1.5" + + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~> 3.85" + } + } +}