From a6cb8adf840d31ab0b83ee633e5aa2d38ccd7f86 Mon Sep 17 00:00:00 2001 From: Igor Ljaskevic Date: Tue, 4 Jul 2017 14:29:15 +0100 Subject: [PATCH 1/8] Importing the work from hashicorp/terraform#14631 by @iljaskevic --- azurerm/config.go | 7 + azurerm/import_arm_servicebus_queue_test.go | 33 ++ azurerm/provider.go | 1 + azurerm/resource_arm_servicebus_queue.go | 254 +++++++++++++ azurerm/resource_arm_servicebus_queue_test.go | 348 ++++++++++++++++++ 5 files changed, 643 insertions(+) create mode 100644 azurerm/import_arm_servicebus_queue_test.go create mode 100644 azurerm/resource_arm_servicebus_queue.go create mode 100644 azurerm/resource_arm_servicebus_queue_test.go diff --git a/azurerm/config.go b/azurerm/config.go index ffdcdbb23af5..f588dd99b2d7 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -103,6 +103,7 @@ type ArmClient struct { trafficManagerEndpointsClient trafficmanager.EndpointsClient serviceBusNamespacesClient servicebus.NamespacesClient + serviceBusQueuesClient servicebus.QueuesClient serviceBusTopicsClient servicebus.TopicsClient serviceBusSubscriptionsClient servicebus.SubscriptionsClient @@ -471,6 +472,12 @@ func (c *Config) getArmClient() (*ArmClient, error) { sbnc.Sender = autorest.CreateSender(withRequestLogging()) client.serviceBusNamespacesClient = sbnc + sbqc := servicebus.NewQueuesClientWithBaseURI(endpoint, c.SubscriptionID) + setUserAgent(&sbqc.Client) + sbqc.Authorizer = auth + sbqc.Sender = autorest.CreateSender(withRequestLogging()) + client.serviceBusQueuesClient = sbqc + sbtc := servicebus.NewTopicsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&sbtc.Client) sbtc.Authorizer = auth diff --git a/azurerm/import_arm_servicebus_queue_test.go b/azurerm/import_arm_servicebus_queue_test.go new file mode 100644 index 000000000000..8617bd898f6b --- /dev/null +++ b/azurerm/import_arm_servicebus_queue_test.go @@ -0,0 +1,33 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAzureRMServiceBusQueue_importBasic(t *testing.T) { + resourceName := "azurerm_servicebus_queue.test" + + ri := acctest.RandInt() + config := fmt.Sprintf(testAccAzureRMServiceBusQueue_basic, ri, ri, ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: config, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} \ No newline at end of file diff --git a/azurerm/provider.go b/azurerm/provider.go index 2bf1b2ddf214..88d3839bd14f 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -104,6 +104,7 @@ func Provider() terraform.ResourceProvider { "azurerm_route": resourceArmRoute(), "azurerm_route_table": resourceArmRouteTable(), "azurerm_servicebus_namespace": resourceArmServiceBusNamespace(), + "azurerm_servicebus_queue": resourceArmServiceBusQueue(), "azurerm_servicebus_subscription": resourceArmServiceBusSubscription(), "azurerm_servicebus_topic": resourceArmServiceBusTopic(), "azurerm_sql_elasticpool": resourceArmSqlElasticPool(), diff --git a/azurerm/resource_arm_servicebus_queue.go b/azurerm/resource_arm_servicebus_queue.go new file mode 100644 index 000000000000..9db656c28580 --- /dev/null +++ b/azurerm/resource_arm_servicebus_queue.go @@ -0,0 +1,254 @@ +package azurerm + +import ( + "fmt" + "log" + "net/http" + + "github.com/Azure/azure-sdk-for-go/arm/servicebus" + "github.com/hashicorp/terraform/helper/schema" +) + +func resourceArmServiceBusQueue() *schema.Resource { + return &schema.Resource{ + Create: resourceArmServiceBusQueueCreate, + Read: resourceArmServiceBusQueueRead, + Update: resourceArmServiceBusQueueCreate, + Delete: resourceArmServiceBusQueueDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "namespace_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "location": locationSchema(), + + "resource_group_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "auto_delete_on_idle": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + + "default_message_ttl": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + + "duplicate_detection_history_time_window": { + Type: schema.TypeString, + Optional: true, + }, + + "enable_batched_operations": { + Type: schema.TypeBool, + Default: false, + Optional: true, + }, + + "enable_express": { + Type: schema.TypeBool, + Default: false, + Optional: true, + }, + + "enable_partitioning": { + Type: schema.TypeBool, + Default: false, + Optional: true, + ForceNew: true, + }, + + "max_size_in_megabytes": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + + "requires_duplicate_detection": { + Type: schema.TypeBool, + Default: false, + Optional: true, + ForceNew: true, + }, + + "support_ordering": { + Type: schema.TypeBool, + Default: false, + Optional: true, + }, + }, + } +} + +func resourceArmServiceBusQueueCreate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).serviceBusQueuesClient + log.Printf("[INFO] preparing arguments for Azure ARM ServiceBus Queue creation.") + + name := d.Get("name").(string) + namespaceName := d.Get("namespace_name").(string) + location := d.Get("location").(string) + resGroup := d.Get("resource_group_name").(string) + + parameters := servicebus.QueueCreateOrUpdateParameters{ + Name: &name, + Location: &location, + QueueProperties: &servicebus.QueueProperties{}, + } + + if autoDeleteOnIdle := d.Get("auto_delete_on_idle").(string); autoDeleteOnIdle != "" { + parameters.QueueProperties.AutoDeleteOnIdle = &autoDeleteOnIdle + } + + if defaultTTL := d.Get("default_message_ttl").(string); defaultTTL != "" { + parameters.QueueProperties.DefaultMessageTimeToLive = &defaultTTL + } + + if duplicateWindow := d.Get("duplicate_detection_history_time_window").(string); duplicateWindow != "" { + parameters.QueueProperties.DuplicateDetectionHistoryTimeWindow = &duplicateWindow + } + + // We need to retrieve the namespace because Premium namespace works differently from Basic and Standard, + // so it needs different rules applied to it. + namespace, nsErr := meta.(*ArmClient).serviceBusNamespacesClient.Get(resGroup, namespaceName) + if nsErr != nil { + return nsErr + } + + // Enforce Premium namespace to have partitioning enabled in Terraform. It is always enabled in Azure for + // Premium SKU. + if namespace.Sku.Name == servicebus.Premium && !d.Get("enable_partitioning").(bool) { + return fmt.Errorf("ServiceBus Queue (%s) must have Partitioning enabled for Premium SKU", name) + } + + // Enforce Premium namespace to have Express Entities disabled in Terraform since they are not supported for + // Premium SKU. + if namespace.Sku.Name == servicebus.Premium && d.Get("enable_express").(bool) { + return fmt.Errorf("ServiceBus Queue (%s) does not support Express Entities in Premium SKU and must be disabled", name) + } + + enableBatchedOps := d.Get("enable_batched_operations").(bool) + enableExpress := d.Get("enable_express").(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.QueueProperties.EnableBatchedOperations = &enableBatchedOps + parameters.QueueProperties.EnableExpress = &enableExpress + parameters.QueueProperties.EnablePartitioning = &enablePartitioning + parameters.QueueProperties.MaxSizeInMegabytes = &maxSize + parameters.QueueProperties.RequiresDuplicateDetection = &requiresDuplicateDetection + parameters.QueueProperties.SupportOrdering = &supportOrdering + + _, err := client.CreateOrUpdate(resGroup, namespaceName, name, parameters) + if err != nil { + return err + } + + read, err := client.Get(resGroup, namespaceName, name) + if err != nil { + return err + } + if read.ID == nil { + return fmt.Errorf("Cannot read ServiceBus Queue %s (resource group %s) ID", name, resGroup) + } + + d.SetId(*read.ID) + + return resourceArmServiceBusQueueRead(d, meta) +} + +func resourceArmServiceBusQueueRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).serviceBusQueuesClient + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resGroup := id.ResourceGroup + namespaceName := id.Path["namespaces"] + name := id.Path["queues"] + + resp, err := client.Get(resGroup, namespaceName, name) + if err != nil { + return fmt.Errorf("Error making Read request on Azure ServiceBus Queue %s: %s", name, err) + } + if resp.StatusCode == http.StatusNotFound { + d.SetId("") + return nil + } + + d.Set("name", resp.Name) + d.Set("resource_group_name", resGroup) + d.Set("namespace_name", namespaceName) + d.Set("location", azureRMNormalizeLocation(*resp.Location)) + + if resp.QueueProperties == nil { + return fmt.Errorf("Missing QueueProperties in response for Azure ServiceBus Queue %s: %s", name, err) + } + + props := resp.QueueProperties + d.Set("auto_delete_on_idle", props.AutoDeleteOnIdle) + d.Set("default_message_ttl", props.DefaultMessageTimeToLive) + d.Set("duplicate_detection_history_time_window", props.DuplicateDetectionHistoryTimeWindow) + + d.Set("enable_batched_operations", props.EnableBatchedOperations) + d.Set("enable_express", props.EnableExpress) + d.Set("enable_partitioning", props.EnablePartitioning) + d.Set("requires_duplicate_detection", props.RequiresDuplicateDetection) + d.Set("support_ordering", props.SupportOrdering) + + maxSize := int(*props.MaxSizeInMegabytes) + + // If the queue is NOT in a premium namespace (ie. it is Basic or Standard) and partitioning is enabled + // then the max size returned by the API will be 16 times greater than the value set. + if *props.EnablePartitioning { + namespace, err := meta.(*ArmClient).serviceBusNamespacesClient.Get(resGroup, namespaceName) + if err != nil { + return err + } + + if namespace.Sku.Name != servicebus.Premium { + const partitionCount = 16 + maxSize = int(*props.MaxSizeInMegabytes / partitionCount) + } + } + + d.Set("max_size_in_megabytes", maxSize) + + return nil +} + +func resourceArmServiceBusQueueDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).serviceBusQueuesClient + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resGroup := id.ResourceGroup + namespaceName := id.Path["namespaces"] + name := id.Path["queues"] + + _, err = client.Delete(resGroup, namespaceName, name) + + return err +} \ No newline at end of file diff --git a/azurerm/resource_arm_servicebus_queue_test.go b/azurerm/resource_arm_servicebus_queue_test.go new file mode 100644 index 000000000000..b3035feeb374 --- /dev/null +++ b/azurerm/resource_arm_servicebus_queue_test.go @@ -0,0 +1,348 @@ +package azurerm + +import ( + "fmt" + "net/http" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccAzureRMServiceBusQueue_basic(t *testing.T) { + ri := acctest.RandInt() + config := fmt.Sprintf(testAccAzureRMServiceBusQueue_basic, ri, ri, ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMServiceBusQueueExists("azurerm_servicebus_queue.test"), + resource.TestCheckResourceAttr( + "azurerm_servicebus_queue.test", "enable_batched_operations", "false"), + resource.TestCheckResourceAttr( + "azurerm_servicebus_queue.test", "enable_express", "false"), + resource.TestCheckResourceAttr( + "azurerm_servicebus_queue.test", "enable_partitioning", "false"), + ), + }, + }, + }) +} + +func TestAccAzureRMServiceBusQueue_update(t *testing.T) { + ri := acctest.RandInt() + preConfig := fmt.Sprintf(testAccAzureRMServiceBusQueue_basic, ri, ri, ri) + postConfig := fmt.Sprintf(testAccAzureRMServiceBusQueue_update, ri, ri, ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: preConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMServiceBusQueueExists("azurerm_servicebus_queue.test"), + resource.TestCheckResourceAttr( + "azurerm_servicebus_queue.test", "enable_batched_operations", "false"), + resource.TestCheckResourceAttr( + "azurerm_servicebus_queue.test", "enable_express", "false"), + ), + }, + resource.TestStep{ + Config: postConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "azurerm_servicebus_queue.test", "enable_batched_operations", "true"), + resource.TestCheckResourceAttr( + "azurerm_servicebus_queue.test", "enable_express", "true"), + resource.TestCheckResourceAttr( + "azurerm_servicebus_queue.test", "max_size_in_megabytes", "2048"), + ), + }, + }, + }) +} + +func TestAccAzureRMServiceBusQueue_enablePartitioningStandard(t *testing.T) { + ri := acctest.RandInt() + preConfig := fmt.Sprintf(testAccAzureRMServiceBusQueue_basic, ri, ri, ri) + postConfig := fmt.Sprintf(testAccAzureRMServiceBusQueue_enablePartitioningStandard, ri, ri, ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: preConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMServiceBusQueueExists("azurerm_servicebus_queue.test"), + resource.TestCheckResourceAttr( + "azurerm_servicebus_queue.test", "enable_partitioning", "false"), + ), + }, + resource.TestStep{ + Config: postConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "azurerm_servicebus_queue.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_queue.test", "max_size_in_megabytes", "5120"), + ), + }, + }, + }) +} + +func TestAccAzureRMServiceBusQueue_defaultEnablePartitioningPremium(t *testing.T) { + ri := acctest.RandInt() + config := fmt.Sprintf(testAccAzureRMServiceBusQueue_Premium, ri, ri, ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMServiceBusQueueExists("azurerm_servicebus_queue.test"), + resource.TestCheckResourceAttr( + "azurerm_servicebus_queue.test", "enable_partitioning", "true"), + resource.TestCheckResourceAttr( + "azurerm_servicebus_queue.test", "enable_express", "false"), + ), + }, + }, + }) +} + +func TestAccAzureRMServiceBusQueue_enableDuplicateDetection(t *testing.T) { + ri := acctest.RandInt() + preConfig := fmt.Sprintf(testAccAzureRMServiceBusQueue_basic, ri, ri, ri) + postConfig := fmt.Sprintf(testAccAzureRMServiceBusQueue_enableDuplicateDetection, ri, ri, ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: preConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMServiceBusQueueExists("azurerm_servicebus_queue.test"), + resource.TestCheckResourceAttr( + "azurerm_servicebus_queue.test", "requires_duplicate_detection", "false"), + ), + }, + resource.TestStep{ + Config: postConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "azurerm_servicebus_queue.test", "requires_duplicate_detection", "true"), + ), + }, + }, + }) +} + +func testCheckAzureRMServiceBusQueueDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).serviceBusQueuesClient + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_servicebus_queue" { + continue + } + + name := rs.Primary.Attributes["name"] + namespaceName := rs.Primary.Attributes["namespace_name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := client.Get(resourceGroup, namespaceName, name) + if err != nil { + if resp.StatusCode == http.StatusNotFound { + return nil + } + return err + } + + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("ServiceBus Queue still exists:\n%#v", resp.QueueProperties) + } + } + + return nil +} + +func testCheckAzureRMServiceBusQueueExists(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + queueName := rs.Primary.Attributes["name"] + namespaceName := rs.Primary.Attributes["namespace_name"] + resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] + if !hasResourceGroup { + return fmt.Errorf("Bad: no resource group found in state for queue: %s", queueName) + } + + client := testAccProvider.Meta().(*ArmClient).serviceBusQueuesClient + + resp, err := client.Get(resourceGroup, namespaceName, queueName) + if err != nil { + return fmt.Errorf("Bad: Get on serviceBusQueuesClient: %s", err) + } + + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Bad: Queue %q (resource group: %q) does not exist", namespaceName, resourceGroup) + } + + return nil + } +} + +var testAccAzureRMServiceBusQueue_basic = ` +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_queue" "test" { + name = "acctestservicebusqueue-%d" + location = "West US" + namespace_name = "${azurerm_servicebus_namespace.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" +} +` + +var testAccAzureRMServiceBusQueue_Premium = ` +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 = "premium" +} + +resource "azurerm_servicebus_queue" "test" { + name = "acctestservicebusqueue-%d" + location = "West US" + namespace_name = "${azurerm_servicebus_namespace.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + enable_partitioning = true + enable_express = false +} +` + +var testAccAzureRMServiceBusQueue_update = ` +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_queue" "test" { + name = "acctestservicebusqueue-%d" + location = "West US" + namespace_name = "${azurerm_servicebus_namespace.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + enable_batched_operations = true + enable_express = true + max_size_in_megabytes = 2048 +} +` + +var testAccAzureRMServiceBusQueue_enablePartitioningStandard = ` +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_queue" "test" { + name = "acctestservicebusqueue-%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 = 5120 +} +` + +var testAccAzureRMServiceBusQueue_enablePartitioningPremium = ` +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 = "premium" +} + +resource "azurerm_servicebus_queue" "test" { + name = "acctestservicebusqueue-%d" + location = "West US" + namespace_name = "${azurerm_servicebus_namespace.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + enable_partitioning = false +} +` + +var testAccAzureRMServiceBusQueue_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_queue" "test" { + name = "acctestservicebusqueue-%d" + location = "West US" + namespace_name = "${azurerm_servicebus_namespace.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + requires_duplicate_detection = true +} +` \ No newline at end of file From d8229f4d568c74709a4c0a097d6f0e3dcb0ce0ea Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Tue, 4 Jul 2017 14:35:04 +0100 Subject: [PATCH 2/8] Refactoring the tests --- azurerm/import_arm_servicebus_queue_test.go | 8 +- azurerm/resource_arm_servicebus_queue_test.go | 84 ++++++++----------- 2 files changed, 39 insertions(+), 53 deletions(-) diff --git a/azurerm/import_arm_servicebus_queue_test.go b/azurerm/import_arm_servicebus_queue_test.go index 8617bd898f6b..1fe9e8a22de8 100644 --- a/azurerm/import_arm_servicebus_queue_test.go +++ b/azurerm/import_arm_servicebus_queue_test.go @@ -1,7 +1,6 @@ package azurerm import ( - "fmt" "testing" "github.com/hashicorp/terraform/helper/acctest" @@ -12,18 +11,17 @@ func TestAccAzureRMServiceBusQueue_importBasic(t *testing.T) { resourceName := "azurerm_servicebus_queue.test" ri := acctest.RandInt() - config := fmt.Sprintf(testAccAzureRMServiceBusQueue_basic, ri, ri, ri) + config := testAccAzureRMServiceBusQueue_basic(ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: config, }, - - resource.TestStep{ + { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, diff --git a/azurerm/resource_arm_servicebus_queue_test.go b/azurerm/resource_arm_servicebus_queue_test.go index b3035feeb374..dadb15f604e5 100644 --- a/azurerm/resource_arm_servicebus_queue_test.go +++ b/azurerm/resource_arm_servicebus_queue_test.go @@ -12,14 +12,14 @@ import ( func TestAccAzureRMServiceBusQueue_basic(t *testing.T) { ri := acctest.RandInt() - config := fmt.Sprintf(testAccAzureRMServiceBusQueue_basic, ri, ri, ri) + config := testAccAzureRMServiceBusQueue_basic(ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: config, Check: resource.ComposeTestCheckFunc( testCheckAzureRMServiceBusQueueExists("azurerm_servicebus_queue.test"), @@ -37,15 +37,15 @@ func TestAccAzureRMServiceBusQueue_basic(t *testing.T) { func TestAccAzureRMServiceBusQueue_update(t *testing.T) { ri := acctest.RandInt() - preConfig := fmt.Sprintf(testAccAzureRMServiceBusQueue_basic, ri, ri, ri) - postConfig := fmt.Sprintf(testAccAzureRMServiceBusQueue_update, ri, ri, ri) + preConfig := testAccAzureRMServiceBusQueue_basic(ri) + postConfig := testAccAzureRMServiceBusQueue_update(ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: preConfig, Check: resource.ComposeTestCheckFunc( testCheckAzureRMServiceBusQueueExists("azurerm_servicebus_queue.test"), @@ -55,7 +55,7 @@ func TestAccAzureRMServiceBusQueue_update(t *testing.T) { "azurerm_servicebus_queue.test", "enable_express", "false"), ), }, - resource.TestStep{ + { Config: postConfig, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -72,15 +72,15 @@ func TestAccAzureRMServiceBusQueue_update(t *testing.T) { func TestAccAzureRMServiceBusQueue_enablePartitioningStandard(t *testing.T) { ri := acctest.RandInt() - preConfig := fmt.Sprintf(testAccAzureRMServiceBusQueue_basic, ri, ri, ri) - postConfig := fmt.Sprintf(testAccAzureRMServiceBusQueue_enablePartitioningStandard, ri, ri, ri) + preConfig := testAccAzureRMServiceBusQueue_basic(ri) + postConfig := testAccAzureRMServiceBusQueue_enablePartitioningStandard(ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: preConfig, Check: resource.ComposeTestCheckFunc( testCheckAzureRMServiceBusQueueExists("azurerm_servicebus_queue.test"), @@ -88,7 +88,7 @@ func TestAccAzureRMServiceBusQueue_enablePartitioningStandard(t *testing.T) { "azurerm_servicebus_queue.test", "enable_partitioning", "false"), ), }, - resource.TestStep{ + { Config: postConfig, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -104,14 +104,14 @@ func TestAccAzureRMServiceBusQueue_enablePartitioningStandard(t *testing.T) { func TestAccAzureRMServiceBusQueue_defaultEnablePartitioningPremium(t *testing.T) { ri := acctest.RandInt() - config := fmt.Sprintf(testAccAzureRMServiceBusQueue_Premium, ri, ri, ri) + config := testAccAzureRMServiceBusQueue_Premium(ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: config, Check: resource.ComposeTestCheckFunc( testCheckAzureRMServiceBusQueueExists("azurerm_servicebus_queue.test"), @@ -127,15 +127,15 @@ func TestAccAzureRMServiceBusQueue_defaultEnablePartitioningPremium(t *testing.T func TestAccAzureRMServiceBusQueue_enableDuplicateDetection(t *testing.T) { ri := acctest.RandInt() - preConfig := fmt.Sprintf(testAccAzureRMServiceBusQueue_basic, ri, ri, ri) - postConfig := fmt.Sprintf(testAccAzureRMServiceBusQueue_enableDuplicateDetection, ri, ri, ri) + preConfig := testAccAzureRMServiceBusQueue_basic(ri) + postConfig := testAccAzureRMServiceBusQueue_enableDuplicateDetection(ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: preConfig, Check: resource.ComposeTestCheckFunc( testCheckAzureRMServiceBusQueueExists("azurerm_servicebus_queue.test"), @@ -143,7 +143,7 @@ func TestAccAzureRMServiceBusQueue_enableDuplicateDetection(t *testing.T) { "azurerm_servicebus_queue.test", "requires_duplicate_detection", "false"), ), }, - resource.TestStep{ + { Config: postConfig, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -212,7 +212,8 @@ func testCheckAzureRMServiceBusQueueExists(name string) resource.TestCheckFunc { } } -var testAccAzureRMServiceBusQueue_basic = ` +func testAccAzureRMServiceBusQueue_basic(rInt int) string { + return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "West US" @@ -231,9 +232,11 @@ resource "azurerm_servicebus_queue" "test" { namespace_name = "${azurerm_servicebus_namespace.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -` +`, rInt, rInt, rInt) +} -var testAccAzureRMServiceBusQueue_Premium = ` +func testAccAzureRMServiceBusQueue_Premium(rInt int) string { + return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "West US" @@ -254,9 +257,11 @@ resource "azurerm_servicebus_queue" "test" { enable_partitioning = true enable_express = false } -` +`, rInt, rInt, rInt) +} -var testAccAzureRMServiceBusQueue_update = ` +func testAccAzureRMServiceBusQueue_update(rInt int) string { + return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "West US" @@ -278,9 +283,11 @@ resource "azurerm_servicebus_queue" "test" { enable_express = true max_size_in_megabytes = 2048 } -` +`, rInt, rInt, rInt) +} -var testAccAzureRMServiceBusQueue_enablePartitioningStandard = ` +func testAccAzureRMServiceBusQueue_enablePartitioningStandard(rInt int) string { + return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "West US" @@ -299,33 +306,13 @@ resource "azurerm_servicebus_queue" "test" { namespace_name = "${azurerm_servicebus_namespace.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" enable_partitioning = true - max_size_in_megabytes = 5120 -} -` - -var testAccAzureRMServiceBusQueue_enablePartitioningPremium = ` -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 = "premium" + max_size_in_megabytes = 5120 } - -resource "azurerm_servicebus_queue" "test" { - name = "acctestservicebusqueue-%d" - location = "West US" - namespace_name = "${azurerm_servicebus_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - enable_partitioning = false +`, rInt, rInt, rInt) } -` -var testAccAzureRMServiceBusQueue_enableDuplicateDetection = ` +func testAccAzureRMServiceBusQueue_enableDuplicateDetection(rInt int) string { + return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "West US" @@ -345,4 +332,5 @@ resource "azurerm_servicebus_queue" "test" { resource_group_name = "${azurerm_resource_group.test.name}" requires_duplicate_detection = true } -` \ No newline at end of file +`, rInt, rInt, rInt) +} From 69517e0ad543d70beff88fe698fb4193e5cc86a1 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Tue, 4 Jul 2017 14:35:13 +0100 Subject: [PATCH 3/8] Formatting --- azurerm/import_arm_servicebus_queue_test.go | 2 +- azurerm/resource_arm_servicebus_queue.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/azurerm/import_arm_servicebus_queue_test.go b/azurerm/import_arm_servicebus_queue_test.go index 1fe9e8a22de8..03d943e7d894 100644 --- a/azurerm/import_arm_servicebus_queue_test.go +++ b/azurerm/import_arm_servicebus_queue_test.go @@ -28,4 +28,4 @@ func TestAccAzureRMServiceBusQueue_importBasic(t *testing.T) { }, }, }) -} \ No newline at end of file +} diff --git a/azurerm/resource_arm_servicebus_queue.go b/azurerm/resource_arm_servicebus_queue.go index 9db656c28580..687ab704588b 100644 --- a/azurerm/resource_arm_servicebus_queue.go +++ b/azurerm/resource_arm_servicebus_queue.go @@ -251,4 +251,4 @@ func resourceArmServiceBusQueueDelete(d *schema.ResourceData, meta interface{}) _, err = client.Delete(resGroup, namespaceName, name) return err -} \ No newline at end of file +} From 27041873902b25d86d215faa0447d1a7fc6aa670 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Tue, 4 Jul 2017 14:37:21 +0100 Subject: [PATCH 4/8] Importing the docs --- website/azurerm.erb | 4 + website/docs/r/servicebus_queue.html.markdown | 114 ++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 website/docs/r/servicebus_queue.html.markdown diff --git a/website/azurerm.erb b/website/azurerm.erb index 22e434fe8a75..1dc68166ff3c 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -288,6 +288,10 @@ azurerm_servicebus_namespace + > + azurerm_servicebus_queue + + > azurerm_servicebus_subscription diff --git a/website/docs/r/servicebus_queue.html.markdown b/website/docs/r/servicebus_queue.html.markdown new file mode 100644 index 000000000000..0100235eac23 --- /dev/null +++ b/website/docs/r/servicebus_queue.html.markdown @@ -0,0 +1,114 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_servicebus_queue" +sidebar_current: "docs-azurerm-resource-servicebus-queue" +description: |- + Create a ServiceBus Queue. +--- + +# azurerm\_servicebus\_queue + +Create and manage a ServiceBus Queue. + +## Example Usage + +``` +resource "azurerm_resource_group" "test" { + name = "resourceGroup1" + location = "West US" +} + +resource "azurerm_servicebus_namespace" "test" { + name = "acceptanceTestServiceBusNamespace" + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" + sku = "standard" + + tags { + environment = "Production" + } +} + +resource "azurerm_servicebus_queue" "test" { + name = "testQueue" + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" + namespace_name = "${azurerm_servicebus_namespace.test.name}" + + enable_partitioning = true +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name of the ServiceBus Queue resource. Changing this forces a + new resource to be created. + +* `namespace_name` - (Required) The name of the ServiceBus Namespace to create + this queue in. Changing this forces a new resource to be created. + +* `location` - (Required) Specifies the supported Azure location where the resource exists. + Changing this forces a new resource to be created. + +* `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. + +* `auto_delete_on_idle` - (Optional) The idle interval after which the + Queue is automatically deleted, minimum of 5 minutes. Provided in the [TimeSpan](#timespan-format) + format. + +* `default_message_ttl` - (Optional) The TTL of messages sent to this queue. This is the default value + used when TTL is not set on message itself. Provided in the [TimeSpan](#timespan-format) + format. + +* `duplicate_detection_history_time_window` - (Optional) The duration during which + duplicates can be detected. Default value is 10 minutes. Provided in the [TimeSpan](#timespan-format) format. + +* `enable_batched_operations` - (Optional) Boolean flag which controls if server-side + batched operations are enabled. Defaults to `false`. + +* `enable_express` - (Optional) Boolean flag which controls whether Express Entities + are enabled. An express queue holds a message in memory temporarily before writing + it to persistent storage. Defaults to `false` for Basic and Standard. For Premium, it MUST + be set to `false`. + +~> **NOTE:** Service Bus Premium namespaces do not support Express Entities, so `enable_express` MUST be set to `false`. + +* `enable_partitioning` - (Optional) Boolean flag which controls whether to enable + the queue to be partitioned across multiple message brokers. Changing this forces + a new resource to be created. Defaults to `false` for Basic and Standard. For Premium, it MUST + be set to `true`. + +~> **NOTE:** Service Bus Premium namespaces are always partitioned, so `enable_partitioning` MUST be set to `true`. + +* `max_size_in_megabytes` - (Optional) Integer value which controls the size of + memory allocated for the queue. For supported values see the "Queue/topic size" + section of [this document](https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-quotas). + +* `requires_duplicate_detection` - (Optional) Boolean flag which controls whether + the Queue requires duplicate detection. Changing this forces + a new resource to be created. Defaults to `false`. + +* `support_ordering` - (Optional) Boolean flag which controls whether the Queue + supports ordering. Defaults to `false`. + +### TimeSpan Format + +Some arguments for this resource are required in the TimeSpan format which is +used to represent a length of time. The supported format is documented [here](https://msdn.microsoft.com/en-us/library/se73z7b9(v=vs.110).aspx#Anchor_2) + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ServiceBus Queue ID. + +## Import + +Service Bus Queue can be imported using the `resource id`, e.g. + +``` +terraform import azurerm_servicebus_queue.test /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/microsoft.servicebus/namespaces/sbns1/queues/snqueue1 +``` From 1fb24c55d05f92f685c3942e43785259558dc5c4 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Tue, 4 Jul 2017 15:44:39 +0100 Subject: [PATCH 5/8] Refactoring --- azurerm/resource_arm_servicebus_queue.go | 38 ++++++++++++------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/azurerm/resource_arm_servicebus_queue.go b/azurerm/resource_arm_servicebus_queue.go index 687ab704588b..71177eafd075 100644 --- a/azurerm/resource_arm_servicebus_queue.go +++ b/azurerm/resource_arm_servicebus_queue.go @@ -11,9 +11,9 @@ import ( func resourceArmServiceBusQueue() *schema.Resource { return &schema.Resource{ - Create: resourceArmServiceBusQueueCreate, + Create: resourceArmServiceBusQueueCreateUpdate, Read: resourceArmServiceBusQueueRead, - Update: resourceArmServiceBusQueueCreate, + Update: resourceArmServiceBusQueueCreateUpdate, Delete: resourceArmServiceBusQueueDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, @@ -98,19 +98,33 @@ func resourceArmServiceBusQueue() *schema.Resource { } } -func resourceArmServiceBusQueueCreate(d *schema.ResourceData, meta interface{}) error { +func resourceArmServiceBusQueueCreateUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*ArmClient).serviceBusQueuesClient - log.Printf("[INFO] preparing arguments for Azure ARM ServiceBus Queue creation.") + log.Printf("[INFO] preparing arguments for AzureRM ServiceBus Queue creation/update.") name := d.Get("name").(string) namespaceName := d.Get("namespace_name").(string) location := d.Get("location").(string) resGroup := d.Get("resource_group_name").(string) + enableBatchedOps := d.Get("enable_batched_operations").(bool) + enableExpress := d.Get("enable_express").(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.QueueCreateOrUpdateParameters{ Name: &name, Location: &location, - QueueProperties: &servicebus.QueueProperties{}, + QueueProperties: &servicebus.QueueProperties{ + EnableBatchedOperations: &enableBatchedOps, + EnableExpress: &enableExpress, + EnablePartitioning: &enablePartitioning, + MaxSizeInMegabytes: &maxSize, + RequiresDuplicateDetection: &requiresDuplicateDetection, + SupportOrdering: &supportOrdering, + }, } if autoDeleteOnIdle := d.Get("auto_delete_on_idle").(string); autoDeleteOnIdle != "" { @@ -144,20 +158,6 @@ func resourceArmServiceBusQueueCreate(d *schema.ResourceData, meta interface{}) return fmt.Errorf("ServiceBus Queue (%s) does not support Express Entities in Premium SKU and must be disabled", name) } - enableBatchedOps := d.Get("enable_batched_operations").(bool) - enableExpress := d.Get("enable_express").(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.QueueProperties.EnableBatchedOperations = &enableBatchedOps - parameters.QueueProperties.EnableExpress = &enableExpress - parameters.QueueProperties.EnablePartitioning = &enablePartitioning - parameters.QueueProperties.MaxSizeInMegabytes = &maxSize - parameters.QueueProperties.RequiresDuplicateDetection = &requiresDuplicateDetection - parameters.QueueProperties.SupportOrdering = &supportOrdering - _, err := client.CreateOrUpdate(resGroup, namespaceName, name, parameters) if err != nil { return err From 5a77880ec48b52beafb9bf20021b56c03847a718 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Tue, 4 Jul 2017 16:12:06 +0100 Subject: [PATCH 6/8] Making `duplicate_detection_history_time_window` computed --- azurerm/resource_arm_servicebus_queue.go | 1 + 1 file changed, 1 insertion(+) diff --git a/azurerm/resource_arm_servicebus_queue.go b/azurerm/resource_arm_servicebus_queue.go index 71177eafd075..43c01707094c 100644 --- a/azurerm/resource_arm_servicebus_queue.go +++ b/azurerm/resource_arm_servicebus_queue.go @@ -55,6 +55,7 @@ func resourceArmServiceBusQueue() *schema.Resource { "duplicate_detection_history_time_window": { Type: schema.TypeString, Optional: true, + Computed: true, }, "enable_batched_operations": { From f2182ff294429eea63f4aaa1725440a420c542b0 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Tue, 4 Jul 2017 16:23:35 +0100 Subject: [PATCH 7/8] Refactoring the tests --- azurerm/resource_arm_servicebus_queue_test.go | 90 +++++++++---------- 1 file changed, 40 insertions(+), 50 deletions(-) diff --git a/azurerm/resource_arm_servicebus_queue_test.go b/azurerm/resource_arm_servicebus_queue_test.go index dadb15f604e5..75733d079cac 100644 --- a/azurerm/resource_arm_servicebus_queue_test.go +++ b/azurerm/resource_arm_servicebus_queue_test.go @@ -11,6 +11,7 @@ import ( ) func TestAccAzureRMServiceBusQueue_basic(t *testing.T) { + resourceName := "azurerm_servicebus_queue.test" ri := acctest.RandInt() config := testAccAzureRMServiceBusQueue_basic(ri) @@ -22,13 +23,10 @@ func TestAccAzureRMServiceBusQueue_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusQueueExists("azurerm_servicebus_queue.test"), - resource.TestCheckResourceAttr( - "azurerm_servicebus_queue.test", "enable_batched_operations", "false"), - resource.TestCheckResourceAttr( - "azurerm_servicebus_queue.test", "enable_express", "false"), - resource.TestCheckResourceAttr( - "azurerm_servicebus_queue.test", "enable_partitioning", "false"), + testCheckAzureRMServiceBusQueueExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "enable_batched_operations", "false"), + resource.TestCheckResourceAttr(resourceName, "enable_express", "false"), + resource.TestCheckResourceAttr(resourceName, "enable_partitioning", "false"), ), }, }, @@ -36,6 +34,7 @@ func TestAccAzureRMServiceBusQueue_basic(t *testing.T) { } func TestAccAzureRMServiceBusQueue_update(t *testing.T) { + resourceName := "azurerm_servicebus_queue.test" ri := acctest.RandInt() preConfig := testAccAzureRMServiceBusQueue_basic(ri) postConfig := testAccAzureRMServiceBusQueue_update(ri) @@ -48,22 +47,17 @@ func TestAccAzureRMServiceBusQueue_update(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusQueueExists("azurerm_servicebus_queue.test"), - resource.TestCheckResourceAttr( - "azurerm_servicebus_queue.test", "enable_batched_operations", "false"), - resource.TestCheckResourceAttr( - "azurerm_servicebus_queue.test", "enable_express", "false"), + testCheckAzureRMServiceBusQueueExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "enable_batched_operations", "false"), + resource.TestCheckResourceAttr(resourceName, "enable_express", "false"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "azurerm_servicebus_queue.test", "enable_batched_operations", "true"), - resource.TestCheckResourceAttr( - "azurerm_servicebus_queue.test", "enable_express", "true"), - resource.TestCheckResourceAttr( - "azurerm_servicebus_queue.test", "max_size_in_megabytes", "2048"), + resource.TestCheckResourceAttr(resourceName, "enable_batched_operations", "true"), + resource.TestCheckResourceAttr(resourceName, "enable_express", "true"), + resource.TestCheckResourceAttr(resourceName, "max_size_in_megabytes", "2048"), ), }, }, @@ -71,6 +65,7 @@ func TestAccAzureRMServiceBusQueue_update(t *testing.T) { } func TestAccAzureRMServiceBusQueue_enablePartitioningStandard(t *testing.T) { + resourceName := "azurerm_servicebus_queue.test" ri := acctest.RandInt() preConfig := testAccAzureRMServiceBusQueue_basic(ri) postConfig := testAccAzureRMServiceBusQueue_enablePartitioningStandard(ri) @@ -83,19 +78,16 @@ func TestAccAzureRMServiceBusQueue_enablePartitioningStandard(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusQueueExists("azurerm_servicebus_queue.test"), - resource.TestCheckResourceAttr( - "azurerm_servicebus_queue.test", "enable_partitioning", "false"), + testCheckAzureRMServiceBusQueueExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "enable_partitioning", "false"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "azurerm_servicebus_queue.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_queue.test", "max_size_in_megabytes", "5120"), + resource.TestCheckResourceAttr(resourceName, "max_size_in_megabytes", "5120"), ), }, }, @@ -103,6 +95,7 @@ func TestAccAzureRMServiceBusQueue_enablePartitioningStandard(t *testing.T) { } func TestAccAzureRMServiceBusQueue_defaultEnablePartitioningPremium(t *testing.T) { + resourceName := "azurerm_servicebus_queue.test" ri := acctest.RandInt() config := testAccAzureRMServiceBusQueue_Premium(ri) @@ -114,11 +107,9 @@ func TestAccAzureRMServiceBusQueue_defaultEnablePartitioningPremium(t *testing.T { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusQueueExists("azurerm_servicebus_queue.test"), - resource.TestCheckResourceAttr( - "azurerm_servicebus_queue.test", "enable_partitioning", "true"), - resource.TestCheckResourceAttr( - "azurerm_servicebus_queue.test", "enable_express", "false"), + testCheckAzureRMServiceBusQueueExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "enable_partitioning", "true"), + resource.TestCheckResourceAttr(resourceName, "enable_express", "false"), ), }, }, @@ -126,6 +117,7 @@ func TestAccAzureRMServiceBusQueue_defaultEnablePartitioningPremium(t *testing.T } func TestAccAzureRMServiceBusQueue_enableDuplicateDetection(t *testing.T) { + resourceName := "azurerm_servicebus_queue.test" ri := acctest.RandInt() preConfig := testAccAzureRMServiceBusQueue_basic(ri) postConfig := testAccAzureRMServiceBusQueue_enableDuplicateDetection(ri) @@ -138,16 +130,14 @@ func TestAccAzureRMServiceBusQueue_enableDuplicateDetection(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusQueueExists("azurerm_servicebus_queue.test"), - resource.TestCheckResourceAttr( - "azurerm_servicebus_queue.test", "requires_duplicate_detection", "false"), + testCheckAzureRMServiceBusQueueExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "requires_duplicate_detection", "false"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "azurerm_servicebus_queue.test", "requires_duplicate_detection", "true"), + resource.TestCheckResourceAttr(resourceName, "requires_duplicate_detection", "true"), ), }, }, @@ -221,16 +211,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_servicebus_namespace" "test" { name = "acctestservicebusnamespace-%d" - location = "West US" resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" sku = "standard" } resource "azurerm_servicebus_queue" "test" { name = "acctestservicebusqueue-%d" - location = "West US" - namespace_name = "${azurerm_servicebus_namespace.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + namespace_name = "${azurerm_servicebus_namespace.test.name}" } `, rInt, rInt, rInt) } @@ -244,16 +234,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_servicebus_namespace" "test" { name = "acctestservicebusnamespace-%d" - location = "West US" resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" sku = "premium" } resource "azurerm_servicebus_queue" "test" { name = "acctestservicebusqueue-%d" - location = "West US" - namespace_name = "${azurerm_servicebus_namespace.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + namespace_name = "${azurerm_servicebus_namespace.test.name}" enable_partitioning = true enable_express = false } @@ -269,16 +259,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_servicebus_namespace" "test" { name = "acctestservicebusnamespace-%d" - location = "West US" resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" sku = "standard" } resource "azurerm_servicebus_queue" "test" { name = "acctestservicebusqueue-%d" - location = "West US" - namespace_name = "${azurerm_servicebus_namespace.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + namespace_name = "${azurerm_servicebus_namespace.test.name}" enable_batched_operations = true enable_express = true max_size_in_megabytes = 2048 @@ -295,16 +285,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_servicebus_namespace" "test" { name = "acctestservicebusnamespace-%d" - location = "West US" resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" sku = "standard" } resource "azurerm_servicebus_queue" "test" { name = "acctestservicebusqueue-%d" - location = "West US" - namespace_name = "${azurerm_servicebus_namespace.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + namespace_name = "${azurerm_servicebus_namespace.test.name}" enable_partitioning = true max_size_in_megabytes = 5120 } @@ -320,16 +310,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_servicebus_namespace" "test" { name = "acctestservicebusnamespace-%d" - location = "West US" resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" sku = "standard" } resource "azurerm_servicebus_queue" "test" { name = "acctestservicebusqueue-%d" - location = "West US" - namespace_name = "${azurerm_servicebus_namespace.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + namespace_name = "${azurerm_servicebus_namespace.test.name}" requires_duplicate_detection = true } `, rInt, rInt, rInt) From 5be2cb7c972ba0e55b2b603824c51dce3b9ccc11 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Tue, 4 Jul 2017 16:28:30 +0100 Subject: [PATCH 8/8] Fixing the formatting --- azurerm/resource_arm_servicebus_queue.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/azurerm/resource_arm_servicebus_queue.go b/azurerm/resource_arm_servicebus_queue.go index 43c01707094c..3b8be54402c5 100644 --- a/azurerm/resource_arm_servicebus_queue.go +++ b/azurerm/resource_arm_servicebus_queue.go @@ -116,15 +116,15 @@ func resourceArmServiceBusQueueCreateUpdate(d *schema.ResourceData, meta interfa supportOrdering := d.Get("support_ordering").(bool) parameters := servicebus.QueueCreateOrUpdateParameters{ - Name: &name, - Location: &location, + Name: &name, + Location: &location, QueueProperties: &servicebus.QueueProperties{ - EnableBatchedOperations: &enableBatchedOps, - EnableExpress: &enableExpress, - EnablePartitioning: &enablePartitioning, - MaxSizeInMegabytes: &maxSize, + EnableBatchedOperations: &enableBatchedOps, + EnableExpress: &enableExpress, + EnablePartitioning: &enablePartitioning, + MaxSizeInMegabytes: &maxSize, RequiresDuplicateDetection: &requiresDuplicateDetection, - SupportOrdering: &supportOrdering, + SupportOrdering: &supportOrdering, }, }