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_subscription_rule - correlation_filter with empty attributes no longer crashes #19352

Merged
merged 1 commit into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ func expandAzureRmServiceBusCorrelationFilter(d *pluginsdk.ResourceData) (*rules
return nil, fmt.Errorf("`correlation_filter` is required when `filter_type` is set to `CorrelationFilter`")
}

if configs[0] == nil {
return nil, fmt.Errorf("at least one property must not be empty in the `correlation_filter` block")
}
config := configs[0].(map[string]interface{})

contentType := config["content_type"].(string)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package servicebus_test
import (
"context"
"fmt"
"regexp"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/subscriptions"
Expand Down Expand Up @@ -152,6 +153,18 @@ func TestAccServiceBusSubscriptionRule_updateSqlFilterToCorrelationFilter(t *tes
})
}

func TestAccServiceBusSubscriptionRule_correlationFilterWhiteSpace(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_servicebus_subscription_rule", "test")
r := ServiceBusSubscriptionRuleResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.correlationFilterWhiteSpace(data),
ExpectError: regexp.MustCompile("expanding `correlation_filter`: at least one property must not be empty in the `correlation_filter` block"),
},
})
}

func (t ServiceBusSubscriptionRuleResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := subscriptions.ParseRuleID(state.ID)
if err != nil {
Expand Down Expand Up @@ -301,6 +314,23 @@ resource "azurerm_servicebus_subscription_rule" "test" {
`, r.template(data), data.RandomInteger)
}

func (r ServiceBusSubscriptionRuleResource) correlationFilterWhiteSpace(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_servicebus_subscription_rule" "test" {
name = "acctestservicebusrule-%d"
subscription_id = azurerm_servicebus_subscription.test.id
action = "SET Test='true'"
filter_type = "CorrelationFilter"

correlation_filter {
label = ""
}
}
`, r.template(data), data.RandomInteger)
}

func (ServiceBusSubscriptionRuleResource) template(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down