Quickly deploy Azure Service Bus Namespace and Topic using Bicep Language
  • 23 Jan 2023
  • 2 Minutes to read
  • Dark
    Light
  • PDF

Quickly deploy Azure Service Bus Namespace and Topic using Bicep Language

  • Dark
    Light
  • PDF

#ServerlessTips - Azure Bicep
Author: Dave Rendon Microsoft MVP

The purpose of this article is to help you Azure Service Bus Namespace and Topic in your environment using Infrastructure-as-Code with Azure Bicep.

Azure Bicep is a domain-specific language (DSL) that uses a declarative syntax to deploy Azure resources.

Bicep is an abstraction on top of Azure Resource Manager (ARM) templates to define Azure resources using declarative Infrastructure as Code.

This article will show how you can deploy Azure Service Bus Namespace and Topic using Azure Bicep, a Domain Specific Language (DSL) for deploying Azure resources declaratively.

Prerequisites

• An Active Azure account: You can create an account for free.
Azure Bicep is installed on your local machine.
• Azure PowerShell. See: Install Azure PowerShell.
• A resource group in your Azure subscription

Let’s get started!

1. Solution Overview

We will author a Bicep template that creates an Azure Service Bus Namespace and Topic instance. The solution will include the following files:
• 📄 main.bicep: This is the Bicep template
• 📄 azuredeploy.parameters.json: This parameter file contains the values to use for deploying your Bicep template.

2. Azure Bicep Template — parameters

Create a new file in your working directory and name it main.bicep . We will define the following parameters:

@description('Name of the Service Bus Namespace')
param serviceBusNamespaceName string

@description('Name of the Service Bus Topic')
param serviceBusTopicName string

@description('Location for all resources.')
param location string = resourceGroup().location

3. Azure Bicep Template — resources

We will define the following resources:

resource serviceBusNamespace 'Microsoft.ServiceBus/namespaces@2022-01-01-preview' = {
  name: serviceBusNamespaceName
  location: location
  properties: {
  }
}

resource serviceBusNamespaceName_serviceBusTopic 'Microsoft.ServiceBus/namespaces/topics@2022-01-01-preview' = {
  parent: serviceBusNamespace
  name: serviceBusTopicName
  properties: {
    
  }
}

4. Parameters file

Create a new file named azuredeploy.parameters.json. The code below shows the definition of the parameters file:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "serviceBusNamespaceName": {
        "value": "azinsidernamespace"
      },
      "serviceBusTopicName": {
        "value": "azinsidertopic"
      },
      "location": {
        "value": "eastus"
      }
    }
  }

5. Azure Bicep Template — Deployment

We will use the command below to deploy our Bicep template:

$date = Get-Date -Format "MM-dd-yyyy"
$rand = Get-Random -Maximum 1000
$deploymentName = "AzInsiderDeployment-"+"$date"+"-"+"$rand"

New-AzResourceGroupDeployment -Name $deploymentName -ResourceGroupName azinsider_demo -TemplateFile .\main.bicep -TemplateParameterFile .\azuredeploy.parameters.json -c

The image below shows the preview of the deployment:

Picture135

Then we will execute the deployment. The image below shows the deployment output:

Picture234

You can also review the deployment in the Azure Portal

Picture329

Source Code

You can find the code of this solution in the following URL, feel free to contribute!

https://github.com/daveRendon/azinsider/tree/main/application-workloads/create-service-bus-namespace-and-topic


Was this article helpful?