Skip to content

Commit

Permalink
Merge pull request #861 from terraform-providers/f-servicebus-sub-aut…
Browse files Browse the repository at this point in the history
…oforward

Add forward_to property to servicebus subscription resource. Fixes #810
  • Loading branch information
katbyte authored Feb 23, 2018
2 parents 66489d3 + d0acd0c commit 1381dde
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 114 deletions.
10 changes: 10 additions & 0 deletions azurerm/resource_arm_servicebus_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ func resourceArmServiceBusSubscription() *schema.Resource {
ForceNew: true,
},

"forward_to": {
Type: schema.TypeString,
Optional: true,
},

// TODO: remove in the next major version
"dead_lettering_on_filter_evaluation_exceptions": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -124,6 +129,10 @@ func resourceArmServiceBusSubscriptionCreate(d *schema.ResourceData, meta interf
parameters.SBSubscriptionProperties.LockDuration = &lockDuration
}

if forwardTo := d.Get("forward_to").(string); forwardTo != "" {
parameters.SBSubscriptionProperties.ForwardTo = &forwardTo
}

_, err := client.CreateOrUpdate(ctx, resourceGroup, namespaceName, topicName, name, parameters)
if err != nil {
return err
Expand Down Expand Up @@ -176,6 +185,7 @@ func resourceArmServiceBusSubscriptionRead(d *schema.ResourceData, meta interfac
d.Set("dead_lettering_on_message_expiration", props.DeadLetteringOnMessageExpiration)
d.Set("enable_batched_operations", props.EnableBatchedOperations)
d.Set("requires_session", props.RequiresSession)
d.Set("forward_to", props.ForwardTo)

if count := props.MaxDeliveryCount; count != nil {
d.Set("max_delivery_count", int(*count))
Expand Down
123 changes: 59 additions & 64 deletions azurerm/resource_arm_servicebus_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ func TestAccAzureRMServiceBusSubscription_basic(t *testing.T) {
})
}

func TestAccAzureRMServiceBusSubscription_update(t *testing.T) {
func TestAccAzureRMServiceBusSubscription_updateEnableBatched(t *testing.T) {
resourceName := "azurerm_servicebus_subscription.test"
ri := acctest.RandInt()
location := testLocation()
preConfig := testAccAzureRMServiceBusSubscription_basic(ri, location)
postConfig := testAccAzureRMServiceBusSubscription_update(ri, location)
postConfig := testAccAzureRMServiceBusSubscription_updateEnableBatched(ri, location)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -86,6 +86,36 @@ func TestAccAzureRMServiceBusSubscription_updateRequiresSession(t *testing.T) {
})
}

func TestAccAzureRMServiceBusSubscription_updateForwardTo(t *testing.T) {
resourceName := "azurerm_servicebus_subscription.test"
ri := acctest.RandInt()
location := testLocation()
preConfig := testAccAzureRMServiceBusSubscription_basic(ri, location)
postConfig := testAccAzureRMServiceBusSubscription_updateForwardTo(ri, location)

expectedValue := fmt.Sprintf("acctestservicebustopic-forward_to-%d", ri)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMServiceBusTopicDestroy,
Steps: []resource.TestStep{
{
Config: preConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMServiceBusSubscriptionExists(resourceName),
),
},
{
Config: postConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "forward_to", expectedValue),
),
},
},
})
}

func testCheckAzureRMServiceBusSubscriptionDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*ArmClient).serviceBusSubscriptionsClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext
Expand Down Expand Up @@ -148,94 +178,59 @@ func testCheckAzureRMServiceBusSubscriptionExists(name string) resource.TestChec
}
}

