Skip to content

tothenew/terraform-azure-servicebus

Repository files navigation

Azure Service Bus feature

Lint Status LICENSE

This is a template to use for baseline. The default actions will provide updates for section bitween Requirements and Outputs.

The following content needed to be created and managed:

  • Introduction
    • Explaination of module
    • Intended users
  • Resource created and managed by this module
  • Example Usages

Requirements

Name Version
terraform >= 1.3.0

Providers

Name Version
azurecaf ~> 1.2, >= 1.2.22
azurerm ~> 3.39

Modules

This Terraform module creates an Azure Service Bus.

<!-- data "azurerm_subnet" "example" {
  name                 = "backend"
  virtual_network_name = "production"
  resource_group_name  = module.rg.resource_group_name
} -->

module "servicebus" {
  source  = "claranet/service-bus/azurerm"
  version = "x.x.x"

  location       = module.azure_region.location
  location_short = module.azure_region.location_short
  client_name    = var.client_name
  environment    = var.environment
  stack          = var.stack

  resource_group_name = module.rg.resource_group_name

  namespace_parameters = {
    sku = "Premium"
  }

  namespace_authorizations = {
    listen = true
    send   = false
  }

  # Network rules
  network_rules_enabled    = false
  trusted_services_allowed = true
  <!-- allowed_cidrs = [
    "1.2.3.4/32",
  ]
  subnet_ids = [
    data.azurerm_subnet.example.id,
  ] -->

  servicebus_queues = [{
    name                = "myqueue"
    default_message_ttl = "P1D" # 1 day

    dead_lettering_on_message_expiration = true

    authorizations = {
      listen = true
      send   = false
    }
  }]

  servicebus_topics = [{
    name                = "mytopic"
    default_message_ttl = 5 # 5min

    authorizations = {
      listen = true
      send   = true
      manage = false
    }
  }]

  extra_tags = {
    foo = "bar"
  }
}

Resources

Name Type
azurerm_servicebus_namespace.servicebus_namespace resource
azurerm_servicebus_namespace_authorization_rule.listen resource
azurerm_servicebus_namespace_authorization_rule.manage resource
azurerm_servicebus_namespace_authorization_rule.send resource
azurerm_servicebus_namespace_network_rule_set.network_rules resource
azurerm_servicebus_queue.queue resource
azurerm_servicebus_queue_authorization_rule.listen resource
azurerm_servicebus_queue_authorization_rule.manage resource
azurerm_servicebus_queue_authorization_rule.send resource
azurerm_servicebus_topic.topic resource
azurerm_servicebus_topic_authorization_rule.listen resource
azurerm_servicebus_topic_authorization_rule.manage resource
azurerm_servicebus_topic_authorization_rule.send resource

Inputs

Name Description Type Default Required
allowed_cidrs List of CIDR to allow access to that Service Bus Namespace. list(string) [] no
client_name Client name/account used in naming string n/a yes
default_firewall_action Which default firewalling policy to apply. Valid values are Allow or Deny. string "Deny" no
default_tags_enabled Option to enable or disable default tags bool true no
environment Project environment string n/a yes
extra_tags Extra tags to add map(string) {} no
identity_ids Specifies a list of User Assigned Managed Identity IDs to be assigned to this Service Bus. list(string) null no
identity_type Specifies the type of Managed Service Identity that should be configured on this Service Bus. Possible values are SystemAssigned, UserAssigned, SystemAssigned, UserAssigned (to enable both). string "SystemAssigned" no
location Azure location for Servicebus. string n/a yes
name_prefix Optional prefix for the generated name string "" no
name_suffix Optional suffix for the generated name string "" no
namespace_authorizations Object to specify which Namespace Authorization Rules need to be created.
object({
listen = optional(bool, true)
send = optional(bool, true)
manage = optional(bool, true)
})
{} no
namespace_parameters Object to handle Service Bus Namespace options.
custom_name         = To override default resource name, generated if not set.
sku = Defines which tier to use. Options are Basic, Standard or Premium.
capacity = Specifies the capacity. When SKU is Premium, capacity can be 1, 2, 4, 8 or 16.
local_auth_enabled = Whether or not SAS authentication is enabled for the Service Bus Namespace.
zone_redundant = Whether or not this resource is zone redundant. SKU needs to be Premium.
minimum_tls_version = The minimum supported TLS version for this Service Bus Namespace.

