diff --git a/modules/azure-event-hub/.terraform-docs.yml b/modules/azure-event-hub/.terraform-docs.yml new file mode 100644 index 000000000..bce3ca3a9 --- /dev/null +++ b/modules/azure-event-hub/.terraform-docs.yml @@ -0,0 +1,48 @@ +formatter: "markdown" # this is required + +version: "" + +header-from: docs/header.md +footer-from: docs/footer.md + +recursive: + enabled: false + path: modules + include-main: true + +sections: + hide: [] + show: [] + +content: "" + +output: + file: "README.md" + mode: inject + template: |- + + {{ .Content }} + + +output-values: + enabled: false + from: "" + +sort: + enabled: true + by: name + +settings: + anchor: true + color: true + default: true + description: false + escape: true + hide-empty: false + html: true + indent: 2 + lockfile: true + read-comments: true + required: true + sensitive: true + type: true \ No newline at end of file diff --git a/modules/azure-event-hub/README.md b/modules/azure-event-hub/README.md index 369cde99d..f72417276 100644 --- a/modules/azure-event-hub/README.md +++ b/modules/azure-event-hub/README.md @@ -1,56 +1,27 @@ -## Requirements + +# Azure Event Hub Terraform Module -| Name | Version | -|------|---------| -| [terraform](#requirement\_terraform) | >= 1.7.0 | -| [azurerm](#requirement\_azurerm) | >= 4.51.0 | - -## Providers +## Overview -| Name | Version | -|------|---------| -| [azurerm](#provider\_azurerm) | >= 4.51.0 | - - -## Resources +This Terraform module allows you to create and manage a complete Azure Event Hub environment, including: +- Namespace, Event Hubs, authorization rules, and consumer groups. +- Integration with Event Grid System Topics and subscriptions. +- Advanced network, security, and scalability configuration. +- Flexible tagging and tag inheritance from the Resource Group. -| Name | Type | -|------|------| -| [azurerm_eventgrid_system_topic.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/eventgrid_system_topic) | resource | -| [azurerm_eventgrid_system_topic_event_subscription.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/eventgrid_system_topic_event_subscription) | resource | -| [azurerm_eventhub.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/eventhub) | resource | -| [azurerm_eventhub_authorization_rule.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/eventhub_authorization_rule) | resource | -| [azurerm_eventhub_consumer_group.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/eventhub_consumer_group) | resource | -| [azurerm_eventhub_namespace.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/eventhub_namespace) | resource | -| [azurerm_role_assignment.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) | resource | -| [azurerm_resource_group.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resource_group) | data source | +## Main features +- Create namespaces and multiple Event Hubs with custom configuration. +- Support for authorization rules, consumer groups, and event subscriptions. +- Integration with Event Grid System Topics. +- Network rules configuration (IP, VNet, public access, etc). -## Inputs - -| Name | Description | Type | Default | Required | -|------|-------------|------|---------|:--------:| -| [eventhub](#input\_eventhub) | n/a |
map(object({
name = string
partition_count = number
message_retention = number
consumer_group_names = list(string)
auth_rules = list(object({
name = string
listen = bool
send = bool
manage = bool
}))
event_subscription = optional(object({
name = string
included_event_types = list(string)
retry_ttl = number
max_attempts = number
}))
system_topic_name = optional(string)
}))
| n/a | yes | -| [namespace](#input\_namespace) | n/a |
object({
name = string
location = string
resource_group_name = string
sku = string
capacity = number
auto_inflate_enabled = bool
identity_type = string
ruleset = object({
default_action = string
public_network_access_enabled = bool
trusted_service_access_enabled = bool
virtual_network_rules = optional(list(object({
subnet_id = string
ignore_missing_virtual_network_service_endpoint = optional(bool)
})), [])
ip_rules = optional(list(object({
ip_mask = string
action = string
})), [])
})
})
| n/a | yes | -| [system\_topic](#input\_system\_topic) | n/a |
map(object({
name = string
location = string
topic_type = string
source_resource_id = string
}))
| n/a | yes | -| [tags](#input\_tags) | Tags to apply to resources | `map(string)` | `{}` | no | -| [tags\_from\_rg](#input\_tags\_from\_rg) | Use resource group tags as base for module tags | `bool` | `false` | no | - -## Outputs - -| Name | Description | -|------|-------------| -| [eventhub\_id](#output\_eventhub\_id) | n/a | -| [eventhub\_namespace\_id](#output\_eventhub\_namespace\_id) | Outputs | - - -## Example of Usage +## Complete usage example ```yaml values: tags_from_rg: true tags: extra_tag: "example" - namespace: name: "example-namespace" location: "westeurope" @@ -68,14 +39,12 @@ values: action: "Allow" - ip_mask: "10.0.0.2" action: "Allow" - system_topic: topic-events: name: "topic-events" location: "global" topic_type: "Microsoft.Resources.Subscriptions" source_resource_id: "/subscriptions/00000000-0000-0000-0000-000000000000" - eventhub: events-hub: name: "events-hub" @@ -117,3 +86,89 @@ values: send: true manage: false ``` + +## Notes +- In each `eventhub` entry, `system_topic_name` must be the **map key** of the linked entry in `system_topic` (e.g. `topic-events`), not the topic's `name` attribute. +- In HCL, map keys that contain hyphens (e.g. `example-topic`, `example-hub`) must be quoted: `"example-topic" = { ... }`. + +## File structure + +``` +. +├── main.tf +├── variables.tf +├── outputs.tf +├── README.md +├── CHANGELOG.md +└── docs/ + ├── header.md + └── footer.md +``` + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 1.7.0 | +| [azurerm](#requirement\_azurerm) | >= 4.51.0 | + +## Providers + +| Name | Version | +|------|---------| +| [azurerm](#provider\_azurerm) | >= 4.51.0 | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [azurerm_eventgrid_system_topic.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/eventgrid_system_topic) | resource | +| [azurerm_eventgrid_system_topic_event_subscription.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/eventgrid_system_topic_event_subscription) | resource | +| [azurerm_eventhub.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/eventhub) | resource | +| [azurerm_eventhub_authorization_rule.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/eventhub_authorization_rule) | resource | +| [azurerm_eventhub_consumer_group.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/eventhub_consumer_group) | resource | +| [azurerm_eventhub_namespace.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/eventhub_namespace) | resource | +| [azurerm_role_assignment.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) | resource | +| [azurerm_resource_group.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resource_group) | data source | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [eventhub](#input\_eventhub) | n/a |
map(object({
name = string
partition_count = number
message_retention = number
consumer_group_names = list(string)
auth_rules = list(object({
name = string
listen = bool
send = bool
manage = bool
}))
event_subscription = optional(object({
name = string
included_event_types = list(string)
retry_ttl = number
max_attempts = number
}))
system_topic_name = optional(string)
}))
| n/a | yes | +| [namespace](#input\_namespace) | n/a |
object({
name = string
location = string
resource_group_name = string
sku = string
capacity = number
auto_inflate_enabled = bool
identity_type = string
ruleset = object({
default_action = string
public_network_access_enabled = bool
trusted_service_access_enabled = bool
virtual_network_rules = optional(list(object({
subnet_id = string
ignore_missing_virtual_network_service_endpoint = optional(bool)
})), [])
ip_rules = optional(list(object({
ip_mask = string
action = string
})), [])
})
})
| n/a | yes | +| [system\_topic](#input\_system\_topic) | n/a |
map(object({
name = string
location = string
topic_type = string
source_resource_id = string
}))
| n/a | yes | +| [tags](#input\_tags) | Tags to apply to resources | `map(string)` | `{}` | no | +| [tags\_from\_rg](#input\_tags\_from\_rg) | Use resource group tags as base for module tags | `bool` | `false` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| [eventhub\_id](#output\_eventhub\_id) | n/a | +| [eventhub\_namespace\_id](#output\_eventhub\_namespace\_id) | Outputs | + +--- + +## Examples + +For detailed examples, refer to the [module examples](https://github.com/prefapp/tfm/tree/main/modules/azure-event-hub/_examples): + +- [basic](https://github.com/prefapp/tfm/tree/main/modules/azure-event-hub/_examples/basic) - Event Hub namespace with a basic event hub and optional system topic integration. + +## Additional resources + +- [Azure Event Hubs](https://learn.microsoft.com/en-us/azure/event-hubs/) +- [Terraform AzureRM Provider - azurerm\_eventhub](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/eventhub) +- [Terraform AzureRM Provider - azurerm\_eventhub\_namespace](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/eventhub_namespace) +- [Terraform AzureRM Provider - azurerm\_eventgrid\_system\_topic](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/eventgrid_system_topic) +- [Official Terraform documentation](https://www.terraform.io/docs) + +## Support + +For issues, questions, or contributions related to this module, please visit the repository’s issue tracker: [https://github.com/prefapp/tfm/issues](https://github.com/prefapp/tfm/issues) + \ No newline at end of file diff --git a/modules/azure-event-hub/_examples/basic/main.tf b/modules/azure-event-hub/_examples/basic/main.tf new file mode 100644 index 000000000..85710d0d3 --- /dev/null +++ b/modules/azure-event-hub/_examples/basic/main.tf @@ -0,0 +1,53 @@ +module "azure_event_hub" { + source = "../../" + + namespace = { + name = "example-namespace" + location = "westeurope" + resource_group_name = "example-rg" + sku = "Standard" + capacity = 1 + auto_inflate_enabled = false + identity_type = "SystemAssigned" + ruleset = { + default_action = "Allow" + public_network_access_enabled = true + trusted_service_access_enabled = true + virtual_network_rules = [] + ip_rules = [] + } + } + + system_topic = { + "example-topic" = { + name = "example-system-topic" + location = "westeurope" + topic_type = "Microsoft.EventHub.namespaces" + source_resource_id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.EventHub/namespaces/example-namespace" + } + } + + eventhub = { + "example-hub" = { + name = "example-eventhub" + partition_count = 2 + message_retention = 7 + consumer_group_names = ["$Default"] + auth_rules = [ + { + name = "listen" + listen = true + send = false + manage = false + } + ] + event_subscription = null + system_topic_name = "example-topic" + } + } + + tags_from_rg = false + tags = { + environment = "dev" + } +} diff --git a/modules/azure-event-hub/_examples/basic/values.yaml b/modules/azure-event-hub/_examples/basic/values.yaml new file mode 100644 index 000000000..bcc308a1b --- /dev/null +++ b/modules/azure-event-hub/_examples/basic/values.yaml @@ -0,0 +1,40 @@ +namespace: + name: example-namespace + location: westeurope + resource_group_name: example-rg + sku: Standard + capacity: 1 + auto_inflate_enabled: false + identity_type: SystemAssigned + ruleset: + default_action: Allow + public_network_access_enabled: true + trusted_service_access_enabled: true + virtual_network_rules: [] + ip_rules: [] + +system_topic: + example-topic: + name: example-system-topic + location: westeurope + topic_type: Microsoft.EventHub.namespaces + source_resource_id: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.EventHub/namespaces/example-namespace + +eventhub: + example-hub: + name: example-eventhub + partition_count: 2 + message_retention: 7 + consumer_group_names: + - $Default + auth_rules: + - name: listen + listen: true + send: false + manage: false + event_subscription: null + system_topic_name: example-topic + +tags_from_rg: false +tags: + environment: dev diff --git a/modules/azure-event-hub/docs/footer.md b/modules/azure-event-hub/docs/footer.md new file mode 100644 index 000000000..20d8765f2 --- /dev/null +++ b/modules/azure-event-hub/docs/footer.md @@ -0,0 +1,19 @@ +--- + +## Examples + +For detailed examples, refer to the [module examples](https://github.com/prefapp/tfm/tree/main/modules/azure-event-hub/_examples): + +- [basic](https://github.com/prefapp/tfm/tree/main/modules/azure-event-hub/_examples/basic) - Event Hub namespace with a basic event hub and optional system topic integration. + +## Additional resources + +- [Azure Event Hubs](https://learn.microsoft.com/en-us/azure/event-hubs/) +- [Terraform AzureRM Provider - azurerm_eventhub](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/eventhub) +- [Terraform AzureRM Provider - azurerm_eventhub_namespace](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/eventhub_namespace) +- [Terraform AzureRM Provider - azurerm_eventgrid_system_topic](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/eventgrid_system_topic) +- [Official Terraform documentation](https://www.terraform.io/docs) + +## Support + +For issues, questions, or contributions related to this module, please visit the repository’s issue tracker: [https://github.com/prefapp/tfm/issues](https://github.com/prefapp/tfm/issues) \ No newline at end of file diff --git a/modules/azure-event-hub/docs/header.md b/modules/azure-event-hub/docs/header.md new file mode 100644 index 000000000..abf269a07 --- /dev/null +++ b/modules/azure-event-hub/docs/header.md @@ -0,0 +1,105 @@ +# Azure Event Hub Terraform Module + +## Overview + +This Terraform module allows you to create and manage a complete Azure Event Hub environment, including: +- Namespace, Event Hubs, authorization rules, and consumer groups. +- Integration with Event Grid System Topics and subscriptions. +- Advanced network, security, and scalability configuration. +- Flexible tagging and tag inheritance from the Resource Group. + +## Main features +- Create namespaces and multiple Event Hubs with custom configuration. +- Support for authorization rules, consumer groups, and event subscriptions. +- Integration with Event Grid System Topics. +- Network rules configuration (IP, VNet, public access, etc). + +## Complete usage example + +```yaml +values: + tags_from_rg: true + tags: + extra_tag: "example" + namespace: + name: "example-namespace" + location: "westeurope" + resource_group_name: "example-resource-group" + sku: "Standard" + capacity: 1 + auto_inflate_enabled: false + identity_type: "SystemAssigned" + ruleset: + default_action: "Deny" + public_network_access_enabled: true + trusted_service_access_enabled: true + ip_rules: + - ip_mask: "10.0.0.1" + action: "Allow" + - ip_mask: "10.0.0.2" + action: "Allow" + system_topic: + topic-events: + name: "topic-events" + location: "global" + topic_type: "Microsoft.Resources.Subscriptions" + source_resource_id: "/subscriptions/00000000-0000-0000-0000-000000000000" + eventhub: + events-hub: + name: "events-hub" + partition_count: 1 + message_retention: 1 + consumer_group_names: + - "events-subscription" + - "external-processor" + auth_rules: + - name: "external-listen" + listen: true + send: false + manage: false + event_subscription: + name: "events-subscription" + included_event_types: + - "Microsoft.Resources.ResourceWriteSuccess" + - "Microsoft.Resources.ResourceWriteFailure" + - "Microsoft.Resources.ResourceWriteCancel" + - "Microsoft.Resources.ResourceDeleteSuccess" + - "Microsoft.Resources.ResourceDeleteFailure" + - "Microsoft.Resources.ResourceDeleteCancel" + - "Microsoft.Resources.ResourceActionSuccess" + - "Microsoft.Resources.ResourceActionFailure" + - "Microsoft.Resources.ResourceActionCancel" + retry_ttl: 1440 + max_attempts: 30 + system_topic_name: "topic-events" + logs-hub: + name: "logs-hub" + partition_count: 1 + message_retention: 1 + consumer_group_names: + - "app-logs" + - "infra-logs" + auth_rules: + - name: "app-fluentbit-agent" + listen: false + send: true + manage: false +``` + +## Notes +- In each `eventhub` entry, `system_topic_name` must be the **map key** of the linked entry in `system_topic` (e.g. `topic-events`), not the topic's `name` attribute. +- In HCL, map keys that contain hyphens (e.g. `example-topic`, `example-hub`) must be quoted: `"example-topic" = { ... }`. + +## File structure + +``` +. +├── main.tf +├── variables.tf +├── outputs.tf +├── README.md +├── CHANGELOG.md +└── docs/ + ├── header.md + └── footer.md +``` \ No newline at end of file