-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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_topic
- add premium namespace partition validation
#26680
base: main
Are you sure you want to change the base?
Conversation
isPremiumNamespacePartitioned := true | ||
var sku namespaces.SkuName | ||
if nsModel := resp.Model; nsModel != nil { | ||
sku = nsModel.Sku.Name | ||
} | ||
|
||
if sbNamespaceModel := resp.Model; sbNamespaceModel != nil { | ||
if sbNamespaceModel.Properties != nil && | ||
sbNamespaceModel.Properties.PremiumMessagingPartitions != nil && *sbNamespaceModel.Properties.PremiumMessagingPartitions == 1 { | ||
isPremiumNamespacePartitioned = false | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few things here:
- We can condense this so we only nil check the model once
- Sku is a pointer so this should be nil checked to prevent a potential panic
- Premium messaging partitions can be 0, 1, 2 or 4, I'm assuming any value other than 0 means that the namespace is partitioned so the condition should be updated to check whether premium messaging partitions is greater than 0 and set the bool to true if it is.
isPremiumNamespacePartitioned := true | |
var sku namespaces.SkuName | |
if nsModel := resp.Model; nsModel != nil { | |
sku = nsModel.Sku.Name | |
} | |
if sbNamespaceModel := resp.Model; sbNamespaceModel != nil { | |
if sbNamespaceModel.Properties != nil && | |
sbNamespaceModel.Properties.PremiumMessagingPartitions != nil && *sbNamespaceModel.Properties.PremiumMessagingPartitions == 1 { | |
isPremiumNamespacePartitioned = false | |
} | |
} | |
isPremiumNamespacePartitioned := false | |
var sku namespaces.SkuName | |
if model := resp.Model; model != nil { | |
if model.Sku != nil { | |
sku = model.Sku.Name | |
} | |
if props := model.Properties; props != nil && props.PremiumMessagingPartitions != nil && props.PremiumMessagingPartitions > 0 { | |
isPremiumNamespacePartitioned = true | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @stephybun for the comment. The message partition cannot be set to 0
for servicebus premium namespace. premium_messaging_partitions = 1
means the servicebus namespace is not partitioned, while value greater than 1 means the servicebus namespace is partitioned.
If the parent namespace is partitioned, the child entities such as queue and topic can't be set to the non-partitioned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provider accepts 0 as a value for partitioning. If the API doesn't allow this then we should also update the premium_messaging_partitions
property in the azurerm_servicebus_namespace
resource.
Furthermore, please still make the following changes since there are redundant nil checks and variable assignments in the original.
isPremiumNamespacePartitioned := true | |
var sku namespaces.SkuName | |
if nsModel := resp.Model; nsModel != nil { | |
sku = nsModel.Sku.Name | |
} | |
if sbNamespaceModel := resp.Model; sbNamespaceModel != nil { | |
if sbNamespaceModel.Properties != nil && | |
sbNamespaceModel.Properties.PremiumMessagingPartitions != nil && *sbNamespaceModel.Properties.PremiumMessagingPartitions == 1 { | |
isPremiumNamespacePartitioned = false | |
} | |
} | |
isPremiumNamespacePartitioned := true | |
var sku namespaces.SkuName | |
if model := resp.Model; model != nil { | |
if model.Sku != nil { | |
sku = model.Sku.Name | |
} | |
if props := model.Properties; props != nil && props.PremiumMessagingPartitions != nil && props.PremiumMessagingPartitions == 1 { | |
isPremiumNamespacePartitioned = false | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't set the default value to 1
as the premiumMessagingPartitions
also applies to standard namespace which has 0
as the default value.
Updated the nil check
|
||
if sku == namespaces.SkuNamePremium { | ||
if isPremiumNamespacePartitioned && !enablePartitioning { | ||
return fmt.Errorf("non-partitioned entities are not allowed in partitioned namespace") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be helpful to rephrase the error message into something actionable for the user
return fmt.Errorf("non-partitioned entities are not allowed in partitioned namespace") | |
return fmt.Errorf("topic must have `partitioning_enabled` set to `true` when the parent namespace is partitioned") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hasn't been updated and there is no response as to why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
Thanks @stephybun for the review, I left my comments in the thread. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xiaxyi please see responses
Sorry for the late response as I was out of office for the past two weeks. Please see my response and let me know if there is anything needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xiaxyi once the last round of comments have been resolved this should be good to go. Thanks!
if isPremiumNamespacePartitioned && !enablePartitioning { | ||
return fmt.Errorf("topic must have `partitioning_enabled` set to `true` when the parent namespace is partitioned") | ||
} else if !isPremiumNamespacePartitioned && enablePartitioning { | ||
return fmt.Errorf("the parent premium namespace is not partitioned and the partitioning for premium namespace is only available at the namepsace creation") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please re-write this
return fmt.Errorf("the parent premium namespace is not partitioned and the partitioning for premium namespace is only available at the namepsace creation") | |
return fmt.Errorf("topic partitioning is only available if the parent namespace is partitioned") |
data.ResourceTest(t, r, []acceptance.TestStep{ | ||
{ | ||
Config: r.nonPartitionedPremiumNamespaceError(data), | ||
ExpectError: regexp.MustCompile("the parent premium namespace is not partitioned and the partitioning for premium namespace is only available at the namepsace creation"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message needs to be updated
data.ResourceTest(t, r, []acceptance.TestStep{ | ||
{ | ||
Config: r.PremiumNamespacePartitioned(data, false), | ||
ExpectError: regexp.MustCompile("non-partitioned entities are not allowed in partitioned namespace"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message doesn't match what's been written in the resource
@@ -61,7 +61,7 @@ The following arguments are supported: | |||
|
|||
* `partitioning_enabled` - (Optional) Boolean flag which controls whether to enable the topic to be partitioned across multiple message brokers. Changing this forces a new resource to be created. | |||
|
|||
-> **NOTE:** Partitioning is available at entity creation for all queues and topics in Basic or Standard SKUs. It is not available for the Premium messaging SKU, but any previously existing partitioned entities in Premium namespaces continue to work as expected. Please [see the documentation](https://docs.microsoft.com/azure/service-bus-messaging/service-bus-partitioning) for more information. | |||
-> **NOTE:** Partitioning is available at entity creation for all queues and topics in Basic or Standard SKUs. It is not available for the Premium messaging SKU, but any previously existing partitioned entities in Premium namespaces continue to work as expected. For premium namespace, partitioning is available at namespace creation, and all queues and topics in the partitioned namespace will be partitioned, for the premium namespace that has `premium_messaging_partitions` sets to `1`, the namespace is not partitioned. Please [see the documentation](https://docs.microsoft.com/azure/service-bus-messaging/service-bus-partitioning) for more information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> **NOTE:** Partitioning is available at entity creation for all queues and topics in Basic or Standard SKUs. It is not available for the Premium messaging SKU, but any previously existing partitioned entities in Premium namespaces continue to work as expected. For premium namespace, partitioning is available at namespace creation, and all queues and topics in the partitioned namespace will be partitioned, for the premium namespace that has `premium_messaging_partitions` sets to `1`, the namespace is not partitioned. Please [see the documentation](https://docs.microsoft.com/azure/service-bus-messaging/service-bus-partitioning) for more information. | |
-> **NOTE:** Partitioning is available at entity creation for all queues and topics in Basic or Standard SKUs. It is not available for the Premium messaging SKU, but any previously existing partitioned entities in Premium namespaces continue to work as expected. For premium namespaces, partitioning is available at namespace creation and all queues and topics in the partitioned namespace will be partitioned. Premium namespaces that have `premium_messaging_partitions` set to `1` are not partitioned. Please [see the documentation](https://docs.microsoft.com/azure/service-bus-messaging/service-bus-partitioning) for more information. |
Community Note
Description
For premium service bus namespace, the setting of the partitioning feature for its entity such as servicebus namespace queue/ topic is only available during the namespace creation. Given the fact that the property
partitioning_enabled
is forcenew, there is a chance of unexpected deletion if user ignores the terraform plan message. Add a validation to warn the user.PR Checklist
For example: “
resource_name_here
- description of change e.g. adding propertynew_property_name_here
”Changes to existing Resource / Data Source
Testing
--- PASS: TestAccServiceBusTopic_nonPartitionedPremiumNamespaceError (280.30s)
PASS
ok github.com/hashicorp/terraform-provider-azurerm/internal/services/servicebus (cached)
--- PASS: TestAccServiceBusTopic_partitionedPremiumNamespace (338.72s)
PASS
ok github.com/hashicorp/terraform-provider-azurerm/internal/services/servicebus 355.206s
Change Log
Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.
azurerm_resource
- support for thething1
property [GH-00000]This is a (please select all that apply):
Related Issue(s)
Fixes #26642
Note
If this PR changes meaningfully during the course of review please update the title and description as required.