Build Azure Service Bus Queues Using Terraform

What are we creating?

  1. Microservice 1 generates messages and posts them to the messagesQueue.
  2. Microservice 2 listens to messages from the Queue and process them. If it fails to process, post back to the same queue (for up to 5 times).
  3. If it fails for more than 5 times, post the message to the Error Messages Queue.
  4. The Error Messages Queue automatically posts back the errored messages to the regular queue after one hour (this parameter can be changed on file modules/queue/
  5. Whether there’s an error or success, Microservice 2 should always post log information to Logging Microservice

Starting Terraform locally

terraform init \
-backend-config "container_name=<your folder inside Azure Blob Storage>" \
-backend-config "storage_account_name=<your Azure Storage Name>" \
-backend-config "key=<file name to be stored>" \
-backend-config "subscription_id=<subscription ID of your account>" \
-backend-config "client_id=<your username>" \
-backend-config "client_secret=<your password>" \
-backend-config "tenant_id=<tenant id>" \
-backend-config "resource_group_name=<resource group name to find your Blob Storage>"

Planning your Service Bus deploy

terraform plan \
-var 'client_id=<client id>' \
-var 'client_secret=<client secret' \
-var 'subscription_id=<subscription id>' \
-var 'tenant_id=<tenant id>' \
-var-file="rootVars.tfvars" \
-var-file="rootVars-<environment>.tfvars" \
-out tfout.log
  • -VAR-FILE — The first var file one has common variables for all our environments.
  • -VAR-FILE — The second var file has a specific value for the current environment. Take a look at the rootVars-<all>.tfvars files.
  • TFOUT.LOG — This is the name of the file to which Terraform will store the plan to achieve your Terraform configuration

Deploying your Service Bus infrastructure

terraform apply tfout.log



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Guilherme Sesterheim

Guilherme Sesterheim

Sharing experiences on IT subjects. Working for AWS. DevOps, Kubernetes, Microservices, Terraform, Ansible, and Java