Skip to content

Commit 6b4c4f3

Browse files
authored
Merge pull request #36 from using-system/features/azure-bus
feat: Add tf modules for azure bus
2 parents 7aacf94 + a637b4f commit 6b4c4f3

File tree

16 files changed

+612
-0
lines changed

16 files changed

+612
-0
lines changed
4.74 KB

Requirements

No requirements.

Providers

Name Version
azurerm 3.96.0

Modules

No modules.

Resources

Name Type
azurerm_servicebus_queue.asb resource

Inputs

Name Description Type Default Required
default_message_ttl The TTL for messages in the Service Bus Queue string "PT5M" no
duplicate_detection_history_time_window The time window for duplicate detection string "PT10M" no
enable_partitioning Is partitioning enabled for the Service Bus Queue bool false no
forward_dead_lettered_messages_to The name of the Service Bus Queue to forward dead lettered messages to string "" no
forward_to The name of the Service Bus Queue to forward messages to string "" no
lock_duration The lock duration for messages in the Service Bus Queue string "PT1M" no
name The name of the Service Bus Queue string n/a yes
namespace_id The ID of the Service Bus Namespace string n/a yes
requires_duplicate_detection Does the Service Bus Queue require duplicate detection bool false no
requires_session Does the Service Bus Queue require a session bool false no

Outputs

