Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ monitor_action_group = {
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ locals {
for object in local.monitor_action_group_object_list : "${object.action_group_key}-${object.region}" => object
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ variable "monitor_action_group" {
})))

}))
}
}

3 changes: 2 additions & 1 deletion infrastructure/modules/monitor-action-group/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ resource "azurerm_monitor_action_group" "this" {
}
}

}
}

1 change: 1 addition & 0 deletions infrastructure/modules/monitor-action-group/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@ variable "tags" {
type = map(string)
default = {}
}

33 changes: 33 additions & 0 deletions infrastructure/modules/service-bus/example/example.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
regions = {
uksouth = {
is_primary_region = true
address_space = "10.113.0.0/16"
connect_peering = false
subnets = {}
}
}

service_bus = {
dtoss-breast-screening = {
capacity = 1
sku_tier = "Premium"
max_payload_size = "100mb"
topics = {
episode_uploaded = {},
episode_created = {},
episode_cancelled = {}
}
},
dtoss-bowel-screening = {
namespace_name = "bowel-screening-for-all"
capacity = 1
sku_tier = "Premium"
max_payload_size = "100mb"
topics = {
episode_uploaded = {},
episode_created = {},
episode_cancelled = {}
}
}
}

36 changes: 36 additions & 0 deletions infrastructure/modules/service-bus/example/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module "azure_service_bus" {
for_each = local.azure_service_bus_map

source = "../../../dtos-devops-templates/infrastructure/modules/service-bus"

servicebus_topic_map = each.value.topics
# The namespace defaults to the object key unless a namespace is specified, then it overwrites it.
servicebus_namespace_name = coalesce(each.value.namespace_name, each.key)
resource_group_name = azurerm_resource_group.core[each.value.region].name
location = each.value.region
capacity = each.value.capacity
sku_tier = each.value.sku_tier

tags = var.tags
}

locals {

azure_service_bus_object_list = flatten([
for region in keys(var.regions) : [
for service_bus_key, service_bus_details in var.service_bus : merge(
{
region = region
service_bus_key = service_bus_key
},
service_bus_details
)
]
])

# ...then project the list of objects into a map with unique keys (combining the iterators), for consumption by a for_each meta argument
azure_service_bus_map = {
for object in local.azure_service_bus_object_list : "${object.service_bus_key}-${object.region}" => object
}
}

40 changes: 40 additions & 0 deletions infrastructure/modules/service-bus/example/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
variable "regions" {
type = map(object({
address_space = optional(string)
is_primary_region = bool
connect_peering = optional(bool, false)
subnets = optional(map(object({
cidr_newbits = string
cidr_offset = string
create_nsg = optional(bool, true) # defaults to true
name = optional(string) # Optional name override
delegation_name = optional(string)
service_delegation_name = optional(string)
service_delegation_actions = optional(list(string))
})))
}))
}

variable "service_bus" {
description = "Configuration for Service Bus namespaces and their topics"
type = map(object({
namespace_name = optional(string)
capacity = number
sku_tier = string
max_payload_size = string
topics = map(object({
auto_delete_on_idle = optional(string, "P10675199DT2H48M5.4775807S")
batched_operations_enabled = optional(bool, false)
default_message_ttl = optional(string, "P10675199DT2H48M5.4775807S")
duplicate_detection_history_time_window = optional(string)
partitioning_enabled = optional(bool, false)
max_message_size_in_kilobytes = optional(number, 1024)
max_size_in_megabytes = optional(number, 5120)
requires_duplicate_detection = optional(bool, false)
support_ordering = optional(bool)
status = optional(string, "Active")
topic_name = optional(string)
}))
}))
}

29 changes: 29 additions & 0 deletions infrastructure/modules/service-bus/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
resource "azurerm_servicebus_namespace" "this" {
name = var.servicebus_namespace_name
location = var.location
resource_group_name = var.resource_group_name
sku = var.sku_tier
capacity = var.capacity
premium_messaging_partitions = var.premium_messaging_partitions
public_network_access_enabled = var.public_network_access_enabled

tags = var.tags
}

