diff --git a/internal/services/servicebus/servicebus_namespace_authorization_rule_resource_test.go b/internal/services/servicebus/servicebus_namespace_authorization_rule_resource_test.go index a5dfd834ac2a..5496f1e56922 100644 --- a/internal/services/servicebus/servicebus_namespace_authorization_rule_resource_test.go +++ b/internal/services/servicebus/servicebus_namespace_authorization_rule_resource_test.go @@ -180,19 +180,21 @@ resource "azurerm_resource_group" "secondary" { } resource "azurerm_servicebus_namespace" "primary_namespace_test" { - name = "acctest1-%[1]d" - location = azurerm_resource_group.primary.location - resource_group_name = azurerm_resource_group.primary.name - sku = "Premium" - capacity = "1" + name = "acctest1-%[1]d" + location = azurerm_resource_group.primary.location + resource_group_name = azurerm_resource_group.primary.name + sku = "Premium" + premium_messaging_partitions = 1 + capacity = "1" } resource "azurerm_servicebus_namespace" "secondary_namespace_test" { - name = "acctest2-%[1]d" - location = azurerm_resource_group.secondary.location - resource_group_name = azurerm_resource_group.secondary.name - sku = "Premium" - capacity = "1" + name = "acctest2-%[1]d" + location = azurerm_resource_group.secondary.location + resource_group_name = azurerm_resource_group.secondary.name + sku = "Premium" + premium_messaging_partitions = 1 + capacity = "1" } resource "azurerm_servicebus_namespace_disaster_recovery_config" "pairing_test" { diff --git a/internal/services/servicebus/servicebus_namespace_data_source.go b/internal/services/servicebus/servicebus_namespace_data_source.go index e89deb99ed9b..12486ba13628 100644 --- a/internal/services/servicebus/servicebus_namespace_data_source.go +++ b/internal/services/servicebus/servicebus_namespace_data_source.go @@ -50,6 +50,11 @@ func dataSourceServiceBusNamespace() *pluginsdk.Resource { Computed: true, }, + "premium_messaging_partitions": { + Type: pluginsdk.TypeInt, + Computed: true, + }, + "default_primary_connection_string": { Type: pluginsdk.TypeString, Computed: true, @@ -116,6 +121,7 @@ func dataSourceServiceBusNamespaceRead(d *pluginsdk.ResourceData, meta interface } if props := model.Properties; props != nil { + d.Set("premium_messaging_partitions", props.PremiumMessagingPartitions) d.Set("zone_redundant", props.ZoneRedundant) d.Set("endpoint", props.ServiceBusEndpoint) } diff --git a/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_test.go b/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_test.go index 99903a81fff4..27509456dc3a 100644 --- a/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_test.go +++ b/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_test.go @@ -63,19 +63,21 @@ resource "azurerm_resource_group" "secondary" { } resource "azurerm_servicebus_namespace" "primary_namespace_test" { - name = "acctest1-%[1]d" - location = azurerm_resource_group.primary.location - resource_group_name = azurerm_resource_group.primary.name - sku = "Premium" - capacity = "1" + name = "acctest1-%[1]d" + location = azurerm_resource_group.primary.location + resource_group_name = azurerm_resource_group.primary.name + sku = "Premium" + capacity = "1" + premium_messaging_partitions = 1 } resource "azurerm_servicebus_namespace" "secondary_namespace_test" { - name = "acctest2-%[1]d" - location = azurerm_resource_group.secondary.location - resource_group_name = azurerm_resource_group.secondary.name - sku = "Premium" - capacity = "1" + name = "acctest2-%[1]d" + location = azurerm_resource_group.secondary.location + resource_group_name = azurerm_resource_group.secondary.name + sku = "Premium" + capacity = "1" + premium_messaging_partitions = 1 } resource "azurerm_servicebus_namespace_disaster_recovery_config" "pairing_test" { diff --git a/internal/services/servicebus/servicebus_namespace_network_rule_set_resource_test.go b/internal/services/servicebus/servicebus_namespace_network_rule_set_resource_test.go index 21d28bb98a81..713d99e8851c 100644 --- a/internal/services/servicebus/servicebus_namespace_network_rule_set_resource_test.go +++ b/internal/services/servicebus/servicebus_namespace_network_rule_set_resource_test.go @@ -157,12 +157,12 @@ resource "azurerm_resource_group" "test" { } resource "azurerm_servicebus_namespace" "test" { - name = "acctest-sb-namespace-%[1]d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - sku = "Premium" - - capacity = 1 + name = "acctest-sb-namespace-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Premium" + premium_messaging_partitions = 1 + capacity = 1 } resource "azurerm_virtual_network" "test" { diff --git a/internal/services/servicebus/servicebus_namespace_resource.go b/internal/services/servicebus/servicebus_namespace_resource.go index 96c932b7a2f6..56fa2647cbb8 100644 --- a/internal/services/servicebus/servicebus_namespace_resource.go +++ b/internal/services/servicebus/servicebus_namespace_resource.go @@ -97,6 +97,14 @@ func resourceServiceBusNamespace() *pluginsdk.Resource { ValidateFunc: validation.IntInSlice([]int{0, 1, 2, 4, 8, 16}), }, + "premium_messaging_partitions": { + Type: pluginsdk.TypeInt, + ForceNew: true, + Default: 0, + Optional: true, + ValidateFunc: validation.IntInSlice([]int{0, 1, 2, 4}), + }, + "customer_managed_key": { Type: pluginsdk.TypeList, Optional: true, @@ -336,6 +344,16 @@ func resourceServiceBusNamespaceCreateUpdate(d *pluginsdk.ResourceData, meta int parameters.Sku.Capacity = utils.Int64(int64(capacity.(int))) } + if premiumMessagingUnit := d.Get("premium_messaging_partitions"); premiumMessagingUnit != nil { + if !strings.EqualFold(sku, string(namespaces.SkuNamePremium)) && premiumMessagingUnit.(int) > 0 { + return fmt.Errorf("Premium messaging partition is not supported by service Bus SKU %q and it can only be set to 0", sku) + } + if strings.EqualFold(sku, string(namespaces.SkuNamePremium)) && premiumMessagingUnit.(int) == 0 { + return fmt.Errorf("Service Bus SKU %q only supports `premium_messaging_partitions` of 1, 2, 4", sku) + } + parameters.Properties.PremiumMessagingPartitions = utils.Int64(int64(premiumMessagingUnit.(int))) + } + if err := client.CreateOrUpdateThenPoll(ctx, id, parameters); err != nil { return fmt.Errorf("creating/updating %s: %+v", id, err) } @@ -411,6 +429,7 @@ func resourceServiceBusNamespaceRead(d *pluginsdk.ResourceData, meta interface{} d.Set("capacity", sku.Capacity) if props := model.Properties; props != nil { + d.Set("premium_messaging_partitions", props.PremiumMessagingPartitions) d.Set("zone_redundant", props.ZoneRedundant) if customerManagedKey, err := flattenServiceBusNamespaceEncryption(props.Encryption); err == nil { d.Set("customer_managed_key", customerManagedKey) diff --git a/internal/services/servicebus/servicebus_namespace_resource_test.go b/internal/services/servicebus/servicebus_namespace_resource_test.go index 08e55b520226..81ef24184e93 100644 --- a/internal/services/servicebus/servicebus_namespace_resource_test.go +++ b/internal/services/servicebus/servicebus_namespace_resource_test.go @@ -139,6 +139,17 @@ func TestAccAzureRMServiceBusNamespace_premiumCapacity(t *testing.T) { }) } +func TestAccAzureRMServiceBusNamespace_premiumMessagingPartition(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace", "test") + r := ServiceBusNamespaceResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.premiumMessagingPartition(data), + ExpectError: regexp.MustCompile("Service Bus SKU \"Premium\" only supports `premium_messaging_partitions` of 1, 2, 4"), + }, + }) +} + func TestAccAzureRMServiceBusNamespace_zoneRedundant(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace", "test") r := ServiceBusNamespaceResource{} @@ -404,11 +415,12 @@ resource "azurerm_resource_group" "test" { } resource "azurerm_servicebus_namespace" "test" { - name = "acctestservicebusnamespace-%d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - sku = "Premium" - capacity = 1 + name = "acctestservicebusnamespace-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Premium" + capacity = 4 + premium_messaging_partitions = 1 } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } @@ -445,12 +457,34 @@ resource "azurerm_resource_group" "test" { location = "%s" } +resource "azurerm_servicebus_namespace" "test" { + name = "acctestservicebusnamespace-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Premium" + capacity = 0 + premium_messaging_partitions = 1 +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} + +func (ServiceBusNamespaceResource) premiumMessagingPartition(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + resource "azurerm_servicebus_namespace" "test" { name = "acctestservicebusnamespace-%d" location = azurerm_resource_group.test.location resource_group_name = azurerm_resource_group.test.name sku = "Premium" - capacity = 0 + capacity = 2 } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } @@ -467,12 +501,13 @@ resource "azurerm_resource_group" "test" { } resource "azurerm_servicebus_namespace" "test" { - name = "acctestservicebusnamespace-%d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - sku = "Premium" - capacity = 1 - zone_redundant = true + name = "acctestservicebusnamespace-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Premium" + premium_messaging_partitions = 1 + capacity = 1 + zone_redundant = true } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } @@ -631,11 +666,12 @@ resource "azurerm_key_vault_key" "test" { } resource "azurerm_servicebus_namespace" "test" { - name = "acctestservicebusnamespace-%[2]d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - sku = "Premium" - capacity = 1 + name = "acctestservicebusnamespace-%[2]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Premium" + premium_messaging_partitions = 1 + capacity = 1 identity { type = "UserAssigned" @@ -724,11 +760,12 @@ resource "azurerm_subnet" "test" { } resource "azurerm_servicebus_namespace" "test" { - name = "acctestservicebusnamespace-%[1]d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - sku = "Premium" - capacity = 1 + name = "acctestservicebusnamespace-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Premium" + capacity = 1 + premium_messaging_partitions = 1 network_rule_set { default_action = "Deny" @@ -771,12 +808,12 @@ resource "azurerm_subnet" "test" { } resource "azurerm_servicebus_namespace" "test" { - name = "acctestservicebusnamespace-%[1]d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - sku = "Premium" - capacity = 1 - + name = "acctestservicebusnamespace-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Premium" + capacity = 1 + premium_messaging_partitions = 1 network_rule_set { default_action = "Deny" trusted_services_allowed = true @@ -822,11 +859,12 @@ resource "azurerm_subnet" "test" { } resource "azurerm_servicebus_namespace" "test" { - name = "acctestservicebusnamespace-%[1]d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - sku = "Premium" - capacity = 1 + name = "acctestservicebusnamespace-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Premium" + capacity = 1 + premium_messaging_partitions = 1 network_rule_set {} } diff --git a/internal/services/servicebus/servicebus_queue_authorization_rule_resource_test.go b/internal/services/servicebus/servicebus_queue_authorization_rule_resource_test.go index 10e47ebdce41..1b2591b9188c 100644 --- a/internal/services/servicebus/servicebus_queue_authorization_rule_resource_test.go +++ b/internal/services/servicebus/servicebus_queue_authorization_rule_resource_test.go @@ -219,11 +219,12 @@ resource "azurerm_resource_group" "secondary" { } resource "azurerm_servicebus_namespace" "primary_namespace_test" { - name = "acctest1-%[1]d" - location = azurerm_resource_group.primary.location - resource_group_name = azurerm_resource_group.primary.name - sku = "Premium" - capacity = "1" + name = "acctest1-%[1]d" + location = azurerm_resource_group.primary.location + resource_group_name = azurerm_resource_group.primary.name + sku = "Premium" + capacity = "1" + premium_messaging_partitions = 1 } resource "azurerm_servicebus_queue" "example" { @@ -232,11 +233,12 @@ resource "azurerm_servicebus_queue" "example" { } resource "azurerm_servicebus_namespace" "secondary_namespace_test" { - name = "acctest2-%[1]d" - location = azurerm_resource_group.secondary.location - resource_group_name = azurerm_resource_group.secondary.name - sku = "Premium" - capacity = "1" + name = "acctest2-%[1]d" + location = azurerm_resource_group.secondary.location + resource_group_name = azurerm_resource_group.secondary.name + sku = "Premium" + capacity = "1" + premium_messaging_partitions = 1 } resource "azurerm_servicebus_namespace_disaster_recovery_config" "pairing_test" { diff --git a/internal/services/servicebus/servicebus_queue_resource_test.go b/internal/services/servicebus/servicebus_queue_resource_test.go index d04cdc0f2c01..95f5e6a1d5b7 100644 --- a/internal/services/servicebus/servicebus_queue_resource_test.go +++ b/internal/services/servicebus/servicebus_queue_resource_test.go @@ -435,11 +435,12 @@ resource "azurerm_resource_group" "test" { } resource "azurerm_servicebus_namespace" "test" { - name = "acctestservicebusnamespace-%d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - sku = "Premium" - capacity = 1 + name = "acctestservicebusnamespace-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + sku = "Premium" + premium_messaging_partitions = 1 + capacity = 1 } resource "azurerm_servicebus_queue" "test" { @@ -465,11 +466,12 @@ resource "azurerm_resource_group" "test" { } resource "azurerm_servicebus_namespace" "test" { - name = "acctestservicebusnamespace-%d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - sku = "Premium" - capacity = 1 + name = "acctestservicebusnamespace-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + sku = "Premium" + premium_messaging_partitions = 1 + capacity = 1 } resource "azurerm_servicebus_queue" "test" { diff --git a/internal/services/servicebus/servicebus_subscription_resource_test.go b/internal/services/servicebus/servicebus_subscription_resource_test.go index 7bc338a64fa5..d5402e3cffa4 100644 --- a/internal/services/servicebus/servicebus_subscription_resource_test.go +++ b/internal/services/servicebus/servicebus_subscription_resource_test.go @@ -396,11 +396,12 @@ resource "azurerm_resource_group" "test" { } resource "azurerm_servicebus_namespace" "test" { - name = "acctestsbn-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - sku = "Premium" - capacity = 1 + name = "acctestsbn-%[1]d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + sku = "Premium" + premium_messaging_partitions = 1 + capacity = 1 } resource "azurerm_servicebus_topic" "test" { diff --git a/internal/services/servicebus/servicebus_topic_authorization_rule_resource_test.go b/internal/services/servicebus/servicebus_topic_authorization_rule_resource_test.go index ca9abc725ddf..c87a2b3c4468 100644 --- a/internal/services/servicebus/servicebus_topic_authorization_rule_resource_test.go +++ b/internal/services/servicebus/servicebus_topic_authorization_rule_resource_test.go @@ -219,11 +219,12 @@ resource "azurerm_resource_group" "secondary" { } resource "azurerm_servicebus_namespace" "primary_namespace_test" { - name = "acctest1-%[1]d" - location = azurerm_resource_group.primary.location - resource_group_name = azurerm_resource_group.primary.name - sku = "Premium" - capacity = "1" + name = "acctest1-%[1]d" + location = azurerm_resource_group.primary.location + resource_group_name = azurerm_resource_group.primary.name + sku = "Premium" + premium_messaging_partitions = 1 + capacity = "1" } resource "azurerm_servicebus_topic" "example" { @@ -232,11 +233,12 @@ resource "azurerm_servicebus_topic" "example" { } resource "azurerm_servicebus_namespace" "secondary_namespace_test" { - name = "acctest2-%[1]d" - location = azurerm_resource_group.secondary.location - resource_group_name = azurerm_resource_group.secondary.name - sku = "Premium" - capacity = "1" + name = "acctest2-%[1]d" + location = azurerm_resource_group.secondary.location + resource_group_name = azurerm_resource_group.secondary.name + sku = "Premium" + premium_messaging_partitions = 1 + capacity = "1" } resource "azurerm_servicebus_namespace_disaster_recovery_config" "pairing_test" { diff --git a/internal/services/servicebus/servicebus_topic_resource_test.go b/internal/services/servicebus/servicebus_topic_resource_test.go index 309c2845b14f..7c9e9f87101d 100644 --- a/internal/services/servicebus/servicebus_topic_resource_test.go +++ b/internal/services/servicebus/servicebus_topic_resource_test.go @@ -377,11 +377,12 @@ resource "azurerm_resource_group" "test" { } resource "azurerm_servicebus_namespace" "test" { - name = "acctestservicebusnamespace-%d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - sku = "Premium" - capacity = 1 + name = "acctestservicebusnamespace-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Premium" + premium_messaging_partitions = 1 + capacity = 1 } resource "azurerm_servicebus_topic" "test" { @@ -433,11 +434,12 @@ resource "azurerm_resource_group" "test" { } resource "azurerm_servicebus_namespace" "test" { - name = "acctestservicebusnamespace-%d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - sku = "Premium" - capacity = 1 + name = "acctestservicebusnamespace-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Premium" + premium_messaging_partitions = 1 + capacity = 1 } resource "azurerm_servicebus_topic" "test" { diff --git a/website/docs/d/servicebus_namespace.html.markdown b/website/docs/d/servicebus_namespace.html.markdown index 95f566b6b442..6df2db80db3e 100644 --- a/website/docs/d/servicebus_namespace.html.markdown +++ b/website/docs/d/servicebus_namespace.html.markdown @@ -37,6 +37,8 @@ output "location" { * `capacity` - The capacity of the ServiceBus Namespace. +* `premium_messaging_partitions` - The messaging partitions of the ServiceBus Namespace. + * `zone_redundant` - Whether or not this ServiceBus Namespace is zone redundant. * `endpoint` - The URL to access the ServiceBus Namespace. diff --git a/website/docs/r/servicebus_namespace.html.markdown b/website/docs/r/servicebus_namespace.html.markdown index 045d6698fa04..434956c562bc 100644 --- a/website/docs/r/servicebus_namespace.html.markdown +++ b/website/docs/r/servicebus_namespace.html.markdown @@ -51,6 +51,10 @@ The following arguments are supported: * `capacity` - (Optional) Specifies the capacity. When `sku` is `Premium`, capacity can be `1`, `2`, `4`, `8` or `16`. When `sku` is `Basic` or `Standard`, capacity can be `0` only. +* `premium_messaging_partitions` - (Optional) Specifies the number messaging partitions. Only valid when `sku` is `Premium` and the minimum number is `1`. Possible values include `0`, `1`, `2`, and `4`. Defaults to `0` for Standard, Basic namespace. Changing this forces a new resource to be created. + +-> **Note:** It's not possible to change the partitioning option on any existing namespace. The number of partitions can only be set during namespace creation. Please check the doc https://learn.microsoft.com/en-us/azure/service-bus-messaging/enable-partitions-premium for more feature restrictions. + * `customer_managed_key` - (Optional) An `customer_managed_key` block as defined below. * `local_auth_enabled` - (Optional) Whether or not SAS authentication is enabled for the Service Bus namespace. Defaults to `true`.