azurerm_servicebus_topic - add premium namespace partition validation#26680
azurerm_servicebus_topic - add premium namespace partition validation#26680stephybun merged 8 commits intohashicorp:mainfrom
azurerm_servicebus_topic - add premium namespace partition validation#26680Conversation
| 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.
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.
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.
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.
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.
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.
This hasn't been updated and there is no response as to why?
|
Thanks @stephybun for the review, I left my comments in the thread. |
|
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. |
| 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.
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.
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.
This error message doesn't match what's been written in the resource
| * `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.
| -> **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. |
|
@stephybun Thanks for the review, code is updated and tests are passed: |
* CHANGELOG.md for v4.19.0 * Update CHANGELOG.md #28523 * Update CHANGELOG.md #28691 * Updated to include #28717 * Update for #26680 * Update CHANGELOG.md #28633 * Update CHANGELOG.md for #28703 * Update CHANGELOG.md for #28391 * Update CHANGELOG.md #28725 * Update #28733 * Update CHANGELOG.md #28659 * Update for #28741 * Update CHANGELOG.md #28712 * Update CHANGELOG.md #28441 * Update CHANGELOG.md #28441 * Update CHANGELOG.md #28441 * Update CHANGELOG.md for #28602 * Update for #27424 * Update CHANGELOG.md for #28524 * Update CHANGELOG.md #28726 * Update for #28767 * Update for #28195 * prep for release v4.19.0 --------- Co-authored-by: sreallymatt <[email protected]> Co-authored-by: Wodans Son <[email protected]> Co-authored-by: stephybun <[email protected]> Co-authored-by: Wyatt Fry <[email protected]> Co-authored-by: Matthew Frahry <[email protected]> Co-authored-by: jackofallops <[email protected]>
…on (hashicorp#26680) * add premium namespace partition validation * update test case to fit the 4.0 flag in teamCity * update test case - remove import step from the error validation test * simplify the test checks * update code per reviewer's comment * update code based on review
* CHANGELOG.md for v4.19.0 * Update CHANGELOG.md hashicorp#28523 * Update CHANGELOG.md hashicorp#28691 * Updated to include hashicorp#28717 * Update for hashicorp#26680 * Update CHANGELOG.md hashicorp#28633 * Update CHANGELOG.md for hashicorp#28703 * Update CHANGELOG.md for hashicorp#28391 * Update CHANGELOG.md hashicorp#28725 * Update hashicorp#28733 * Update CHANGELOG.md hashicorp#28659 * Update for hashicorp#28741 * Update CHANGELOG.md hashicorp#28712 * Update CHANGELOG.md hashicorp#28441 * Update CHANGELOG.md hashicorp#28441 * Update CHANGELOG.md hashicorp#28441 * Update CHANGELOG.md for hashicorp#28602 * Update for hashicorp#27424 * Update CHANGELOG.md for hashicorp#28524 * Update CHANGELOG.md hashicorp#28726 * Update for hashicorp#28767 * Update for hashicorp#28195 * prep for release v4.19.0 --------- Co-authored-by: sreallymatt <[email protected]> Co-authored-by: Wodans Son <[email protected]> Co-authored-by: stephybun <[email protected]> Co-authored-by: Wyatt Fry <[email protected]> Co-authored-by: Matthew Frahry <[email protected]> Co-authored-by: jackofallops <[email protected]>
|
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
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_enabledis 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 thething1property [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.