Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
frasdav committed Mar 18, 2024
1 parent 4b1d374 commit 2a8b954
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/eventhub-namespace/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
1 change: 1 addition & 0 deletions modules/eventhub-namespace/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# EventHub Namespace
1 change: 1 addition & 0 deletions modules/eventhub-namespace/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0
14 changes: 14 additions & 0 deletions modules/eventhub-namespace/src/locals.tf
Original file line number Diff line number Diff line change
@@ -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
}
}
52 changes: 52 additions & 0 deletions modules/eventhub-namespace/src/main.tf
Original file line number Diff line number Diff line change
@@ -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
}
}
}
11 changes: 11 additions & 0 deletions modules/eventhub-namespace/src/outputs.tf
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 10 additions & 0 deletions modules/eventhub-namespace/src/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = "~> 1.5"

required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.85"
}
}
}
84 changes: 84 additions & 0 deletions modules/eventhub-namespace/src/variables.tf
Original file line number Diff line number Diff line change
@@ -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
}
19 changes: 19 additions & 0 deletions modules/eventhub-namespace/test/main.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}
10 changes: 10 additions & 0 deletions modules/eventhub-namespace/test/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = "~> 1.5"

required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.85"
}
}
}

0 comments on commit 2a8b954

Please sign in to comment.