public_network_access_enabled = Is public network access enabled for the Service Bus Namespace?
object({
custom_name = optional(string)
sku = optional(string, "Standard")
capacity = optional(number, 0)
local_auth_enabled = optional(bool, true)
zone_redundant = optional(bool, false)
minimum_tls_version = optional(string, "1.2")

public_network_access_enabled = optional(bool, true)
})
{} no
network_rules_enabled Boolean to enable Network Rules on the Service Bus Namespace, requires trusted_services_allowed, allowed_cidrs, subnet_ids or default_firewall_action correctly set if enabled. bool false no
resource_group_name Name of the resource group string n/a yes
servicebus_queues List of objects to create Queues with their options.
name        = Short Queue name.
custom_name = Custom name for Azure resource.

status = The status of the Queue. Possible values are Active, Creating, Deleting, Disabled, ReceiveDisabled, Renaming, SendDisabled, Unknown. Note that Restoring is not accepted.

auto_delete_on_idle = Duration of the idle interval after which the Queue is automatically deleted.
default_message_ttl = Duration of the TTL of messages sent to this Queue.
duplicate_detection_history_time_window = Duration during which duplicates can be detected.
lock_duration = Duration of a peek-lock that is, the amount of time that the message is locked for other receivers. Maximum value is 5 minutes.
max_message_size_in_kilobytes = Integer value which controls the maximum size of a message allowed on the Queue for Premium SKU.
max_size_in_megabytes = Integer value which controls the size of memory allocated for the Queue.
max_delivery_count = Integer value which controls when a message is automatically dead lettered.

enable_batched_operations = Boolean flag which controls whether server-side batched operations are enabled.
enable_partitioning = Boolean flag which controls whether to enable the Queue to be partitioned across multiple message brokers. Partitioning is available at entity creation for all Queues and Topics in Basic or Standard SKUs.
enable_express = Boolean flag which controls whether Express Entities are enabled. An express Queue holds a message in memory temporarily before writing it to persistent storage.
dead_lettering_on_message_expiration = Boolean flag which controls whether the Queue has dead letter support when a message expires.
requires_duplicate_detection = Boolean flag which controls whether the Queue requires duplicate detection.
requires_session = Boolean flag which controls whether the Queue requires sessions. This will allow ordered handling of unbounded sequences of related messages. With sessions enabled a Queue can guarantee first-in-first-out delivery of messages.

forward_to = The name of a Queue or Topic to automatically forward messages to.
forward_dead_lettered_messages_to = The name of a Queue or Topic to automatically forward dead lettered messages to.

authorizations_custom_name = To override default Queue Authorization Rules names, generated if not set (first with the custom name of the Queue if set, otherwise with Azure CAF).
authorizations = Object with listen, send and manage attributes to create Queues Authorizations Rules.
list(object({
name = string
custom_name = optional(string)

status = optional(string, "Active")

auto_delete_on_idle = optional(string)
default_message_ttl = optional(string)
duplicate_detection_history_time_window = optional(string)
lock_duration = optional(string)
max_message_size_in_kilobytes = optional(number)
max_size_in_megabytes = optional(number)
max_delivery_count = optional(number, 10)

enable_batched_operations = optional(bool, true)
enable_partitioning = optional(bool)
enable_express = optional(bool)
dead_lettering_on_message_expiration = optional(bool)
requires_duplicate_detection = optional(bool)
requires_session = optional(bool)

forward_to = optional(string)
forward_dead_lettered_messages_to = optional(string)

authorizations_custom_name = optional(string)
authorizations = optional(object({
listen = optional(bool, true)
send = optional(bool, true)
manage = optional(bool, true)
}), {})
}))
[] no
servicebus_topics List of objects to create Topics with their options.
name        = Short Topic name.
custom_name = Custom name for Azure resource.