Name Description
id The ServiceBus Queue ID.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
skip-path:
2+
- tests
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
resource "azurerm_servicebus_queue" "asb" {
2+
name = var.name
3+
namespace_id = var.namespace_id
4+
5+
lock_duration = var.lock_duration
6+
default_message_ttl = var.default_message_ttl
7+
requires_session = var.requires_session
8+
enable_partitioning = var.enable_partitioning
9+
requires_duplicate_detection = var.requires_duplicate_detection
10+
duplicate_detection_history_time_window = var.duplicate_detection_history_time_window
11+
12+
forward_to = var.forward_to
13+
forward_dead_lettered_messages_to = var.forward_dead_lettered_messages_to
14+
15+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "id" {
2+
description = "The ServiceBus Queue ID."
3+
value = azurerm_servicebus_queue.asb.id
4+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
provider "azurerm" {
2+
features {
3+
}
4+
}
5+
6+
run "setup" {
7+
module {
8+
source = "./tests/setup"
9+
}
10+
}
11+
12+
run "plan" {
13+
14+
command = plan
15+
16+
variables {
17+
name = "azasbstandardqueue"
18+
namespace_id = run.setup.namespace_id
19+
default_message_ttl = "PT1M"
20+
}
21+
22+
assert {
23+
condition = azurerm_servicebus_queue.asb.name == var.name
24+
error_message = "azurerm_servicebus_queue name must be set"
25+
}
26+
27+
assert {
28+
condition = azurerm_servicebus_queue.asb.namespace_id == var.namespace_id
29+
error_message = "azurerm_servicebus_queue namespace_id must be set"
30+
}
31+
32+
assert {
33+
condition = azurerm_servicebus_queue.asb.default_message_ttl == var.default_message_ttl
34+
error_message = "azurerm_servicebus_queue default_message_ttl must be set"
35+
}
36+
37+
}
38+
39+
run "apply" {
40+
41+
command = apply
42+
43+
variables {
44+
name = "azasbstandardqueue"
45+
namespace_id = run.setup.namespace_id
46+
default_message_ttl = "PT1M"
47+
}
48+
49+
assert {
50+
condition = output.id != "" && output.id != null
51+
error_message = "output id is empty"
52+
}
53+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
data "azurerm_resource_group" "test" {
2+
name = "tf-test-rg"
3+
}
4+
5+
resource "azurerm_servicebus_namespace" "test" {
6+
name = "system-az-asb-queue"
7+
location = data.azurerm_resource_group.test.location
8+
resource_group_name = data.azurerm_resource_group.test.name
9+
sku = "Standard"
10+
11+
tags = {
12+
environment = "Test"
13+
}
14+
}
15+
16+
output "namespace_id" {
17+
value = azurerm_servicebus_namespace.test.id
18+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
variable "name" {
2+
description = "The name of the Service Bus Queue"
3+
type = string
4+
}
5+
6+
variable "namespace_id" {
7+
description = "The ID of the Service Bus Namespace"
8+
type = string
9+
}
10+
11+
variable "lock_duration" {
12+
description = "The lock duration for messages in the Service Bus Queue"
13+
type = string
14+
default = "PT1M"
15+
}
16+
17+
variable "default_message_ttl" {
18+
description = "The TTL for messages in the Service Bus Queue"
19+
type = string
20+
default = "PT5M"
21+
}
22+
23+
variable "requires_session" {
24+
description = "Does the Service Bus Queue require a session"
25+
type = bool
26+
default = false
27+
}
28+
29+
variable "enable_partitioning" {
30+
description = "Is partitioning enabled for the Service Bus Queue"
31+
type = bool
32+
default = false
33+
}
34+
35+
variable "requires_duplicate_detection" {
36+
description = "Does the Service Bus Queue require duplicate detection"
37+
type = bool
38+
default = false
39+
}
40+
41+
variable "duplicate_detection_history_time_window" {
42+
description = "The time window for duplicate detection"
43+
type = string
44+
default = "PT10M"
45+
}
46+
47+
variable "forward_to" {
48+
description = "The name of the Service Bus Queue to forward messages to"
49+
type = string
50+
default = null
51+
}
52+
53+
variable "forward_dead_lettered_messages_to" {
54+
description = "The name of the Service Bus Queue to forward dead lettered messages to"
55+
type = string
56+
default = null
57+
}

terraform/modules/az-asb/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## Requirements
2+
3+
No requirements.
4+
5+
## Providers
6+
7+
| Name | Version |
8+
|------|---------|
9+
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | 3.96.0 |
10+
11+
## Modules
12+
13+
No modules.
14+
15+
## Resources
16+
17+
| Name | Type |
18+
|------|------|
19+
| [azurerm_servicebus_namespace.asb](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/servicebus_namespace) | resource |
20+
21+
## Inputs
22+
23+
| Name | Description | Type | Default | Required |
24+
|------|-------------|------|---------|:--------:|
25+
| <a name="input_capacity"></a> [capacity](#input\_capacity) | The capacity of the Azure Service Bus Namespace | `number` | `1` | no |
26+
| <a name="input_cmk_key_vault_key_id"></a> [cmk\_key\_vault\_key\_id](#input\_cmk\_key\_vault\_key\_id) | The Key Vault Key Id to associate with the Azure Service Bus Namespace | `string` | `null` | no |
27+
| <a name="input_identity_ids"></a> [identity\_ids](#input\_identity\_ids) | A list of identities associated with the Azure Service Bus Namespace | `list(string)` | `[]` | no |
28+
| <a name="input_location"></a> [location](#input\_location) | Azure Region Location | `string` | n/a | yes |
29+
| <a name="input_minimum_tls_version"></a> [minimum\_tls\_version](#input\_minimum\_tls\_version) | The minimum TLS version for the Azure Service Bus Namespace | `string` | `"1.2"` | no |
30+
| <a name="input_name"></a> [name](#input\_name) | Name of the azure bus namespace | `any` | n/a | yes |
31+
| <a name="input_network_rules_default_action"></a> [network\_rules\_default\_action](#input\_network\_rules\_default\_action) | The default action of the network rules | `string` | `"Deny"` | no |
32+
| <a name="input_premium_messaging_partitions"></a> [premium\_messaging\_partitions](#input\_premium\_messaging\_partitions) | The number of messaging partitions for the Azure Service Bus Namespace | `number` | `1` | no |
33+
| <a name="input_public_network_access_enabled"></a> [public\_network\_access\_enabled](#input\_public\_network\_access\_enabled) | Is public network access enabled for the Azure Service Bus Namespace | `bool` | `false` | no |
34+
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | Resource group name of the azure bus namespace | `any` | n/a | yes |
35+
| <a name="input_sku"></a> [sku](#input\_sku) | The SKU of the Azure Service Bus Namespace | `string` | `"Premium"` | no |
36+
| <a name="input_subnet_ids"></a> [subnet\_ids](#input\_subnet\_ids) | The list of subnet ids to associate with the Azure Service Bus Namespace | `list(string)` | `[]` | no |
37+
| <a name="input_tags"></a> [tags](#input\_tags) | Tags to associate with resources. | `map(string)` | n/a | yes |
38+
| <a name="input_trusted_services_allowed"></a> [trusted\_services\_allowed](#input\_trusted\_services\_allowed) | The list of trusted services allowed | `bool` | `false` | no |
39+
40+
## Outputs
41+
42+
| Name | Description |
43+
|------|-------------|
44+
| <a name="output_endpoint"></a> [endpoint](#output\_endpoint) | The endpoint for the Service Bus Namespace. |
45+
| <a name="output_id"></a> [id](#output\_id) | The ID of the Service Bus Namespace. |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
skip-path:
2+
- tests

terraform/modules/az-asb/main.tf

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
resource "azurerm_servicebus_namespace" "asb" {
2+
name = var.name
3+
location = var.location
4+
resource_group_name = var.resource_group_name
5+
sku = var.sku
6+
capacity = var.capacity
7+
premium_messaging_partitions = var.premium_messaging_partitions
8+
9+
public_network_access_enabled = var.public_network_access_enabled
10+
local_auth_enabled = false
11+
minimum_tls_version = var.minimum_tls_version
12+
13+
dynamic "network_rule_set" {
14+
for_each = length(var.subnet_ids) > 0 ? [1] : []
15+
content {
16+
public_network_access_enabled = var.public_network_access_enabled
17+
default_action = var.network_rules_default_action
18+
trusted_services_allowed = var.trusted_services_allowed
19+
20+
dynamic "network_rules" {
21+
for_each = var.subnet_ids
22+
content {
23+
subnet_id = network_rules.value
24+
}
25+
}
26+
}
27+
}
28+
29+
dynamic "identity" {
30+
for_each = length(var.identity_ids) > 0 ? [1] : []
31+
content {
32+
type = "UserAssigned"
33+
identity_ids = var.identity_ids
34+
}
35+
}
36+
37+
dynamic "customer_managed_key" {
38+
for_each = var.cmk_key_vault_key_id != null && length(var.identity_ids) > 0 ? [1] : []
39+
content {
40+
key_vault_key_id = var.cmk_key_vault_key_id
41+
identity_id = var.identity_ids[0]
42+
infrastructure_encryption_enabled = true
43+
}
44+
}
45+
46+
tags = var.tags
47+
}

0 commit comments

Comments
 (0)