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

Add dead_lettering_on_message_expiration property to servicebus queue resource #1235

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
19 changes: 14 additions & 5 deletions azurerm/resource_arm_servicebus_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ func resourceArmServiceBusQueue() *schema.Resource {
ForceNew: true,
},

"dead_lettering_on_message_expiration": {
Type: schema.TypeBool,
Default: false,
Optional: true,
},

// TODO: remove these in the next major release
"enable_batched_operations": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -122,15 +128,17 @@ func resourceArmServiceBusQueueCreateUpdate(d *schema.ResourceData, meta interfa
maxSize := int32(d.Get("max_size_in_megabytes").(int))
requiresDuplicateDetection := d.Get("requires_duplicate_detection").(bool)
requiresSession := d.Get("requires_session").(bool)
deadLetteringOnMessageExpiration := d.Get("dead_lettering_on_message_expiration").(bool)

parameters := servicebus.SBQueue{
Name: &name,
SBQueueProperties: &servicebus.SBQueueProperties{
EnableExpress: &enableExpress,
EnablePartitioning: &enablePartitioning,
MaxSizeInMegabytes: &maxSize,
RequiresDuplicateDetection: &requiresDuplicateDetection,
RequiresSession: &requiresSession,
EnableExpress: &enableExpress,
EnablePartitioning: &enablePartitioning,
MaxSizeInMegabytes: &maxSize,
RequiresDuplicateDetection: &requiresDuplicateDetection,
RequiresSession: &requiresSession,
DeadLetteringOnMessageExpiration: &deadLetteringOnMessageExpiration,
},
}

Expand Down Expand Up @@ -223,6 +231,7 @@ func resourceArmServiceBusQueueRead(d *schema.ResourceData, meta interface{}) er
d.Set("enable_partitioning", props.EnablePartitioning)
d.Set("requires_duplicate_detection", props.RequiresDuplicateDetection)
d.Set("requires_session", props.RequiresSession)
d.Set("dead_lettering_on_message_expiration", props.DeadLetteringOnMessageExpiration)

if maxSizeMB := props.MaxSizeInMegabytes; maxSizeMB != nil {
maxSize := int(*maxSizeMB)
Expand Down
51 changes: 51 additions & 0 deletions azurerm/resource_arm_servicebus_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,33 @@ func TestAccAzureRMServiceBusQueue_enableRequiresSession(t *testing.T) {
})
}

func TestAccAzureRMServiceBusQueue_enableDeadLetteringOnMessageExpiration(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, "dead_lettering_on_message_expiration", "false"),
),
},
{
Config: testAccAzureRMServiceBusQueue_enableDeadLetteringOnMessageExpiration(ri, location),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "dead_lettering_on_message_expiration", "true"),
),
},
},
})
}

func TestAccAzureRMServiceBusQueue_lockDuration(t *testing.T) {
resourceName := "azurerm_servicebus_queue.test"
ri := acctest.RandInt()
Expand Down Expand Up @@ -405,6 +432,30 @@ resource "azurerm_servicebus_queue" "test" {
`, rInt, location, rInt, rInt)
}

func testAccAzureRMServiceBusQueue_enableDeadLetteringOnMessageExpiration(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"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"

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}"
dead_lettering_on_message_expiration = true
}
`, rInt, location, rInt, rInt)
}

func testAccAzureRMServiceBusQueue_lockDuration(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/servicebus_queue.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ The following arguments are supported:
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`.

* `requires_session` - (Optional) Boolean flag which controls whether the Queue has dead letter support when a message expires. Defaults to `false`.

### TimeSpan Format

Expand Down