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

service_bus_queue: support for max_delivery_count #2028

Merged
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
11 changes: 11 additions & 0 deletions azurerm/resource_arm_servicebus_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -117,6 +118,13 @@ func resourceArmServiceBusQueue() *schema.Resource {
Optional: true,
Deprecated: "This field has been removed by Azure.",
},

"max_delivery_count": {
Type: schema.TypeInt,
Optional: true,
Default: 10,
ValidateFunc: validation.IntAtLeast(1),
},
},
}
}
Expand All @@ -133,6 +141,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)
Expand All @@ -143,6 +152,7 @@ func resourceArmServiceBusQueueCreateUpdate(d *schema.ResourceData, meta interfa
EnableExpress: &enableExpress,
EnablePartitioning: &enablePartitioning,
MaxSizeInMegabytes: &maxSize,
MaxDeliveryCount: &maxDeliveryCount,
RequiresDuplicateDetection: &requiresDuplicateDetection,
RequiresSession: &requiresSession,
DeadLetteringOnMessageExpiration: &deadLetteringOnMessageExpiration,
Expand Down Expand Up @@ -233,6 +243,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)
Expand Down
55 changes: 55 additions & 0 deletions azurerm/resource_arm_servicebus_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ func TestAccAzureRMServiceBusQueue_update(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "max_size_in_megabytes", "2048"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -254,6 +259,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"),
),
},
},
katbyte marked this conversation as resolved.
Show resolved Hide resolved
})
}

func testCheckAzureRMServiceBusQueueDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*ArmClient).serviceBusQueuesClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext
Expand Down Expand Up @@ -551,3 +583,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}"
max_delivery_count = 20
}
`, rInt, location, rInt, rInt)
}
8 changes: 5 additions & 3 deletions website/docs/r/servicebus_queue.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down