From 1795bdb74050b97bbaa1acbac58db11c3b503faf Mon Sep 17 00:00:00 2001 From: Jarrod Dickinson Date: Sun, 27 Sep 2020 18:57:50 +1300 Subject: [PATCH 1/4] Adding user defined properties to service bus correlation filters --- ...esource_arm_servicebus_subscription_rule.go | 18 +++++++++++++++++- ...ce_arm_servicebus_subscription_rule_test.go | 15 ++++++++++++--- .../servicebus_subscription_rule.html.markdown | 7 ++++++- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_rule.go b/azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_rule.go index b4b2302401de..f57bddf6bba7 100644 --- a/azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_rule.go +++ b/azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_rule.go @@ -126,6 +126,13 @@ func resourceArmServiceBusSubscriptionRule() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "properties": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, }, }, }, @@ -295,8 +302,9 @@ func expandAzureRmServiceBusCorrelationFilter(d *schema.ResourceData) (*serviceb replyToSessionID := config["reply_to_session_id"].(string) sessionID := config["session_id"].(string) to := config["to"].(string) + properties := utils.ExpandMapStringPtrString(config["properties"].(map[string]interface{})) - if contentType == "" && correlationID == "" && label == "" && messageID == "" && replyTo == "" && replyToSessionID == "" && sessionID == "" && to == "" { + if contentType == "" && correlationID == "" && label == "" && messageID == "" && replyTo == "" && replyToSessionID == "" && sessionID == "" && to == "" && len(properties) == 0 { return nil, fmt.Errorf("At least one property must be set in the `correlation_filter` block") } @@ -334,6 +342,10 @@ func expandAzureRmServiceBusCorrelationFilter(d *schema.ResourceData) (*serviceb correlationFilter.ContentType = utils.String(contentType) } + if len(properties) > 0 { + correlationFilter.Properties = properties + } + return &correlationFilter, nil } @@ -376,5 +388,9 @@ func flattenAzureRmServiceBusCorrelationFilter(input *servicebus.CorrelationFilt filter["content_type"] = *input.ContentType } + if input.Properties != nil { + filter["properties"] = utils.FlattenMapStringPtrString(input.Properties) + } + return []interface{}{filter} } diff --git a/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_subscription_rule_test.go b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_subscription_rule_test.go index 8d03b1b1bd27..cc1347db1272 100644 --- a/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_subscription_rule_test.go +++ b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_subscription_rule_test.go @@ -300,7 +300,10 @@ resource "azurerm_servicebus_subscription_rule" "test" { label = "test_label" session_id = "test_session_id" reply_to_session_id = "test_reply_to_session_id" - content_type = "test_content_type" + content_type = "test_content_type" + properties = { + test_key = "test_value" + } } } `, template, data.RandomInteger) @@ -321,7 +324,10 @@ resource "azurerm_servicebus_subscription_rule" "test" { correlation_filter { correlation_id = "test_correlation_id" - message_id = "test_message_id" + message_id = "test_message_id" + properties = { + test_key = "test_value" + } } } `, template, data.RandomInteger) @@ -343,7 +349,10 @@ resource "azurerm_servicebus_subscription_rule" "test" { correlation_filter { correlation_id = "test_correlation_id" message_id = "test_message_id_updated" - reply_to = "test_reply_to_added" + reply_to = "test_reply_to_added" + properties = { + test_key = "test_value_updated" + } } } `, template, data.RandomInteger) diff --git a/website/docs/r/servicebus_subscription_rule.html.markdown b/website/docs/r/servicebus_subscription_rule.html.markdown index e190860754ba..61e0c47c7974 100644 --- a/website/docs/r/servicebus_subscription_rule.html.markdown +++ b/website/docs/r/servicebus_subscription_rule.html.markdown @@ -101,7 +101,10 @@ resource "azurerm_servicebus_subscription_rule" "example" { correlation_filter { correlation_id = "high" - label = "red" + label = "red", + properties = { + customProperty = "value" + } } } ``` @@ -146,6 +149,8 @@ The following arguments are supported: * `to` - (Optional) Address to send to. +* `properties` - (Optional) A list of user defined properties to be included in the filter. Specified as a map of name/value pairs. + ~> **NOTE:** When creating a subscription rule of type `CorrelationFilter` at least one property must be set in the `correlation_filter` block. From c2e68cc6f2207d5769d919af838870fc14b01489 Mon Sep 17 00:00:00 2001 From: Jarrod Dickinson <7064936+jarrodd07@users.noreply.github.com> Date: Sun, 27 Sep 2020 19:21:36 +1300 Subject: [PATCH 2/4] Adding user defined properties to service bus correlation filters --- ...esource_arm_servicebus_subscription_rule.go | 18 +++++++++++++++++- ...ce_arm_servicebus_subscription_rule_test.go | 15 ++++++++++++--- .../servicebus_subscription_rule.html.markdown | 7 ++++++- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_rule.go b/azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_rule.go index b4b2302401de..f57bddf6bba7 100644 --- a/azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_rule.go +++ b/azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_rule.go @@ -126,6 +126,13 @@ func resourceArmServiceBusSubscriptionRule() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "properties": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, }, }, }, @@ -295,8 +302,9 @@ func expandAzureRmServiceBusCorrelationFilter(d *schema.ResourceData) (*serviceb replyToSessionID := config["reply_to_session_id"].(string) sessionID := config["session_id"].(string) to := config["to"].(string) + properties := utils.ExpandMapStringPtrString(config["properties"].(map[string]interface{})) - if contentType == "" && correlationID == "" && label == "" && messageID == "" && replyTo == "" && replyToSessionID == "" && sessionID == "" && to == "" { + if contentType == "" && correlationID == "" && label == "" && messageID == "" && replyTo == "" && replyToSessionID == "" && sessionID == "" && to == "" && len(properties) == 0 { return nil, fmt.Errorf("At least one property must be set in the `correlation_filter` block") } @@ -334,6 +342,10 @@ func expandAzureRmServiceBusCorrelationFilter(d *schema.ResourceData) (*serviceb correlationFilter.ContentType = utils.String(contentType) } + if len(properties) > 0 { + correlationFilter.Properties = properties + } + return &correlationFilter, nil } @@ -376,5 +388,9 @@ func flattenAzureRmServiceBusCorrelationFilter(input *servicebus.CorrelationFilt filter["content_type"] = *input.ContentType } + if input.Properties != nil { + filter["properties"] = utils.FlattenMapStringPtrString(input.Properties) + } + return []interface{}{filter} } diff --git a/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_subscription_rule_test.go b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_subscription_rule_test.go index 8d03b1b1bd27..cc1347db1272 100644 --- a/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_subscription_rule_test.go +++ b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_subscription_rule_test.go @@ -300,7 +300,10 @@ resource "azurerm_servicebus_subscription_rule" "test" { label = "test_label" session_id = "test_session_id" reply_to_session_id = "test_reply_to_session_id" - content_type = "test_content_type" + content_type = "test_content_type" + properties = { + test_key = "test_value" + } } } `, template, data.RandomInteger) @@ -321,7 +324,10 @@ resource "azurerm_servicebus_subscription_rule" "test" { correlation_filter { correlation_id = "test_correlation_id" - message_id = "test_message_id" + message_id = "test_message_id" + properties = { + test_key = "test_value" + } } } `, template, data.RandomInteger) @@ -343,7 +349,10 @@ resource "azurerm_servicebus_subscription_rule" "test" { correlation_filter { correlation_id = "test_correlation_id" message_id = "test_message_id_updated" - reply_to = "test_reply_to_added" + reply_to = "test_reply_to_added" + properties = { + test_key = "test_value_updated" + } } } `, template, data.RandomInteger) diff --git a/website/docs/r/servicebus_subscription_rule.html.markdown b/website/docs/r/servicebus_subscription_rule.html.markdown index e190860754ba..61e0c47c7974 100644 --- a/website/docs/r/servicebus_subscription_rule.html.markdown +++ b/website/docs/r/servicebus_subscription_rule.html.markdown @@ -101,7 +101,10 @@ resource "azurerm_servicebus_subscription_rule" "example" { correlation_filter { correlation_id = "high" - label = "red" + label = "red", + properties = { + customProperty = "value" + } } } ``` @@ -146,6 +149,8 @@ The following arguments are supported: * `to` - (Optional) Address to send to. +* `properties` - (Optional) A list of user defined properties to be included in the filter. Specified as a map of name/value pairs. + ~> **NOTE:** When creating a subscription rule of type `CorrelationFilter` at least one property must be set in the `correlation_filter` block. From 52628d9a6387927772180bc289e0b39c9d075bb1 Mon Sep 17 00:00:00 2001 From: jarrodd07 <7064936+jarrodd07@users.noreply.github.com> Date: Sun, 27 Sep 2020 19:39:52 +1300 Subject: [PATCH 3/4] Remove comma --- website/docs/r/servicebus_subscription_rule.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/servicebus_subscription_rule.html.markdown b/website/docs/r/servicebus_subscription_rule.html.markdown index 61e0c47c7974..d29733fcdbd6 100644 --- a/website/docs/r/servicebus_subscription_rule.html.markdown +++ b/website/docs/r/servicebus_subscription_rule.html.markdown @@ -101,7 +101,7 @@ resource "azurerm_servicebus_subscription_rule" "example" { correlation_filter { correlation_id = "high" - label = "red", + label = "red" properties = { customProperty = "value" } From 36dd2eed635950d16240f003fe69aaef12b498ec Mon Sep 17 00:00:00 2001 From: Jarrod Dickinson <7064936+jarrodd07@users.noreply.github.com> Date: Sun, 27 Sep 2020 19:50:15 +1300 Subject: [PATCH 4/4] Fix windows indentation --- ...e_arm_servicebus_subscription_rule_test.go | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_subscription_rule_test.go b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_subscription_rule_test.go index cc1347db1272..572e596a4ab0 100644 --- a/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_subscription_rule_test.go +++ b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_subscription_rule_test.go @@ -300,10 +300,10 @@ resource "azurerm_servicebus_subscription_rule" "test" { label = "test_label" session_id = "test_session_id" reply_to_session_id = "test_reply_to_session_id" - content_type = "test_content_type" - properties = { - test_key = "test_value" - } + content_type = "test_content_type" + properties = { + test_key = "test_value" + } } } `, template, data.RandomInteger) @@ -324,10 +324,10 @@ resource "azurerm_servicebus_subscription_rule" "test" { correlation_filter { correlation_id = "test_correlation_id" - message_id = "test_message_id" - properties = { - test_key = "test_value" - } + message_id = "test_message_id" + properties = { + test_key = "test_value" + } } } `, template, data.RandomInteger) @@ -349,10 +349,10 @@ resource "azurerm_servicebus_subscription_rule" "test" { correlation_filter { correlation_id = "test_correlation_id" message_id = "test_message_id_updated" - reply_to = "test_reply_to_added" - properties = { - test_key = "test_value_updated" - } + reply_to = "test_reply_to_added" + properties = { + test_key = "test_value_updated" + } } } `, template, data.RandomInteger)