diff --git a/builtin/providers/azurerm/resource_arm_servicebus_topic.go b/builtin/providers/azurerm/resource_arm_servicebus_topic.go index 9d2eb6229..7b0a74cda 100644 --- a/builtin/providers/azurerm/resource_arm_servicebus_topic.go +++ b/builtin/providers/azurerm/resource_arm_servicebus_topic.go @@ -80,17 +80,20 @@ func resourceArmServiceBusTopic() *schema.Resource { "enable_partitioning": { Type: schema.TypeBool, Optional: true, + ForceNew: true, }, "max_size_in_megabytes": { - Type: schema.TypeInt, - Optional: true, - Computed: true, + Type: schema.TypeInt, + Optional: true, + Computed: true, + ValidateFunc: validateArmServiceBusTopicMaxSize, }, "requires_duplicate_detection": { Type: schema.TypeBool, Optional: true, + ForceNew: true, }, "support_ordering": { @@ -199,10 +202,18 @@ func resourceArmServiceBusTopicRead(d *schema.ResourceData, meta interface{}) er d.Set("enable_express", props.EnableExpress) d.Set("enable_filtering_messages_before_publishing", props.FilteringMessagesBeforePublishing) d.Set("enable_partitioning", props.EnablePartitioning) - d.Set("max_size_in_megabytes", int(*props.MaxSizeInMegabytes)) d.Set("requires_duplicate_detection", props.RequiresDuplicateDetection) d.Set("support_ordering", props.SupportOrdering) + // if partitioning is enabled then the max size returned by the API will be + // 16 times greater than the value set by the user + if *props.EnablePartitioning { + const partitionCount = 16 + d.Set("max_size_in_megabytes", int(*props.MaxSizeInMegabytes/partitionCount)) + } else { + d.Set("max_size_in_megabytes", int(*props.MaxSizeInMegabytes)) + } + return nil } @@ -221,3 +232,12 @@ func resourceArmServiceBusTopicDelete(d *schema.ResourceData, meta interface{}) return err } + +func validateArmServiceBusTopicMaxSize(i interface{}, k string) (s []string, es []error) { + v := i.(int) + if v%1024 != 0 || v < 0 || v > 10240 { + es = append(es, fmt.Errorf("%q must be a multiple of 1024 up to and including 10240", k)) + } + + return +} diff --git a/builtin/providers/azurerm/resource_arm_servicebus_topic_test.go b/builtin/providers/azurerm/resource_arm_servicebus_topic_test.go index 9b3a5f3b9..981a0692a 100644 --- a/builtin/providers/azurerm/resource_arm_servicebus_topic_test.go +++ b/builtin/providers/azurerm/resource_arm_servicebus_topic_test.go @@ -58,6 +58,63 @@ func TestAccAzureRMServiceBusTopic_update(t *testing.T) { }) } +func TestAccAzureRMServiceBusTopic_enablePartitioning(t *testing.T) { + ri := acctest.RandInt() + preConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_basic, ri, ri, ri) + postConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_enablePartitioning, ri, ri, ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMServiceBusTopicDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: preConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMServiceBusTopicExists("azurerm_servicebus_topic.test"), + ), + }, + resource.TestStep{ + Config: postConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "azurerm_servicebus_topic.test", "enable_partitioning", "true"), + // Ensure size is read back in it's original value and not the x16 value returned by Azure + resource.TestCheckResourceAttr( + "azurerm_servicebus_topic.test", "max_size_in_megabytes", "10240"), + ), + }, + }, + }) +} + +func TestAccAzureRMServiceBusTopic_enableDuplicateDetection(t *testing.T) { + ri := acctest.RandInt() + preConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_basic, ri, ri, ri) + postConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_enableDuplicateDetection, ri, ri, ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMServiceBusTopicDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: preConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMServiceBusTopicExists("azurerm_servicebus_topic.test"), + ), + }, + resource.TestStep{ + Config: postConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "azurerm_servicebus_topic.test", "requires_duplicate_detection", "true"), + ), + }, + }, + }) +} + func testCheckAzureRMServiceBusTopicDestroy(s *terraform.State) error { client := testAccProvider.Meta().(*ArmClient).serviceBusTopicsClient @@ -159,3 +216,48 @@ resource "azurerm_servicebus_topic" "test" { enable_express = true } ` + +var testAccAzureRMServiceBusTopic_enablePartitioning = ` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "West US" +} + +resource "azurerm_servicebus_namespace" "test" { + name = "acctestservicebusnamespace-%d" + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" + sku = "standard" +} + +resource "azurerm_servicebus_topic" "test" { + name = "acctestservicebustopic-%d" + location = "West US" + namespace_name = "${azurerm_servicebus_namespace.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + enable_partitioning = true + max_size_in_megabytes = 10240 +} +` + +var testAccAzureRMServiceBusTopic_enableDuplicateDetection = ` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "West US" +} + +resource "azurerm_servicebus_namespace" "test" { + name = "acctestservicebusnamespace-%d" + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" + sku = "standard" +} + +resource "azurerm_servicebus_topic" "test" { + name = "acctestservicebustopic-%d" + location = "West US" + namespace_name = "${azurerm_servicebus_namespace.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + requires_duplicate_detection = true +} +` diff --git a/website/source/docs/providers/azurerm/r/servicebus_topic.html.markdown b/website/source/docs/providers/azurerm/r/servicebus_topic.html.markdown index 2a4ed5bb1..c8f0bdc34 100644 --- a/website/source/docs/providers/azurerm/r/servicebus_topic.html.markdown +++ b/website/source/docs/providers/azurerm/r/servicebus_topic.html.markdown @@ -82,12 +82,16 @@ The following arguments are supported: * `enable_partitioning` - (Optional) Boolean flag which controls whether to enable the topic to be partitioned across multiple message brokers. Defaults to false. + Changing this forces a new resource to be created. * `max_size_in_megabytes` - (Optional) Integer value which controls the size of - memory allocated for the topic. + memory allocated for the topic. Supported values are multiples of 1024 up to + 10240, if `enable_partitioning` is enabled then 16 partitions will be created + per GB, making the maximum possible topic size 163840 (10240 * 16). * `requires_duplicate_detection` - (Optional) Boolean flag which controls whether - the Topic requires duplicate detection. Defaults to false. + the Topic requires duplicate detection. Defaults to false. Changing this forces + a new resource to be created. * `support_ordering` - (Optional) Boolean flag which controls whether the Topic supports ordering. Defaults to false.