hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.53k stars 4.61k forks source link

Support for default rule filter when creating Azure Service Bus subscription #20718

Open gscher opened 1 year ago

gscher commented 1 year ago

Is there an existing issue for this?

Community Note

Description

When adding a new subscription to an Azure service bus topic, implicitly a default subscription rule is created with a TrueRuleFilter (e.g., for .Net SDK) that enables all messages in the topic to reach the subscription.

For our use case of a forward topology, this leads to unwanted side-effects during the initial deployment of the subscription and the first subscription rule. Terraform first creates the subscription with the mentioned default rule. Afterwards one or more subscription rules are added and the implicit default rule is automatically removed. However, in the seconds between the deployment of the subscription and the first subscription rule, all messages sent to topic (example) are forwarded to our destination topic forward_example because the default rule is still active.

A potential fix would be to allow specifying whether the default rule should use a TrueRuleFilter such as "1=1" or a FalseRuleFilter (e.g., for .Net SDK) such as "1=0".

// Demo subscription
resource "azurerm_servicebus_subscription" "demo_subscription" {
  name            = "demo_subscription"
  topic_id        = azurerm_servicebus_topic.example.id
  forward_to      = azurerm_servicebus_topic.forward_example.id
}

// Demo subscription rule
resource "azurerm_servicebus_subscription_rule" "demo_subscription_rule" {
  name            = "demo_rule_1"
  subscription_id = azurerm_servicebus_subscription.demo_subscription.id
  filter_type     = "SqlFilter"
  sql_filter      = "[Some.HeaderField] LIKE '%foobar%'"
}

New or Affected Resource(s)/Data Source(s)

azurerm_servicebus_subscription

Potential Terraform Configuration

resource "azurerm_servicebus_subscription" "demo_subscription" {
  name            = "demo_subscription"
  topic_id        = azurerm_servicebus_topic.example.id
  forward_to      = azurerm_servicebus_topic.forward_example.id
  default_rule_filter = "<match_all|match_none>"
}
# match_all -> TrueRuleFilter in the SDK
# match_non -> FalseRuleFilter in the SDK

References

No response

H-Finch-404 commented 4 months ago

We also bumped into this unfortunate issue. We would already be happy with a simple boolean that allows us to disable the default filter on initial creation of the resource.

Slawek-Sandbox commented 1 week ago

The issue here is that the Microsoft's API creates the $Default rule and there's no option to turn that off. The workaround would be to import the rule and then do something with it.