Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_servicebus_namespace - support for the premium_messaging_partitions property #24676

Merged
merged 12 commits into from
Feb 20, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
19 changes: 19 additions & 0 deletions internal/services/servicebus/servicebus_namespace_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Comment on lines +351 to +353
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't match the schema validation above? The property defaults to 0 also.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for the premium namespace, 0 is not a valid value for premium namespace.

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)
}
Expand Down Expand Up @@ -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)
Expand Down
104 changes: 71 additions & 33 deletions internal/services/servicebus/servicebus_namespace_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't match the schema validation above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation error is for the premium namespaces

},
})
}

func TestAccAzureRMServiceBusNamespace_zoneRedundant(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace", "test")
r := ServiceBusNamespaceResource{}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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" {
Expand Down
22 changes: 12 additions & 10 deletions internal/services/servicebus/servicebus_queue_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
Loading
Loading