|
| 1 | +# variables.tf |
| 2 | + |
| 3 | +variable "resource_group_name" { |
| 4 | + description = "The name of the Azure Resource Group to deploy into. This template will create the RG if it does not exist (idempotent ARM PUT)." |
| 5 | + type = string |
| 6 | + |
| 7 | + validation { |
| 8 | + condition = length(trimspace(var.resource_group_name)) > 0 |
| 9 | + error_message = "resource_group_name must not be empty." |
| 10 | + } |
| 11 | +} |
| 12 | + |
| 13 | +variable "location" { |
| 14 | + description = "The Azure region where the Resource Group and Event Hubs resources will be created." |
| 15 | + type = string |
| 16 | + |
| 17 | + validation { |
| 18 | + condition = length(trimspace(var.location)) > 0 |
| 19 | + error_message = "location must not be empty." |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +variable "append_random_suffix" { |
| 24 | + description = "Whether to append a random suffix to globally-unique names (for example, the Event Hubs namespace) to avoid collisions." |
| 25 | + type = bool |
| 26 | + default = true |
| 27 | +} |
| 28 | + |
| 29 | +variable "random_suffix_length" { |
| 30 | + description = "Length of the random suffix appended when append_random_suffix is true." |
| 31 | + type = number |
| 32 | + default = 6 |
| 33 | + |
| 34 | + validation { |
| 35 | + condition = var.random_suffix_length >= 4 && var.random_suffix_length <= 16 |
| 36 | + error_message = "random_suffix_length must be between 4 and 16." |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +variable "tags" { |
| 41 | + description = "A map of tags to assign to the resources." |
| 42 | + type = map(string) |
| 43 | + default = {} |
| 44 | +} |
| 45 | + |
| 46 | +variable "eventhub_namespace_name" { |
| 47 | + description = "Base name of the Event Hubs namespace. If append_random_suffix is true, the final name will be '<base>-<suffix>'." |
| 48 | + type = string |
| 49 | + |
| 50 | + validation { |
| 51 | + condition = ( |
| 52 | + length(trimspace(var.eventhub_namespace_name)) >= 6 |
| 53 | + && length(var.eventhub_namespace_name) <= (var.append_random_suffix ? (50 - 1 - var.random_suffix_length) : 50) |
| 54 | + && can(regex("^[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$", var.eventhub_namespace_name)) |
| 55 | + ) |
| 56 | + error_message = "eventhub_namespace_name must be 6-50 chars, contain only alphanumeric or '-', start/end with alphanumeric, and leave room for '-<suffix>' when append_random_suffix is true." |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +variable "eventhub_name" { |
| 61 | + description = "Name of the Event Hub to create within the namespace." |
| 62 | + type = string |
| 63 | + |
| 64 | + validation { |
| 65 | + condition = ( |
| 66 | + length(trimspace(var.eventhub_name)) > 0 |
| 67 | + && length(var.eventhub_name) <= 256 |
| 68 | + && can(regex("^[a-zA-Z0-9][a-zA-Z0-9._-]*$", var.eventhub_name)) |
| 69 | + ) |
| 70 | + error_message = "eventhub_name must be 1-256 chars and contain only alphanumeric, '.', '_', or '-'." |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +variable "sku" { |
| 75 | + description = "Event Hubs namespace SKU. Allowed: Basic, Standard, Premium." |
| 76 | + type = string |
| 77 | + default = "Standard" |
| 78 | + |
| 79 | + validation { |
| 80 | + condition = contains(["Basic", "Standard", "Premium"], var.sku) |
| 81 | + error_message = "sku must be one of: Basic, Standard, Premium." |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +variable "capacity" { |
| 86 | + description = "Namespace capacity. For Basic, this is ignored. For Standard, it represents throughput units; for Premium, it represents messaging units." |
| 87 | + type = number |
| 88 | + default = 1 |
| 89 | + |
| 90 | + validation { |
| 91 | + condition = var.capacity >= 1 |
| 92 | + error_message = "capacity must be >= 1." |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +variable "partition_count" { |
| 97 | + description = "Number of partitions for the Event Hub." |
| 98 | + type = number |
| 99 | + default = 2 |
| 100 | + |
| 101 | + validation { |
| 102 | + condition = var.partition_count >= 1 && var.partition_count <= 32 |
| 103 | + error_message = "partition_count must be between 1 and 32." |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +variable "message_retention" { |
| 108 | + description = "Message retention in days for the Event Hub." |
| 109 | + type = number |
| 110 | + default = 1 |
| 111 | + |
| 112 | + validation { |
| 113 | + condition = var.message_retention >= 1 && var.message_retention <= 90 |
| 114 | + error_message = "message_retention must be between 1 and 90." |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +variable "consumer_group_names" { |
| 119 | + description = "Optional list of consumer group names to create for the Event Hub." |
| 120 | + type = list(string) |
| 121 | + default = [] |
| 122 | +} |
0 commit comments