From 4e470da1693bb802d80ef013e0123d78c11118b1 Mon Sep 17 00:00:00 2001 From: Austin Date: Fri, 1 Nov 2019 00:02:57 -0700 Subject: [PATCH 1/2] add support for forward_dead_lettered_messages_to to azurerm_servicebus_subscription --- .../resource_arm_servicebus_subscription.go | 10 ++++ ...source_arm_servicebus_subscription_test.go | 51 ++++++++++++++++++- .../r/servicebus_subscription.html.markdown | 7 ++- 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/azurerm/resource_arm_servicebus_subscription.go b/azurerm/resource_arm_servicebus_subscription.go index 18fcae1d4515..d3cbe694eb67 100644 --- a/azurerm/resource_arm_servicebus_subscription.go +++ b/azurerm/resource_arm_servicebus_subscription.go @@ -102,6 +102,11 @@ func resourceArmServiceBusSubscription() *schema.Resource { Optional: true, }, + "forward_dead_lettered_messages_to": { + Type: schema.TypeString, + Optional: true, + }, + // TODO: remove in the next major version "dead_lettering_on_filter_evaluation_exceptions": { Type: schema.TypeBool, @@ -162,6 +167,10 @@ func resourceArmServiceBusSubscriptionCreateUpdate(d *schema.ResourceData, meta parameters.SBSubscriptionProperties.ForwardTo = &forwardTo } + if forwardDeadLetteredMessagesTo := d.Get("forward_dead_lettered_messages_to").(string); forwardDeadLetteredMessagesTo != "" { + parameters.SBSubscriptionProperties.ForwardDeadLetteredMessagesTo = &forwardDeadLetteredMessagesTo + } + if defaultMessageTtl := d.Get("default_message_ttl").(string); defaultMessageTtl != "" { parameters.DefaultMessageTimeToLive = &defaultMessageTtl } @@ -219,6 +228,7 @@ func resourceArmServiceBusSubscriptionRead(d *schema.ResourceData, meta interfac d.Set("enable_batched_operations", props.EnableBatchedOperations) d.Set("requires_session", props.RequiresSession) d.Set("forward_to", props.ForwardTo) + d.Set("forward_dead_lettered_messages_to", props.ForwardDeadLetteredMessagesTo) if count := props.MaxDeliveryCount; count != nil { d.Set("max_delivery_count", int(*count)) diff --git a/azurerm/resource_arm_servicebus_subscription_test.go b/azurerm/resource_arm_servicebus_subscription_test.go index a96e1d334f3a..fb3b4fea4258 100644 --- a/azurerm/resource_arm_servicebus_subscription_test.go +++ b/azurerm/resource_arm_servicebus_subscription_test.go @@ -190,6 +190,41 @@ func TestAccAzureRMServiceBusSubscription_updateForwardTo(t *testing.T) { }) } +func TestAccAzureRMServiceBusSubscription_updateForwardDeadLetteredMessagesTo(t *testing.T) { + resourceName := "azurerm_servicebus_subscription.test" + ri := tf.AccRandTimeInt() + location := testLocation() + preConfig := testAccAzureRMServiceBusSubscription_basic(ri, location) + postConfig := testAccAzureRMServiceBusSubscription_updateForwardDeadLetteredMessagesTo(ri, location) + + expectedValue := fmt.Sprintf("acctestservicebustopic-forward_dl_messages_to-%d", ri) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMServiceBusSubscriptionDestroy, + Steps: []resource.TestStep{ + { + Config: preConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMServiceBusSubscriptionExists(resourceName), + ), + }, + { + Config: postConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "forward_dead_lettered_messages_to", expectedValue), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testCheckAzureRMServiceBusSubscriptionDestroy(s *terraform.State) error { client := testAccProvider.Meta().(*ArmClient).ServiceBus.SubscriptionsClient ctx := testAccProvider.Meta().(*ArmClient).StopContext @@ -288,7 +323,7 @@ func testAccAzureRMServiceBusSubscription_basic(rInt int, location string) strin func testAccAzureRMServiceBusSubscription_requiresImport(rInt int, location string) string { return fmt.Sprintf(` -%s +%s resource "azurerm_servicebus_subscription" "import" { name = "${azurerm_servicebus_subscription.test.name}" @@ -328,3 +363,17 @@ resource "azurerm_servicebus_topic" "forward_to" { return fmt.Sprintf(forwardToTf, rInt, location, rInt, rInt, rInt, "forward_to = \"${azurerm_servicebus_topic.forward_to.name}\"\n", rInt) } + +func testAccAzureRMServiceBusSubscription_updateForwardDeadLetteredMessagesTo(rInt int, location string) string { + forwardToTf := testAccAzureRMServiceBusSubscription_tfTemplate + ` + +resource "azurerm_servicebus_topic" "forward_dl_messages_to" { + name = "acctestservicebustopic-forward_dl_messages_to-%d" + namespace_name = "${azurerm_servicebus_namespace.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +` + return fmt.Sprintf(forwardToTf, rInt, location, rInt, rInt, rInt, + "forward_dead_lettered_messages_to = \"${azurerm_servicebus_topic.forward_dl_messages_to.name}\"\n", rInt) +} diff --git a/website/docs/r/servicebus_subscription.html.markdown b/website/docs/r/servicebus_subscription.html.markdown index b77bb189df1e..891aba28cfc3 100644 --- a/website/docs/r/servicebus_subscription.html.markdown +++ b/website/docs/r/servicebus_subscription.html.markdown @@ -89,9 +89,12 @@ The following arguments are supported: supports the concept of a session. Defaults to false. Changing this forces a new resource to be created. -* `forward_to` - (Optional) The name of a Queue or Topic to automatically forward +* `forward_to` - (Optional) The name of a Queue or Topic to automatically forward messages to. - + +* `forward_dead_lettered_messages_to` - (Optional) The name of a Queue or Topic to + automatically forward Dead Letter messages to. + ### TimeSpan Format Some arguments for this resource are required in the TimeSpan format which is From b4f52bb2e17f70d1b822cfb15671bd706b9f9f53 Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 1 Nov 2019 15:33:48 -0700 Subject: [PATCH 2/2] Update servicebus_subscription.html.markdown --- website/docs/r/servicebus_subscription.html.markdown | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/website/docs/r/servicebus_subscription.html.markdown b/website/docs/r/servicebus_subscription.html.markdown index 891aba28cfc3..739c997b7fe8 100644 --- a/website/docs/r/servicebus_subscription.html.markdown +++ b/website/docs/r/servicebus_subscription.html.markdown @@ -89,16 +89,13 @@ The following arguments are supported: supports the concept of a session. Defaults to false. Changing this forces a new resource to be created. -* `forward_to` - (Optional) The name of a Queue or Topic to automatically forward - messages to. +* `forward_to` - (Optional) The name of a Queue or Topic to automatically forward messages to. -* `forward_dead_lettered_messages_to` - (Optional) The name of a Queue or Topic to - automatically forward Dead Letter messages to. +* `forward_dead_lettered_messages_to` - (Optional) The name of a Queue or Topic to automatically forward Dead Letter messages to. ### TimeSpan Format -Some arguments for this resource are required in the TimeSpan format which is -used to represent a length of time. The supported format is documented [here](https://msdn.microsoft.com/en-us/library/se73z7b9(v=vs.110).aspx#Anchor_2) +Some arguments for this resource are required in the TimeSpan format which is used to represent a length of time. The supported format is documented [here](https://msdn.microsoft.com/en-us/library/se73z7b9(v=vs.110).aspx#Anchor_2) ## Attributes Reference