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_topic - add premium namespace partition validation #26680

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

xiaxyi
Copy link
Contributor

@xiaxyi xiaxyi commented Jul 18, 2024

Community Note

  • Please vote on this PR by adding a 👍 reaction to the original PR to help the community and maintainers prioritize for review
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for PR followers and do not help prioritize for review

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

  • I have followed the guidelines in our Contributing Documentation.
  • I have checked to ensure there aren't other open Pull Requests for the same update/change.
  • I have checked if my changes close any open issues. If so please include appropriate closing keywords below.
  • I have updated/added Documentation as required written in a helpful and kind way to assist users that may be unfamiliar with the resource / data source.
  • I have used a meaningful PR title to help maintainers and other users understand this change and help prevent duplicate work.
    For example: “resource_name_here - description of change e.g. adding property new_property_name_here

Changes to existing Resource / Data Source

  • I have added an explanation of what my changes do and why I'd like you to include them (This may be covered by linking to an issue above, but may benefit from additional explanation).
  • I have written new tests for my resource or datasource changes & updated any relevent documentation.
  • I have successfully run tests with my changes locally. If not, please provide details on testing challenges that prevented you running the tests.
  • (For changes that include a state migration only). I have manually tested the migration path between relevant versions of the provider.

Testing

  • My submission includes Test coverage as described in the Contribution Guide and the tests pass. (if this is not possible for any reason, please include details of why you did or could not add test coverage)

--- 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 the thing1 property [GH-00000]

This is a (please select all that apply):

  • Bug Fix
  • New Feature (ie adding a service, resource, or data source)
  • Enhancement
  • Breaking Change

Related Issue(s)

Fixes #26642

Note

If this PR changes meaningfully during the course of review please update the title and description as required.

@xiaxyi xiaxyi marked this pull request as draft July 18, 2024 10:01
@xiaxyi xiaxyi marked this pull request as ready for review July 19, 2024 02:43
Comment on lines 286 to 297
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
}
}
Copy link
Member

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.
Suggested change
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
}
}

Copy link
Contributor Author

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.

Copy link
Member

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.

Suggested change
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
}
}

Copy link
Contributor Author

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")
Copy link
Member

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

Suggested change
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")

Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@xiaxyi
Copy link
Contributor Author

xiaxyi commented Aug 8, 2024

Thanks @stephybun for the review, I left my comments in the thread.

Copy link
Member

@stephybun stephybun left a 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

@xiaxyi
Copy link
Contributor Author

xiaxyi commented Aug 27, 2024

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.

@katbyte katbyte requested review from katbyte and a team as code owners November 14, 2024 00:08
Copy link
Member

@stephybun stephybun left a 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")
Copy link
Member

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

Suggested change
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"),
Copy link
Member

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"),
Copy link
Member

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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
-> **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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

azurerm_servicebus_topic enable_partitioning validation for Premium
3 participants