status = The status of the Service Bus Topic. Acceptable values are Active or Disabled.

auto_delete_on_idle = Duration of the idle interval after which the Topic is automatically deleted, minimum of 5 minutes.
default_message_ttl = Duration of TTL of messages sent to this Topic if no TTL value is set on the message itself.
duplicate_detection_history_time_window = Duration during which duplicates can be detected.
max_message_size_in_kilobytes = Integer value which controls the maximum size of a message allowed on the Topic for Premium SKU.
max_size_in_megabytes = Integer value which controls the size of memory allocated for the Topic.

enable_batched_operations = Boolean flag which controls if server-side batched operations are enabled.
enable_partitioning = Boolean flag which controls whether to enable the Topic to be partitioned across multiple message brokers.
enable_express = Boolean flag which controls whether Express Entities are enabled. An express Topic holds a message in memory temporarily before writing it to persistent storage.
requires_duplicate_detection = Boolean flag which controls whether the Topic requires duplicate detection.
support_ordering = Boolean flag which controls whether the Topic supports ordering.

authorizations_custom_name = To override default Topic Authorization Rules names, generated if not set (first with the custom name of the Topic if set, otherwise with Azure CAF).
authorizations = Object with listen, send and manage attributes to create Topics Authorizations Rules.

subscriptions = List of subscriptions per Topic.
list(object({
name = string
custom_name = optional(string)

status = optional(string, "Active")

auto_delete_on_idle = optional(string)
default_message_ttl = optional(string)
duplicate_detection_history_time_window = optional(string)
max_message_size_in_kilobytes = optional(number)
max_size_in_megabytes = optional(number)

enable_batched_operations = optional(bool)
enable_partitioning = optional(bool)
enable_express = optional(bool)
requires_duplicate_detection = optional(bool)
support_ordering = optional(bool)

authorizations_custom_name = optional(string)
authorizations = optional(object({
listen = optional(bool, true)
send = optional(bool, true)
manage = optional(bool, true)
}), {})

# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/servicebus_subscription
subscriptions = optional(list(object({
name = string
custom_name = optional(string)

status = optional(string, "Active")

auto_delete_on_idle = optional(string)
default_message_ttl = optional(string)
lock_duration = optional(string)
max_delivery_count = number

enable_batched_operations = optional(bool, true)
dead_lettering_on_message_expiration = optional(bool)
dead_lettering_on_filter_evaluation_error = optional(bool)
requires_session = optional(bool)

forward_to = optional(string)
forward_dead_lettered_messages_to = optional(string)
})), [])
}))
[] no
stack Project stack name string n/a yes
subnet_ids Subnets to allow access to that Service Bus Namespace. list(string) [] no
trusted_services_allowed If True, then Azure Services that are known and trusted for this resource type are allowed to bypass firewall configuration. bool true no
use_caf_naming Use the Azure CAF naming provider to generate default resource name. custom_name override this if set. Legacy default name is used if this is set to false. bool true no

Outputs

Name Description
namespace Service Bus Namespace outputs.
namespace_listen_authorization_rule Service Bus namespace listen only authorization rule.
namespace_manage_authorization_rule Service Bus namespace manage authorization rule.
namespace_send_authorization_rule Service Bus namespace send only authorization rule.
queues Service Bus queues outputs.
queues_listen_authorization_rule Service Bus queues listen only authorization rules.
queues_manage_authorization_rule Service Bus queues manage authorization rules.
queues_send_authorization_rule Service Bus queues send only authorization rules.
topics Service Bus topics outputs.
topics_listen_authorization_rule Service Bus topics listen only authorization rules.
topics_manage_authorization_rule Service Bus topics manage authorization rules.
topics_send_authorization_rule Service Bus topics send only authorization rules.

Authors

Module managed by TO THE NEW Pvt. Ltd.

License

Apache 2 Licensed. See LICENSE for full details.

Releases

No releases published

Packages

No packages published

Languages