Azure Event Grid Namespaces – Terraform setup

Azure Event Grid Namespaces – Terraform Setup is the second article in the series. I would like to show you how to use Terraform to create all the necessary components: Event Grid Namespace, Topic, and Subscription. A detailed description of the Azure Event Grid Namespace service can be found here.

Azure Event Grid Namespaces – Terraform script

As of April 12, 2024, the AzureRM provider does not support the creation of Azure Event Grid Namespace resources. Instead, we can use the AzAPI provider. While it’s not my preferred choice, it is more favourable to me than Bicep.

I have developed three modules covering all necessary components:

  • event-grid-namespace
    • Uses a public endpoint.
    • System-assigned identity turned on.
    • Uses Standard SKU.
  • event-grid-subscription
    • Uses Queue delivery mode.
    • Uses CloudEventSchemaV1_0 as the event delivery schema.
  • event-grid-topic
    • Uses the input schema CloudEventSchemaV1_0.

You can find the source code here. If you need to modify the modules, please refer to the documentation for Microsoft.EventGrid namespaces.

Azure Event Grid Namespaces: Terraform execution

How do you execute these modules? It’s quite simple. Let’s begin with the creation of the namespace:

HCL
module "event_grid_namespace" {
  source = "./modules/event-grid-namespace"

  name              = "${local.prefix}-egn"
  location          = var.location
  resource_group_id = azurerm_resource_group.rg.id
  is_zone_redundant = true

  tags = {
    environment = var.environment
  }
}

Next, we’ll proceed with creating the topic:

HCL
module "event_grid_topic" {
  source = "./modules/event-grid-topic"

  name         = "${local.prefix}-t1"
  namespace_id = module.event_grid_namespace.id

  event_retention_days = 7
}

Finally, we’ll create the subscription:

HCL
module "event_grid_subscription" {
  source = "./modules/event-grid-subscription"

  name     = "${local.prefix}-s1"
  topic_id = module.event_grid_topic.id
}

As you can see, this setup is straightforward. In the next article, I will explore more advanced scenarios. Stay tuned!

Summary

This article provided a step-by-step guide on how to create an Azure Event Grid Namespace, Topic, and Subscription using Terraform with the AzAPI provider. You can be sure that once the AzureRM-related resources are developed, this article will be updated.

I truly hope you found it enjoyable, and if that’s the case, I would be grateful for a Like or a Comment on my LinkedIn profile.

Leave a Reply

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