resource "azurerm_servicebus_topic" "this" {
for_each = var.servicebus_topic_map

name = coalesce(each.value.topic_name, each.key)
namespace_id = azurerm_servicebus_namespace.this.id
auto_delete_on_idle = each.value.auto_delete_on_idle
batched_operations_enabled = each.value.batched_operations_enabled
default_message_ttl = each.value.default_message_ttl
duplicate_detection_history_time_window = each.value.duplicate_detection_history_time_window
partitioning_enabled = each.value.partitioning_enabled
max_message_size_in_kilobytes = each.value.max_message_size_in_kilobytes
max_size_in_megabytes = each.value.max_size_in_megabytes
requires_duplicate_detection = each.value.requires_duplicate_detection
support_ordering = each.value.support_ordering
status = each.value.status
}

91 changes: 91 additions & 0 deletions infrastructure/modules/service-bus/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
variable "capacity" {
description = "When sku is Premium, capacity can be 1, 2, 4, 8 or 16. When sku is Basic or Standard, capacity must be 0."
type = number
default = 0
validation {
condition = (
(var.sku_tier == "Premium" && contains([1, 2, 4, 8, 16], var.capacity)) ||
((var.sku_tier == "Basic" || var.sku_tier == "Standard") && var.capacity == 0)
)
error_message = "Invalid capacity: Premium allows 1, 2, 4, 8 or 16. Basic and Standard must have capacity 0."
}
}

variable "location" {
description = "The location/region where the Service Bus namespace will be created."
type = string
default = "uksouth"
validation {
condition = contains(["uksouth", "ukwest"], var.location)
error_message = "The location must be either uksouth or ukwest."
}
}

variable "premium_messaging_partitions" {
description = "Boolean flag which controls whether to enable the topic to be partitioned across multiple message brokers. Changing this forces a new resource to be created."
type = number
default = 1
}

variable "public_network_access_enabled" {
type = bool
default = false
}

variable "partitioning_enabled" {
description = "Boolean flag which controls whether to enable the topic to be partitioned across multiple message brokers. Changing this forces a new resource to be created."
type = bool
default = false
}

variable "resource_group_name" {
type = string
description = "The name of the resource group in which to create the Event Grid. Changing this forces a new resource to be created."
validation {
condition = can(regex("^[-\\w\\._\\(\\)]+$", var.resource_group_name)) && length(var.resource_group_name) > 0
error_message = "The resource group name must be a non-empty string using only alphanumeric characters, dashes, underscores, periods, or parentheses."
}
}

variable "servicebus_namespace_name" {
description = "The name of the Service Bus namespace."
type = string
validation {
condition = can(regex("^[a-zA-Z0-9][a-zA-Zq0-9-]{6,49}$", var.servicebus_namespace_name))
error_message = "The Service Bus namespace name must be between 7 and 50 characters and can contain only letters, numbers, and hyphens. It must start with a letter or number."
}
}

variable "servicebus_topic_map" {
type = map(object({
auto_delete_on_idle = optional(string, "P10675199DT2H48M5.4775807S")
batched_operations_enabled = optional(bool, false)
default_message_ttl = optional(string, "P10675199DT2H48M5.4775807S")
duplicate_detection_history_time_window = optional(string)
partitioning_enabled = optional(bool, false)
max_message_size_in_kilobytes = optional(number, 1024)
max_size_in_megabytes = optional(number, 5120)
requires_duplicate_detection = optional(bool, false)
support_ordering = optional(bool)
status = optional(string, "Active")
topic_name = optional(string)
}))
default = {}
}

variable "sku_tier" {
description = "The tier of the SKU."
type = string
default = "Standard"
validation {
condition = contains(["Basic", "Standard", "Premium"], var.sku_tier)
error_message = "The SKU name must be either Basic, Standard or Premium."
}
}

variable "tags" {
description = "A mapping of tags to assign to the resource."
type = map(string)
default = {}
}

Loading