Skip to main content

Introducing the 'Azure Service Bus Namespace' Terraform Module and Usage Patterns to Facilitate Service Bus Setup

· 2 min read

The new Terraform module Azure Service Bus Namespace has been released by the DevEx team to enable customers to easily and straightforwardly set up Service Bus!

This module abstracts inner complexities such as networking, authentication, and scaling. By choosing the l tier (which matches the Premium SKU), the module provides private communication via private endpoints and also includes an autoscaler resource to dynamically change the number of instances depending on CPU and memory metrics.

The module also supports the m tier (Standard SKU), but it is recommended to use this tier only in test environments as the resource cannot be isolated in terms of networking and remains on the public internet.

Getting Started

We recommend referencing the module via the Terraform Registry and pinning the version to the latest stable release:

module "sbns" {
source = "pagopa-dx/azure-service-bus-namespace/azurerm"
version = "~>0.0"
}

Roles can be managed through the traditional role assignment module, which you should already be familiar with. By passing names of queues, topics, and subscriptions, the IAM complexity is taken away.

module "roles" {
source = "pagopa-dx/azure-role-assignments/azurerm"
version = "~>1.0"

principal_id = <principal_id>
subscription_id = data.azurerm_subscription.current.subscription_id

service_bus = [
{
namespace_name = <value>
resource_group_name = <value>
role = "reader|writer|owner"
description = <value>
queue_names = (optional) [<list of queues>]
topic_names = (optional) [<list of topics>]
subscriptions = {
(optional) <list of key-value pairs for subscriptions, e.g. topic = [<list of subscriptions>]>
}
}
]
}

Additionally, the Azure Bootstrap module has been updated to add the needed roles to apply Terraform code to a centralized Service Bus instance, if you have one.

More details can be found in the documentation, which is available in the module entry in the Terraform Registry.

Moreover, if you want to learn more about best practices and patterns, check out DX guidelines.

Examples

Explore module examples to create the Service Bus namespace. Other examples are also available to show queue, topic, and subscription definitions.