func testAccAzureRMServiceBusSubscription_basic(rInt int, location string) string {
return fmt.Sprintf(`
const testAccAzureRMServiceBusSubscription_tfTemplate = `
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_servicebus_namespace" "test" {
name = "acctestservicebusnamespace-%d"
location = "${azurerm_resource_group.test.location}"
name = "acctestservicebusnamespace-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "standard"
sku = "standard"
}
resource "azurerm_servicebus_topic" "test" {
name = "acctestservicebustopic-%d"
namespace_name = "${azurerm_servicebus_namespace.test.name}"
name = "acctestservicebustopic-%d"
namespace_name = "${azurerm_servicebus_namespace.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
}
resource "azurerm_servicebus_subscription" "test" {
name = "acctestservicebussubscription-%d"
namespace_name = "${azurerm_servicebus_namespace.test.name}"
topic_name = "${azurerm_servicebus_topic.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
max_delivery_count = 10
}
`, rInt, location, rInt, rInt, rInt)
}

func testAccAzureRMServiceBusSubscription_update(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}"
name = "acctestservicebussubscription-%d"
namespace_name = "${azurerm_servicebus_namespace.test.name}"
topic_name = "${azurerm_servicebus_topic.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "standard"
max_delivery_count = 10
%s
}
`

resource "azurerm_servicebus_topic" "test" {
name = "acctestservicebustopic-%d"
namespace_name = "${azurerm_servicebus_namespace.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
func testAccAzureRMServiceBusSubscription_basic(rInt int, location string) string {
return fmt.Sprintf(testAccAzureRMServiceBusSubscription_tfTemplate, rInt, location, rInt, rInt, rInt, "")
}

resource "azurerm_servicebus_subscription" "test" {
name = "acctestservicebussubscription-%d"
namespace_name = "${azurerm_servicebus_namespace.test.name}"
topic_name = "${azurerm_servicebus_topic.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
max_delivery_count = 10
enable_batched_operations = true
}
`, rInt, location, rInt, rInt, rInt)
func testAccAzureRMServiceBusSubscription_updateEnableBatched(rInt int, location string) string {
return fmt.Sprintf(testAccAzureRMServiceBusSubscription_tfTemplate, rInt, location, rInt, rInt, rInt,
"enable_batched_operations = true\n")
}

func testAccAzureRMServiceBusSubscription_updateRequiresSession(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
return fmt.Sprintf(testAccAzureRMServiceBusSubscription_tfTemplate, rInt, location, rInt, rInt, rInt,
"requires_session = true\n")
}

resource "azurerm_servicebus_namespace" "test" {
name = "acctestservicebusnamespace-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "standard"
}
func testAccAzureRMServiceBusSubscription_updateForwardTo(rInt int, location string) string {
forwardToTf := testAccAzureRMServiceBusSubscription_tfTemplate + `
resource "azurerm_servicebus_topic" "test" {
name = "acctestservicebustopic-%d"
resource "azurerm_servicebus_topic" "forward_to" {
name = "acctestservicebustopic-forward_to-%d"
namespace_name = "${azurerm_servicebus_namespace.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
}
resource "azurerm_servicebus_subscription" "test" {
name = "acctestservicebussubscription-%d"
namespace_name = "${azurerm_servicebus_namespace.test.name}"
topic_name = "${azurerm_servicebus_topic.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
max_delivery_count = 10
requires_session = true
}
`, rInt, location, rInt, rInt, rInt)
`
return fmt.Sprintf(forwardToTf, rInt, location, rInt, rInt, rInt,
"forward_to = \"${azurerm_servicebus_topic.forward_to.name}\"\n", rInt)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ If you are committing this template to source control, please insure that you ad
## variables.tf
The `variables.tf` file contains all of the input parameters that the user can specify when deploying this Terraform template.

![graph](graph.png)
31 changes: 0 additions & 31 deletions examples/servicebus-create-topic-and-subscription/deploy.ci.sh

This file was deleted.

15 changes: 0 additions & 15 deletions examples/servicebus-create-topic-and-subscription/deploy.mac.sh

This file was deleted.

Binary file not shown.
13 changes: 11 additions & 2 deletions examples/servicebus-create-topic-and-subscription/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ resource "azurerm_servicebus_namespace" "test" {
sku = "standard"
}


resource "azurerm_servicebus_topic" "test" {
name = "${var.unique}Topic"
location = "${var.location}"
resource_group_name = "${var.resource_group}"
namespace_name = "${azurerm_servicebus_namespace.test.name}"

Expand All @@ -29,9 +29,18 @@ resource "azurerm_servicebus_topic" "test" {

resource "azurerm_servicebus_subscription" "test" {
name = "${var.unique}Subscription"
location = "${var.location}"
resource_group_name = "${var.resource_group}"
namespace_name = "${azurerm_servicebus_namespace.test.name}"
topic_name = "${azurerm_servicebus_topic.test.name}"
forward_to = "${azurerm_servicebus_topic.forward_to.name}"
max_delivery_count = 1
}


resource "azurerm_servicebus_topic" "forward_to" {
name = "${var.unique}Topic-forward_to"
resource_group_name = "${var.resource_group}"
namespace_name = "${azurerm_servicebus_namespace.test.name}"

enable_partitioning = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ variable "location" {
}

variable "unique" {
description = "a unique string that will be used to comprise the names of the Service Bus, Topic, and Subscription name spaces"
description = "A unique string that will be used to comprise the names of the Service Bus, Topic, and Subscription name spaces"
}
3 changes: 3 additions & 0 deletions website/docs/r/servicebus_subscription.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ 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.

### TimeSpan Format

Some arguments for this resource are required in the TimeSpan format which is
Expand Down

0 comments on commit 1381dde

Please sign in to comment.