Terraform – Azure Service Bus deployment

This terraform script provisions the following resouces into Azure:

an Azure Service Bus instance,

one topic,

one subscripition,

one topic listen and one send key

provider "azurerm" {
  features {}
}

variable "tags" {
  type = map(string)
  default = {
    CustomerName          = "Client01"
    AutoShutdownSchedule  = "None"
    Environment           = "Sandbox"
    Role                  = "Infrastructure"
  }
}

#create resource group
resource "azurerm_resource_group" "example" {
  name     = "allen-tf-servicebus-rg"
  location = "southafricanorth"
  tags     = var.tags
}


#create service bus instance
resource "azurerm_servicebus_namespace" "example" {
  name                			= "allen-tf-servicebus"
  location            			= azurerm_resource_group.example.location
  resource_group_name 			= azurerm_resource_group.example.name
  sku                 			= "Premium"
  minimum_tls_version 			= 1.2
  capacity 						= 1
  premium_messaging_partitions 	= 1
  local_auth_enabled			= true
  tags     			  			= var.tags
}


#create service bus topic
resource "azurerm_servicebus_topic" "example" {
  name                = "allen-tf-topic01"
  namespace_id 		  = azurerm_servicebus_namespace.example.id
  enable_partitioning = true
}


#create subscription
resource "azurerm_servicebus_subscription" "example" {
  name                = "allen-tf-subscription01"
  topic_id            = azurerm_servicebus_topic.example.id
  max_delivery_count  = 10
}


#create subscription listen key
resource "azurerm_servicebus_topic_authorization_rule" "example" {
  name     = "listen_servicebus_topic_sasPolicy"
  topic_id = azurerm_servicebus_topic.example.id
  listen   = true
  send     = false
  manage   = false
}


#create subscription send key
resource "azurerm_servicebus_topic_authorization_rule" "example1" {
  name     = "send_servicebus_topic_sasPolicy"
  topic_id = azurerm_servicebus_topic.example.id
  listen   = false
  send     = true
  manage   = false
}


2 comments

Leave a comment

Your email address will not be published. Required fields are marked *