From 409f6c577d77eff3cb21ba4c311f1047f7f32fdb Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 3 Jul 2017 13:37:17 +0100 Subject: [PATCH 1/6] Cleaning up service bus namespaces --- .../import_arm_servicebus_namespace_test.go | 7 +- azurerm/resource_arm_servicebus_namespace.go | 33 ++++----- .../resource_arm_servicebus_namespace_test.go | 72 ++++++------------- 3 files changed, 37 insertions(+), 75 deletions(-) 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/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" } From 1c68d840b4924cb851d807942a4314594beb72af Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Tue, 4 Jul 2017 10:58:13 +0100 Subject: [PATCH 2/6] Service Bus Topic's can be disabled --- azurerm/resource_arm_servicebus_topic.go | 52 ++++++++++------- azurerm/resource_arm_servicebus_topic_test.go | 57 ++++++++++++++++++- 2 files changed, 88 insertions(+), 21 deletions(-) diff --git a/azurerm/resource_arm_servicebus_topic.go b/azurerm/resource_arm_servicebus_topic.go index 982b8ea73cdf..644b4c8c7816 100644 --- a/azurerm/resource_arm_servicebus_topic.go +++ b/azurerm/resource_arm_servicebus_topic.go @@ -7,6 +7,7 @@ import ( "github.com/Azure/azure-sdk-for-go/arm/servicebus" "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" ) func resourceArmServiceBusTopic() *schema.Resource { @@ -40,6 +41,16 @@ 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), + }, + "auto_delete_on_idle": { Type: schema.TypeString, Optional: true, @@ -107,11 +118,29 @@ 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: &enableBatchedOps, + EnableExpress: &enableExpress, + FilteringMessagesBeforePublishing: &enableFiltering, + EnablePartitioning: &enablePartitioning, + MaxSizeInMegabytes: &maxSize, + RequiresDuplicateDetection: &requiresDuplicateDetection, + SupportOrdering: &supportOrdering, + }, } if autoDeleteOnIdle := d.Get("auto_delete_on_idle").(string); autoDeleteOnIdle != "" { @@ -126,22 +155,6 @@ func resourceArmServiceBusTopicCreate(d *schema.ResourceData, meta interface{}) parameters.TopicProperties.DuplicateDetectionHistoryTimeWindow = &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 +199,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..f4369b74c361 100644 --- a/azurerm/resource_arm_servicebus_topic_test.go +++ b/azurerm/resource_arm_servicebus_topic_test.go @@ -29,6 +29,59 @@ func TestAccAzureRMServiceBusTopic_basic(t *testing.T) { }) } +func TestAccAzureRMServiceBusTopic_basicDisabled(t *testing.T) { + resourceName := "azurerm_servicebus_topic.test" + ri := acctest.RandInt() + config := fmt.Sprintf(testAccAzureRMServiceBusTopic_basicDisabled, ri, ri, 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 := fmt.Sprintf(testAccAzureRMServiceBusTopic_basic, ri, ri, ri) + disabledConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_basicDisabled, ri, ri, 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), + ), + }, + }, + }) +} + func TestAccAzureRMServiceBusTopic_update(t *testing.T) { ri := acctest.RandInt() preConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_basic, ri, ri, ri) @@ -223,7 +276,7 @@ resource "azurerm_servicebus_topic" "test" { } ` -var testAccAzureRMServiceBusTopic_basicPremium = ` +var testAccAzureRMServiceBusTopic_basicDisabled = ` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "West US" @@ -233,7 +286,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" { From 20cca85a2481bdc546a42dcc33be22710e75e6f2 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Tue, 4 Jul 2017 11:10:31 +0100 Subject: [PATCH 3/6] Refactoring --- azurerm/import_arm_servicebus_topic_test.go | 8 +- azurerm/resource_arm_servicebus_topic_test.go | 109 ++++++++++-------- 2 files changed, 63 insertions(+), 54 deletions(-) diff --git a/azurerm/import_arm_servicebus_topic_test.go b/azurerm/import_arm_servicebus_topic_test.go index b5a933c65153..f00110b6b7c3 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,17 @@ 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, }, - - resource.TestStep{ + { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, diff --git a/azurerm/resource_arm_servicebus_topic_test.go b/azurerm/resource_arm_servicebus_topic_test.go index f4369b74c361..f33c143d60c3 100644 --- a/azurerm/resource_arm_servicebus_topic_test.go +++ b/azurerm/resource_arm_servicebus_topic_test.go @@ -11,18 +11,19 @@ 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), ), }, }, @@ -32,7 +33,7 @@ func TestAccAzureRMServiceBusTopic_basic(t *testing.T) { func TestAccAzureRMServiceBusTopic_basicDisabled(t *testing.T) { resourceName := "azurerm_servicebus_topic.test" ri := acctest.RandInt() - config := fmt.Sprintf(testAccAzureRMServiceBusTopic_basicDisabled, ri, ri, ri) + config := testAccAzureRMServiceBusTopic_basicDisabled(ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -52,8 +53,8 @@ func TestAccAzureRMServiceBusTopic_basicDisabled(t *testing.T) { func TestAccAzureRMServiceBusTopic_basicDisableEnable(t *testing.T) { resourceName := "azurerm_servicebus_topic.test" ri := acctest.RandInt() - enabledConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_basic, ri, ri, ri) - disabledConfig := fmt.Sprintf(testAccAzureRMServiceBusTopic_basicDisabled, ri, ri, ri) + enabledConfig := testAccAzureRMServiceBusTopic_basic(ri) + disabledConfig := testAccAzureRMServiceBusTopic_basicDisabled(ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -84,21 +85,21 @@ func TestAccAzureRMServiceBusTopic_basicDisableEnable(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( @@ -112,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"), ), }, }, @@ -142,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"), ), }, }, @@ -171,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"), ), }, }, @@ -255,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" @@ -274,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_basicDisabled = ` +func testAccAzureRMServiceBusTopic_basicDisabled(rInt int) string { + return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "West US" @@ -295,9 +297,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_update = ` +func testAccAzureRMServiceBusTopic_update(rInt int) string { + return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "West US" @@ -318,9 +322,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" @@ -339,11 +345,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" @@ -362,11 +370,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" @@ -386,4 +396,5 @@ resource "azurerm_servicebus_topic" "test" { resource_group_name = "${azurerm_resource_group.test.name}" requires_duplicate_detection = true } -` +`, rInt, rInt, rInt) +} From da0eb1e85b214685a50aff2bc4f7dfc12bbeef93 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Tue, 4 Jul 2017 12:35:42 +0100 Subject: [PATCH 4/6] Actually enabling disabled --- azurerm/import_arm_servicebus_topic_test.go | 23 +++++++++++++++++++ azurerm/resource_arm_servicebus_topic.go | 1 + azurerm/resource_arm_servicebus_topic_test.go | 1 + 3 files changed, 25 insertions(+) diff --git a/azurerm/import_arm_servicebus_topic_test.go b/azurerm/import_arm_servicebus_topic_test.go index f00110b6b7c3..58ab5deb351e 100644 --- a/azurerm/import_arm_servicebus_topic_test.go +++ b/azurerm/import_arm_servicebus_topic_test.go @@ -29,3 +29,26 @@ func TestAccAzureRMServiceBusTopic_importBasic(t *testing.T) { }, }) } + +func TestAccAzureRMServiceBusTopic_importBasicDisabled(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, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/azurerm/resource_arm_servicebus_topic.go b/azurerm/resource_arm_servicebus_topic.go index 644b4c8c7816..0f0e903b1820 100644 --- a/azurerm/resource_arm_servicebus_topic.go +++ b/azurerm/resource_arm_servicebus_topic.go @@ -49,6 +49,7 @@ func resourceArmServiceBusTopic() *schema.Resource { string(servicebus.EntityStatusActive), string(servicebus.EntityStatusDisabled), }, true), + DiffSuppressFunc: ignoreCaseDiffSuppressFunc, }, "auto_delete_on_idle": { diff --git a/azurerm/resource_arm_servicebus_topic_test.go b/azurerm/resource_arm_servicebus_topic_test.go index f33c143d60c3..096467787a6b 100644 --- a/azurerm/resource_arm_servicebus_topic_test.go +++ b/azurerm/resource_arm_servicebus_topic_test.go @@ -296,6 +296,7 @@ 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) } From 55a30f046e0ce5e3c2ef17fde09fab594117219a Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Tue, 4 Jul 2017 12:35:53 +0100 Subject: [PATCH 5/6] Adding the new field to the docs --- website/docs/r/servicebus_topic.html.markdown | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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. From 1eebdf437460904314dd09763ab213cf9dc35676 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Wed, 5 Jul 2017 09:55:55 +0100 Subject: [PATCH 6/6] Switching to use the azure wrappers --- azurerm/resource_arm_servicebus_topic.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/azurerm/resource_arm_servicebus_topic.go b/azurerm/resource_arm_servicebus_topic.go index 0f0e903b1820..cd2d7b69e631 100644 --- a/azurerm/resource_arm_servicebus_topic.go +++ b/azurerm/resource_arm_servicebus_topic.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" + "github.com/jen20/riviera/azure" ) func resourceArmServiceBusTopic() *schema.Resource { @@ -134,26 +135,26 @@ func resourceArmServiceBusTopicCreate(d *schema.ResourceData, meta interface{}) Location: &location, TopicProperties: &servicebus.TopicProperties{ Status: servicebus.EntityStatus(status), - EnableBatchedOperations: &enableBatchedOps, - EnableExpress: &enableExpress, - FilteringMessagesBeforePublishing: &enableFiltering, - EnablePartitioning: &enablePartitioning, - MaxSizeInMegabytes: &maxSize, - RequiresDuplicateDetection: &requiresDuplicateDetection, - SupportOrdering: &supportOrdering, + 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) } _, err := client.CreateOrUpdate(resGroup, namespaceName, name, parameters)