From a9ea4965e8fac11011689e65104b198c93de67d7 Mon Sep 17 00:00:00 2001 From: KY Date: Fri, 5 Oct 2018 14:16:33 +0800 Subject: [PATCH 1/6] service_bus_queue: support for `max_delivery_count` --- azurerm/resource_arm_servicebus_queue.go | 8 +++ azurerm/resource_arm_servicebus_queue_test.go | 50 +++++++++++++++++++ website/docs/r/servicebus_queue.html.markdown | 8 +-- 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/azurerm/resource_arm_servicebus_queue.go b/azurerm/resource_arm_servicebus_queue.go index 5d2c3ac96cfb..161ebcda2e4c 100644 --- a/azurerm/resource_arm_servicebus_queue.go +++ b/azurerm/resource_arm_servicebus_queue.go @@ -117,6 +117,12 @@ func resourceArmServiceBusQueue() *schema.Resource { Optional: true, Deprecated: "This field has been removed by Azure.", }, + + "max_delivery_count": { + Type: schema.TypeInt, + Optional: true, + Default: 10, + }, }, } } @@ -133,6 +139,7 @@ func resourceArmServiceBusQueueCreateUpdate(d *schema.ResourceData, meta interfa enableExpress := d.Get("enable_express").(bool) enablePartitioning := d.Get("enable_partitioning").(bool) maxSize := int32(d.Get("max_size_in_megabytes").(int)) + maxDeliveryCount := int32(d.Get("max_delivery_count").(int)) requiresDuplicateDetection := d.Get("requires_duplicate_detection").(bool) requiresSession := d.Get("requires_session").(bool) deadLetteringOnMessageExpiration := d.Get("dead_lettering_on_message_expiration").(bool) @@ -143,6 +150,7 @@ func resourceArmServiceBusQueueCreateUpdate(d *schema.ResourceData, meta interfa EnableExpress: &enableExpress, EnablePartitioning: &enablePartitioning, MaxSizeInMegabytes: &maxSize, + MaxDeliveryCount: &maxDeliveryCount, RequiresDuplicateDetection: &requiresDuplicateDetection, RequiresSession: &requiresSession, DeadLetteringOnMessageExpiration: &deadLetteringOnMessageExpiration, diff --git a/azurerm/resource_arm_servicebus_queue_test.go b/azurerm/resource_arm_servicebus_queue_test.go index b50fdeadaabe..49c38e449007 100644 --- a/azurerm/resource_arm_servicebus_queue_test.go +++ b/azurerm/resource_arm_servicebus_queue_test.go @@ -254,6 +254,33 @@ func TestAccAzureRMServiceBusQueue_isoTimeSpanAttributes(t *testing.T) { }) } +func TestAccAzureRMServiceBusQueue_maxDeliveryCount(t *testing.T) { + resourceName := "azurerm_servicebus_queue.test" + location := testLocation() + ri := acctest.RandInt() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMServiceBusQueue_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMServiceBusQueueExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "max_delivery_count", "10"), + ), + }, + { + Config: testAccAzureRMServiceBusQueue_maxDeliveryCount(ri, location), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "max_delivery_count", "20"), + ), + }, + }, + }) +} + func testCheckAzureRMServiceBusQueueDestroy(s *terraform.State) error { client := testAccProvider.Meta().(*ArmClient).serviceBusQueuesClient ctx := testAccProvider.Meta().(*ArmClient).StopContext @@ -551,3 +578,26 @@ resource "azurerm_servicebus_queue" "test" { } `, rInt, location, rInt, rInt) } + +func testAccAzureRMServiceBusQueue_maxDeliveryCount(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_servicebus_namespace" "test" { + name = "acctestservicebusnamespace-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + sku = "standard" +} + +resource "azurerm_servicebus_queue" "test" { + name = "acctestservicebusqueue-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + namespace_name = "${azurerm_servicebus_namespace.test.name}" + maxDeliveryCount = 20 +} +`, rInt, location, rInt, rInt) +} diff --git a/website/docs/r/servicebus_queue.html.markdown b/website/docs/r/servicebus_queue.html.markdown index 28bff27eb3ca..650289039c1e 100644 --- a/website/docs/r/servicebus_queue.html.markdown +++ b/website/docs/r/servicebus_queue.html.markdown @@ -96,13 +96,15 @@ The following arguments are supported: the Queue requires duplicate detection. Changing this forces a new resource to be created. Defaults to `false`. -* `requires_session` - (Optional) Boolean flag which controls whether the Queue requires sessions. - This will allow ordered handling of unbounded sequences of related messages. With sessions enabled - a queue can guarantee first-in-first-out delivery of messages. +* `requires_session` - (Optional) Boolean flag which controls whether the Queue requires sessions. + This will allow ordered handling of unbounded sequences of related messages. With sessions enabled + a queue can guarantee first-in-first-out delivery of messages. Changing this forces a new resource to be created. Defaults to `false`. * `dead_lettering_on_message_expiration` - (Optional) Boolean flag which controls whether the Queue has dead letter support when a message expires. Defaults to `false`. +* `max_delivery_count` - (Optional) Integer value which controls when a message is automatically deadlettered. Defaults to `10`. + ## Attributes Reference The following attributes are exported: From 8b43bd9dd956663094d174688f4b6c0d5272867a Mon Sep 17 00:00:00 2001 From: KY Date: Fri, 5 Oct 2018 20:28:55 +0800 Subject: [PATCH 2/6] Fix service bus queue test --- azurerm/resource_arm_servicebus_queue_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_servicebus_queue_test.go b/azurerm/resource_arm_servicebus_queue_test.go index 49c38e449007..64034684db76 100644 --- a/azurerm/resource_arm_servicebus_queue_test.go +++ b/azurerm/resource_arm_servicebus_queue_test.go @@ -597,7 +597,7 @@ resource "azurerm_servicebus_queue" "test" { name = "acctestservicebusqueue-%d" resource_group_name = "${azurerm_resource_group.test.name}" namespace_name = "${azurerm_servicebus_namespace.test.name}" - maxDeliveryCount = 20 + max_delivery_count = 20 } `, rInt, location, rInt, rInt) } From 4da8554df1af8a0f2ac9cddde6ac6a86439f1139 Mon Sep 17 00:00:00 2001 From: KY Date: Sat, 6 Oct 2018 08:31:37 +0800 Subject: [PATCH 3/6] Add import check step in service bus queue test --- azurerm/resource_arm_servicebus_queue_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/azurerm/resource_arm_servicebus_queue_test.go b/azurerm/resource_arm_servicebus_queue_test.go index 64034684db76..0c5dfda43622 100644 --- a/azurerm/resource_arm_servicebus_queue_test.go +++ b/azurerm/resource_arm_servicebus_queue_test.go @@ -59,6 +59,11 @@ func TestAccAzureRMServiceBusQueue_update(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "max_size_in_megabytes", "2048"), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, }, }) } From 6c0e433864d5a10e5e63cb6065721804318001a7 Mon Sep 17 00:00:00 2001 From: KY Date: Sat, 6 Oct 2018 08:38:32 +0800 Subject: [PATCH 4/6] Read max delivery count --- azurerm/resource_arm_servicebus_queue.go | 1 + 1 file changed, 1 insertion(+) diff --git a/azurerm/resource_arm_servicebus_queue.go b/azurerm/resource_arm_servicebus_queue.go index 161ebcda2e4c..637934da08f3 100644 --- a/azurerm/resource_arm_servicebus_queue.go +++ b/azurerm/resource_arm_servicebus_queue.go @@ -241,6 +241,7 @@ func resourceArmServiceBusQueueRead(d *schema.ResourceData, meta interface{}) er d.Set("requires_duplicate_detection", props.RequiresDuplicateDetection) d.Set("requires_session", props.RequiresSession) d.Set("dead_lettering_on_message_expiration", props.DeadLetteringOnMessageExpiration) + d.Set("max_delivery_count", props.MaxDeliveryCount) if maxSizeMB := props.MaxSizeInMegabytes; maxSizeMB != nil { maxSize := int(*maxSizeMB) From 222388a7c38d3197a7795c0000f3b1a9aa8249ea Mon Sep 17 00:00:00 2001 From: KY Date: Tue, 9 Oct 2018 08:35:18 +0800 Subject: [PATCH 5/6] Validate that max delivery count is at least 1 --- azurerm/resource_arm_servicebus_queue.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/azurerm/resource_arm_servicebus_queue.go b/azurerm/resource_arm_servicebus_queue.go index 637934da08f3..bb5fe0d8f32a 100644 --- a/azurerm/resource_arm_servicebus_queue.go +++ b/azurerm/resource_arm_servicebus_queue.go @@ -119,9 +119,10 @@ func resourceArmServiceBusQueue() *schema.Resource { }, "max_delivery_count": { - Type: schema.TypeInt, - Optional: true, - Default: 10, + Type: schema.TypeInt, + Optional: true, + Default: 10, + ValidateFunc: validation.IntAtLeast(1), }, }, } From d83860d090c6e103a17d45ff4794629b1a16a7cd Mon Sep 17 00:00:00 2001 From: KY Date: Wed, 10 Oct 2018 07:07:41 +0800 Subject: [PATCH 6/6] Fix alignment and missing import --- azurerm/resource_arm_servicebus_queue.go | 1 + azurerm/resource_arm_servicebus_queue_test.go | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/azurerm/resource_arm_servicebus_queue.go b/azurerm/resource_arm_servicebus_queue.go index bb5fe0d8f32a..f3fbf0c05d61 100644 --- a/azurerm/resource_arm_servicebus_queue.go +++ b/azurerm/resource_arm_servicebus_queue.go @@ -6,6 +6,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/servicebus/mgmt/2017-04-01/servicebus" "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) diff --git a/azurerm/resource_arm_servicebus_queue_test.go b/azurerm/resource_arm_servicebus_queue_test.go index 0c5dfda43622..0a059dadcf08 100644 --- a/azurerm/resource_arm_servicebus_queue_test.go +++ b/azurerm/resource_arm_servicebus_queue_test.go @@ -587,22 +587,22 @@ resource "azurerm_servicebus_queue" "test" { func testAccAzureRMServiceBusQueue_maxDeliveryCount(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" + name = "acctestRG-%d" location = "%s" } resource "azurerm_servicebus_namespace" "test" { - name = "acctestservicebusnamespace-%d" + name = "acctestservicebusnamespace-%d" resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - sku = "standard" + location = "${azurerm_resource_group.test.location}" + sku = "standard" } resource "azurerm_servicebus_queue" "test" { - name = "acctestservicebusqueue-%d" + name = "acctestservicebusqueue-%d" resource_group_name = "${azurerm_resource_group.test.name}" - namespace_name = "${azurerm_servicebus_namespace.test.name}" - max_delivery_count = 20 + namespace_name = "${azurerm_servicebus_namespace.test.name}" + max_delivery_count = 20 } `, rInt, location, rInt, rInt) }