diff --git a/azurerm/import_arm_servicebus_namespace_test.go b/azurerm/import_arm_servicebus_namespace_test.go index 2fa623ed3c3f..e1ad9834b8c6 100644 --- a/azurerm/import_arm_servicebus_namespace_test.go +++ b/azurerm/import_arm_servicebus_namespace_test.go @@ -1,7 +1,6 @@ package azurerm import ( - "fmt" "testing" "github.com/hashicorp/terraform/helper/acctest" @@ -12,18 +11,18 @@ func TestAccAzureRMServiceBusNamespace_importBasic(t *testing.T) { resourceName := "azurerm_servicebus_namespace.test" ri := acctest.RandInt() - config := fmt.Sprintf(testAccAzureRMServiceBusNamespace_basic, ri, ri) + config := testAccAzureRMServiceBusNamespace_basic(ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testCheckAzureRMServiceBusNamespaceDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: config, }, - resource.TestStep{ + { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, diff --git a/azurerm/import_arm_servicebus_topic_test.go b/azurerm/import_arm_servicebus_topic_test.go index b5a933c65153..58ab5deb351e 100644 --- a/azurerm/import_arm_servicebus_topic_test.go +++ b/azurerm/import_arm_servicebus_topic_test.go @@ -1,7 +1,6 @@ package azurerm import ( - "fmt" "testing" "github.com/hashicorp/terraform/helper/acctest" @@ -12,18 +11,40 @@ func TestAccAzureRMServiceBusTopic_importBasic(t *testing.T) { resourceName := "azurerm_servicebus_topic.test" ri := acctest.RandInt() - config := fmt.Sprintf(testAccAzureRMServiceBusTopic_basic, ri, ri, ri) + config := testAccAzureRMServiceBusTopic_basic(ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testCheckAzureRMServiceBusTopicDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: config, }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMServiceBusTopic_importBasicDisabled(t *testing.T) { + resourceName := "azurerm_servicebus_topic.test" - resource.TestStep{ + ri := acctest.RandInt() + config := testAccAzureRMServiceBusTopic_basicDisabled(ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMServiceBusTopicDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, diff --git a/azurerm/resource_arm_servicebus_namespace.go b/azurerm/resource_arm_servicebus_namespace.go index d9c93cf48019..fe11c5e99b45 100644 --- a/azurerm/resource_arm_servicebus_namespace.go +++ b/azurerm/resource_arm_servicebus_namespace.go @@ -8,6 +8,7 @@ import ( "github.com/Azure/azure-sdk-for-go/arm/servicebus" "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" ) // Default Authorization Rule/Policy created by Azure, used to populate the @@ -40,10 +41,14 @@ func resourceArmServiceBusNamespace() *schema.Resource { }, "sku": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validateServiceBusNamespaceSku, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + string(servicebus.Basic), + string(servicebus.Standard), + string(servicebus.Premium), + }, true), DiffSuppressFunc: ignoreCaseDiffSuppressFunc, }, @@ -83,7 +88,7 @@ func resourceArmServiceBusNamespace() *schema.Resource { func resourceArmServiceBusNamespaceCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*ArmClient) namespaceClient := client.serviceBusNamespacesClient - log.Printf("[INFO] preparing arguments for Azure ARM ServiceBus Namespace creation.") + log.Printf("[INFO] preparing arguments for AzureRM ServiceBus Namespace creation.") name := d.Get("name").(string) location := d.Get("location").(string) @@ -134,7 +139,7 @@ func resourceArmServiceBusNamespaceRead(d *schema.ResourceData, meta interface{} resp, err := namespaceClient.Get(resGroup, name) if err != nil { - return fmt.Errorf("Error making Read request on Azure ServiceBus Namespace %s: %+v", name, err) + return fmt.Errorf("Error making Read request on Azure ServiceBus Namespace '%s': %+v", name, err) } if resp.StatusCode == http.StatusNotFound { d.SetId("") @@ -177,26 +182,12 @@ func resourceArmServiceBusNamespaceDelete(d *schema.ResourceData, meta interface err = <-error if resp.StatusCode != http.StatusNotFound { - return fmt.Errorf("Error issuing Azure ARM delete request of ServiceBus Namespace'%s': %+v", name, err) + return fmt.Errorf("Error issuing Azure ARM delete request of ServiceBus Namespace '%s': %+v", name, err) } return nil } -func validateServiceBusNamespaceSku(v interface{}, k string) (ws []string, errors []error) { - value := strings.ToLower(v.(string)) - skus := map[string]bool{ - "basic": true, - "standard": true, - "premium": true, - } - - if !skus[value] { - errors = append(errors, fmt.Errorf("ServiceBus Namespace SKU can only be Basic, Standard or Premium")) - } - return -} - func validateServiceBusNamespaceCapacity(v interface{}, k string) (ws []string, errors []error) { value := v.(int) capacities := map[int]bool{ diff --git a/azurerm/resource_arm_servicebus_namespace_test.go b/azurerm/resource_arm_servicebus_namespace_test.go index 0e0942e5aeac..6366fafd27b3 100644 --- a/azurerm/resource_arm_servicebus_namespace_test.go +++ b/azurerm/resource_arm_servicebus_namespace_test.go @@ -43,52 +43,20 @@ func TestAccAzureRMServiceBusNamespaceCapacity_validation(t *testing.T) { } } -func TestAccAzureRMServiceBusNamespaceSku_validation(t *testing.T) { - cases := []struct { - Value string - ErrCount int - }{ - { - Value: "Basic", - ErrCount: 0, - }, - { - Value: "Standard", - ErrCount: 0, - }, - { - Value: "Premium", - ErrCount: 0, - }, - { - Value: "Random", - ErrCount: 1, - }, - } - - for _, tc := range cases { - _, errors := validateServiceBusNamespaceSku(tc.Value, "azurerm_servicebus_namespace") - - if len(errors) != tc.ErrCount { - t.Fatalf("Expected the Azure RM ServiceBus Namespace Sku to trigger a validation error") - } - } -} - func TestAccAzureRMServiceBusNamespace_basic(t *testing.T) { - + resourceName := "azurerm_servicebus_namespace.test" ri := acctest.RandInt() - config := fmt.Sprintf(testAccAzureRMServiceBusNamespace_basic, ri, ri) + config := testAccAzureRMServiceBusNamespace_basic(ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testCheckAzureRMServiceBusNamespaceDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusNamespaceExists("azurerm_servicebus_namespace.test"), + testCheckAzureRMServiceBusNamespaceExists(resourceName), ), }, }, @@ -96,26 +64,27 @@ func TestAccAzureRMServiceBusNamespace_basic(t *testing.T) { } func TestAccAzureRMServiceBusNamespace_readDefaultKeys(t *testing.T) { + resourceName := "azurerm_servicebus_namespace.test" ri := acctest.RandInt() - config := fmt.Sprintf(testAccAzureRMServiceBusNamespace_basic, ri, ri) + config := testAccAzureRMServiceBusNamespace_basic(ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testCheckAzureRMServiceBusNamespaceDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusNamespaceExists("azurerm_servicebus_namespace.test"), + testCheckAzureRMServiceBusNamespaceExists(resourceName), resource.TestMatchResourceAttr( - "azurerm_servicebus_namespace.test", "default_primary_connection_string", regexp.MustCompile("Endpoint=.+")), + resourceName, "default_primary_connection_string", regexp.MustCompile("Endpoint=.+")), resource.TestMatchResourceAttr( - "azurerm_servicebus_namespace.test", "default_secondary_connection_string", regexp.MustCompile("Endpoint=.+")), + resourceName, "default_secondary_connection_string", regexp.MustCompile("Endpoint=.+")), resource.TestMatchResourceAttr( - "azurerm_servicebus_namespace.test", "default_primary_key", regexp.MustCompile(".+")), + resourceName, "default_primary_key", regexp.MustCompile(".+")), resource.TestMatchResourceAttr( - "azurerm_servicebus_namespace.test", "default_secondary_key", regexp.MustCompile(".+")), + resourceName, "default_secondary_key", regexp.MustCompile(".+")), ), }, }, @@ -123,6 +92,7 @@ func TestAccAzureRMServiceBusNamespace_readDefaultKeys(t *testing.T) { } func TestAccAzureRMServiceBusNamespace_NonStandardCasing(t *testing.T) { + resourceName := "azurerm_servicebus_namespace.test" ri := acctest.RandInt() config := testAccAzureRMServiceBusNamespaceNonStandardCasing(ri) @@ -132,13 +102,13 @@ func TestAccAzureRMServiceBusNamespace_NonStandardCasing(t *testing.T) { Providers: testAccProviders, CheckDestroy: testCheckAzureRMServiceBusNamespaceDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusNamespaceExists("azurerm_servicebus_namespace.test"), + testCheckAzureRMServiceBusNamespaceExists(resourceName), ), }, - resource.TestStep{ + { Config: config, PlanOnly: true, ExpectNonEmptyPlan: false, @@ -201,18 +171,20 @@ func testCheckAzureRMServiceBusNamespaceExists(name string) resource.TestCheckFu } } -var testAccAzureRMServiceBusNamespace_basic = ` +func testAccAzureRMServiceBusNamespace_basic(rInt int) string { + return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "West US" } resource "azurerm_servicebus_namespace" "test" { name = "acctestservicebusnamespace-%d" - location = "West US" + location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" sku = "basic" } -` +`, rInt, rInt) +} func testAccAzureRMServiceBusNamespaceNonStandardCasing(ri int) string { return fmt.Sprintf(` @@ -222,7 +194,7 @@ resource "azurerm_resource_group" "test" { } resource "azurerm_servicebus_namespace" "test" { name = "acctestservicebusnamespace-%d" - location = "West US" + location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" sku = "Basic" } diff --git a/azurerm/resource_arm_servicebus_topic.go b/azurerm/resource_arm_servicebus_topic.go index 982b8ea73cdf..cd2d7b69e631 100644 --- a/azurerm/resource_arm_servicebus_topic.go +++ b/azurerm/resource_arm_servicebus_topic.go @@ -7,6 +7,8 @@ import ( "github.com/Azure/azure-sdk-for-go/arm/servicebus" "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" + "github.com/jen20/riviera/azure" ) func resourceArmServiceBusTopic() *schema.Resource { @@ -40,6 +42,17 @@ func resourceArmServiceBusTopic() *schema.Resource { ForceNew: true, }, + "status": { + Type: schema.TypeString, + Optional: true, + Default: string(servicebus.EntityStatusActive), + ValidateFunc: validation.StringInSlice([]string{ + string(servicebus.EntityStatusActive), + string(servicebus.EntityStatusDisabled), + }, true), + DiffSuppressFunc: ignoreCaseDiffSuppressFunc, + }, + "auto_delete_on_idle": { Type: schema.TypeString, Optional: true, @@ -107,41 +120,43 @@ func resourceArmServiceBusTopicCreate(d *schema.ResourceData, meta interface{}) namespaceName := d.Get("namespace_name").(string) location := d.Get("location").(string) resGroup := d.Get("resource_group_name").(string) + status := d.Get("status").(string) + + enableBatchedOps := d.Get("enable_batched_operations").(bool) + enableExpress := d.Get("enable_express").(bool) + enableFiltering := d.Get("enable_filtering_messages_before_publishing").(bool) + enablePartitioning := d.Get("enable_partitioning").(bool) + maxSize := int64(d.Get("max_size_in_megabytes").(int)) + requiresDuplicateDetection := d.Get("requires_duplicate_detection").(bool) + supportOrdering := d.Get("support_ordering").(bool) parameters := servicebus.TopicCreateOrUpdateParameters{ - Name: &name, - Location: &location, - TopicProperties: &servicebus.TopicProperties{}, + Name: &name, + Location: &location, + TopicProperties: &servicebus.TopicProperties{ + Status: servicebus.EntityStatus(status), + EnableBatchedOperations: azure.Bool(enableBatchedOps), + EnableExpress: azure.Bool(enableExpress), + FilteringMessagesBeforePublishing: azure.Bool(enableFiltering), + EnablePartitioning: azure.Bool(enablePartitioning), + MaxSizeInMegabytes: azure.Int64(maxSize), + RequiresDuplicateDetection: azure.Bool(requiresDuplicateDetection), + SupportOrdering: azure.Bool(supportOrdering), + }, } if autoDeleteOnIdle := d.Get("auto_delete_on_idle").(string); autoDeleteOnIdle != "" { - parameters.TopicProperties.AutoDeleteOnIdle = &autoDeleteOnIdle + parameters.TopicProperties.AutoDeleteOnIdle = azure.String(autoDeleteOnIdle) } if defaultTTL := d.Get("default_message_ttl").(string); defaultTTL != "" { - parameters.TopicProperties.DefaultMessageTimeToLive = &defaultTTL + parameters.TopicProperties.DefaultMessageTimeToLive = azure.String(defaultTTL) } if duplicateWindow := d.Get("duplicate_detection_history_time_window").(string); duplicateWindow != "" { - parameters.TopicProperties.DuplicateDetectionHistoryTimeWindow = &duplicateWindow + parameters.TopicProperties.DuplicateDetectionHistoryTimeWindow = azure.String(duplicateWindow) } - enableBatchedOps := d.Get("enable_batched_operations").(bool) - enableExpress := d.Get("enable_express").(bool) - enableFiltering := d.Get("enable_filtering_messages_before_publishing").(bool) - enablePartitioning := d.Get("enable_partitioning").(bool) - maxSize := int64(d.Get("max_size_in_megabytes").(int)) - requiresDuplicateDetection := d.Get("requires_duplicate_detection").(bool) - supportOrdering := d.Get("support_ordering").(bool) - - parameters.TopicProperties.EnableBatchedOperations = &enableBatchedOps - parameters.TopicProperties.EnableExpress = &enableExpress - parameters.TopicProperties.FilteringMessagesBeforePublishing = &enableFiltering - parameters.TopicProperties.EnablePartitioning = &enablePartitioning - parameters.TopicProperties.MaxSizeInMegabytes = &maxSize - parameters.TopicProperties.RequiresDuplicateDetection = &requiresDuplicateDetection - parameters.TopicProperties.SupportOrdering = &supportOrdering - _, err := client.CreateOrUpdate(resGroup, namespaceName, name, parameters) if err != nil { return err @@ -186,6 +201,7 @@ func resourceArmServiceBusTopicRead(d *schema.ResourceData, meta interface{}) er d.Set("location", azureRMNormalizeLocation(*resp.Location)) props := resp.TopicProperties + d.Set("status", string(props.Status)) d.Set("auto_delete_on_idle", props.AutoDeleteOnIdle) d.Set("default_message_ttl", props.DefaultMessageTimeToLive) diff --git a/azurerm/resource_arm_servicebus_topic_test.go b/azurerm/resource_arm_servicebus_topic_test.go index 8ea9fd9ddbee..096467787a6b 100644 --- a/azurerm/resource_arm_servicebus_topic_test.go +++ b/azurerm/resource_arm_servicebus_topic_test.go @@ -11,18 +11,72 @@ import ( ) func TestAccAzureRMServiceBusTopic_basic(t *testing.T) { + resourceName := "azurerm_servicebus_topic.test" ri := acctest.RandInt() - config := fmt.Sprintf(testAccAzureRMServiceBusTopic_basic, ri, ri, ri) + config := testAccAzureRMServiceBusTopic_basic(ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testCheckAzureRMServiceBusTopicDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusTopicExists("azurerm_servicebus_topic.test"), + testCheckAzureRMServiceBusTopicExists(resourceName), + ), + }, + }, + }) +} + +func TestAccAzureRMServiceBusTopic_basicDisabled(t *testing.T) { + resourceName := "azurerm_servicebus_topic.test" + ri := acctest.RandInt() + config := testAccAzureRMServiceBusTopic_basicDisabled(ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMServiceBusTopicDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMServiceBusTopicExists(resourceName), + ), + }, + }, + }) +} + +func TestAccAzureRMServiceBusTopic_basicDisableEnable(t *testing.T) { + resourceName := "azurerm_servicebus_topic.test" + ri := acctest.RandInt() + enabledConfig := testAccAzureRMServiceBusTopic_basic(ri) + disabledConfig := testAccAzureRMServiceBusTopic_basicDisabled(ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMServiceBusTopicDestroy, + Steps: []resource.TestStep{ + { + Config: enabledConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMServiceBusTopicExists(resourceName), + ), + }, + { + Config: disabledConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMServiceBusTopicExists(resourceName), + ), + }, + { + Config: enabledConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMServiceBusTopicExists(resourceName), ), }, }, @@ -31,21 +85,21 @@ func TestAccAzureRMServiceBusTopic_basic(t *testing.T) { func TestAccAzureRMServiceBusTopic_update(t *testing.T) { ri := acctest.RandInt() - preConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_basic, ri, ri, ri) - postConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_update, ri, ri, ri) + preConfig := testAccAzureRMServiceBusTopic_basic(ri) + postConfig := testAccAzureRMServiceBusTopic_update(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( @@ -59,29 +113,28 @@ func TestAccAzureRMServiceBusTopic_update(t *testing.T) { } func TestAccAzureRMServiceBusTopic_enablePartitioningStandard(t *testing.T) { + resourceName := "azurerm_servicebus_topic.test" ri := acctest.RandInt() - preConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_basic, ri, ri, ri) - postConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_enablePartitioningStandard, ri, ri, ri) + preConfig := testAccAzureRMServiceBusTopic_basic(ri) + postConfig := testAccAzureRMServiceBusTopic_enablePartitioningStandard(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"), + testCheckAzureRMServiceBusTopicExists(resourceName), ), }, - resource.TestStep{ + { Config: postConfig, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "azurerm_servicebus_topic.test", "enable_partitioning", "true"), + resource.TestCheckResourceAttr(resourceName, "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", "5120"), + resource.TestCheckResourceAttr(resourceName, "max_size_in_megabytes", "5120"), ), }, }, @@ -89,28 +142,27 @@ func TestAccAzureRMServiceBusTopic_enablePartitioningStandard(t *testing.T) { } func TestAccAzureRMServiceBusTopic_enablePartitioningPremium(t *testing.T) { + resourceName := "azurerm_servicebus_topic.test" ri := acctest.RandInt() - preConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_basic, ri, ri, ri) - postConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_enablePartitioningPremium, ri, ri, ri) + preConfig := testAccAzureRMServiceBusTopic_basic(ri) + postConfig := testAccAzureRMServiceBusTopic_enablePartitioningPremium(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"), + testCheckAzureRMServiceBusTopicExists(resourceName), ), }, - resource.TestStep{ + { Config: postConfig, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "azurerm_servicebus_topic.test", "enable_partitioning", "true"), - resource.TestCheckResourceAttr( - "azurerm_servicebus_topic.test", "max_size_in_megabytes", "81920"), + resource.TestCheckResourceAttr(resourceName, "enable_partitioning", "true"), + resource.TestCheckResourceAttr(resourceName, "max_size_in_megabytes", "81920"), ), }, }, @@ -118,26 +170,26 @@ func TestAccAzureRMServiceBusTopic_enablePartitioningPremium(t *testing.T) { } func TestAccAzureRMServiceBusTopic_enableDuplicateDetection(t *testing.T) { + resourceName := "azurerm_servicebus_topic.test" ri := acctest.RandInt() - preConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_basic, ri, ri, ri) - postConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_enableDuplicateDetection, ri, ri, ri) + preConfig := testAccAzureRMServiceBusTopic_basic(ri) + postConfig := testAccAzureRMServiceBusTopic_enableDuplicateDetection(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"), + testCheckAzureRMServiceBusTopicExists(resourceName), ), }, - resource.TestStep{ + { Config: postConfig, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "azurerm_servicebus_topic.test", "requires_duplicate_detection", "true"), + resource.TestCheckResourceAttr(resourceName, "requires_duplicate_detection", "true"), ), }, }, @@ -202,7 +254,8 @@ func testCheckAzureRMServiceBusTopicExists(name string) resource.TestCheckFunc { } } -var testAccAzureRMServiceBusTopic_basic = ` +func testAccAzureRMServiceBusTopic_basic(rInt int) string { + return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "West US" @@ -221,9 +274,11 @@ resource "azurerm_servicebus_topic" "test" { namespace_name = "${azurerm_servicebus_namespace.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -` +`, rInt, rInt, rInt) +} -var testAccAzureRMServiceBusTopic_basicPremium = ` +func testAccAzureRMServiceBusTopic_basicDisabled(rInt int) string { + return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "West US" @@ -233,7 +288,7 @@ resource "azurerm_servicebus_namespace" "test" { name = "acctestservicebusnamespace-%d" location = "West US" resource_group_name = "${azurerm_resource_group.test.name}" - sku = "premium" + sku = "standard" } resource "azurerm_servicebus_topic" "test" { @@ -241,10 +296,13 @@ resource "azurerm_servicebus_topic" "test" { location = "West US" namespace_name = "${azurerm_servicebus_namespace.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" + status = "disabled" +} +`, rInt, rInt, rInt) } -` -var testAccAzureRMServiceBusTopic_update = ` +func testAccAzureRMServiceBusTopic_update(rInt int) string { + return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "West US" @@ -265,9 +323,11 @@ resource "azurerm_servicebus_topic" "test" { enable_batched_operations = true enable_express = true } -` +`, rInt, rInt, rInt) +} -var testAccAzureRMServiceBusTopic_enablePartitioningStandard = ` +func testAccAzureRMServiceBusTopic_enablePartitioningStandard(rInt int) string { + return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "West US" @@ -286,11 +346,13 @@ resource "azurerm_servicebus_topic" "test" { namespace_name = "${azurerm_servicebus_namespace.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" enable_partitioning = true - max_size_in_megabytes = 5120 + max_size_in_megabytes = 5120 +} +`, rInt, rInt, rInt) } -` -var testAccAzureRMServiceBusTopic_enablePartitioningPremium = ` +func testAccAzureRMServiceBusTopic_enablePartitioningPremium(rInt int) string { + return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "West US" @@ -309,11 +371,13 @@ resource "azurerm_servicebus_topic" "test" { namespace_name = "${azurerm_servicebus_namespace.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" enable_partitioning = true - max_size_in_megabytes = 81920 + max_size_in_megabytes = 81920 +} +`, rInt, rInt, rInt) } -` -var testAccAzureRMServiceBusTopic_enableDuplicateDetection = ` +func testAccAzureRMServiceBusTopic_enableDuplicateDetection(rInt int) string { + return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "West US" @@ -333,4 +397,5 @@ resource "azurerm_servicebus_topic" "test" { resource_group_name = "${azurerm_resource_group.test.name}" requires_duplicate_detection = true } -` +`, rInt, rInt, rInt) +} diff --git a/website/docs/r/servicebus_topic.html.markdown b/website/docs/r/servicebus_topic.html.markdown index 49e9fc7b8a81..7394e7337c0b 100644 --- a/website/docs/r/servicebus_topic.html.markdown +++ b/website/docs/r/servicebus_topic.html.markdown @@ -10,8 +10,7 @@ description: |- Create a ServiceBus Topic. -**Note** Topics can only be created in Namespaces with an SKU of `standard` or -higher. +**Note** Topics can only be created in Namespaces with an SKU of `standard` or higher. ## Example Usage @@ -58,6 +57,8 @@ The following arguments are supported: * `resource_group_name` - (Required) The name of the resource group in which to create the namespace. Changing this forces a new resource to be created. +* `status` - (Optional) The Status of the Service Bus Topic. Acceptable values are `Active` or `Disabled`. Defaults to `Active`. + * `auto_delete_on_idle` - (Optional) The idle interval after which the Topic is automatically deleted, minimum of 5 minutes. Provided in the [TimeSpan](#timespan-format) format.