From 1e91336afd311427a499723f8a9577346418a44b Mon Sep 17 00:00:00 2001 From: magodo Date: Mon, 6 Jan 2020 15:30:19 +0800 Subject: [PATCH 1/4] add condition for storage account queue --- .../storage/resource_arm_storage_account.go | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/azurerm/internal/services/storage/resource_arm_storage_account.go b/azurerm/internal/services/storage/resource_arm_storage_account.go index 26965313008d..a9ff867fe4c8 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_account.go +++ b/azurerm/internal/services/storage/resource_arm_storage_account.go @@ -1239,20 +1239,25 @@ func resourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) err } } - queueClient, err := storageClient.QueuesClient(ctx, *account) - if err != nil { - return fmt.Errorf("Error building Queues Client: %s", err) - } + // queue is only available for certain tier and kind (as specified below) + if resp.Sku.Tier == storage.Standard { + if resp.Kind == storage.Storage || resp.Kind == storage.StorageV2 { + queueClient, err := storageClient.QueuesClient(ctx, *account) + if err != nil { + return fmt.Errorf("Error building Queues Client: %s", err) + } - queueProps, err := queueClient.GetServiceProperties(ctx, name) - if err != nil { - if queueProps.Response.Response != nil && !utils.ResponseWasNotFound(queueProps.Response) { - return fmt.Errorf("Error reading queue properties for AzureRM Storage Account %q: %+v", name, err) - } - } + queueProps, err := queueClient.GetServiceProperties(ctx, name) + if err != nil { + if queueProps.Response.Response != nil && !utils.ResponseWasNotFound(queueProps.Response) { + return fmt.Errorf("Error reading queue properties for AzureRM Storage Account %q: %+v", name, err) + } + } - if err := d.Set("queue_properties", flattenQueueProperties(queueProps)); err != nil { - return fmt.Errorf("Error setting `queue_properties `for AzureRM Storage Account %q: %+v", name, err) + if err := d.Set("queue_properties", flattenQueueProperties(queueProps)); err != nil { + return fmt.Errorf("Error setting `queue_properties `for AzureRM Storage Account %q: %+v", name, err) + } + } } return tags.FlattenAndSet(d, resp.Tags) From c16b511e9c04f63979577c82e162bd98b51531fe Mon Sep 17 00:00:00 2001 From: magodo Date: Tue, 7 Jan 2020 20:59:18 +0800 Subject: [PATCH 2/4] Nil check resp.Sku `resp.Sku` is a nilable object here, so we'd need to nil-check this first: Co-Authored-By: Tom Harvey --- .../internal/services/storage/resource_arm_storage_account.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/azurerm/internal/services/storage/resource_arm_storage_account.go b/azurerm/internal/services/storage/resource_arm_storage_account.go index a9ff867fe4c8..a2a87c2e82c3 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_account.go +++ b/azurerm/internal/services/storage/resource_arm_storage_account.go @@ -1240,6 +1240,10 @@ func resourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) err } // queue is only available for certain tier and kind (as specified below) + if resp.Sku == nil { + return fmt.Errorf("Error retrieving Storage Account %q (Resource Group %q): `sku` was nil", name, resourceGrup) + } + if resp.Sku.Tier == storage.Standard { if resp.Kind == storage.Storage || resp.Kind == storage.StorageV2 { queueClient, err := storageClient.QueuesClient(ctx, *account) From e56f5ee793e1f5a3300b1afc88b1153781e07c31 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Wed, 8 Jan 2020 16:42:03 +0100 Subject: [PATCH 3/4] fixing the linting --- .../internal/services/storage/resource_arm_storage_account.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/storage/resource_arm_storage_account.go b/azurerm/internal/services/storage/resource_arm_storage_account.go index a2a87c2e82c3..aacac91fe213 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_account.go +++ b/azurerm/internal/services/storage/resource_arm_storage_account.go @@ -1243,7 +1243,7 @@ func resourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) err if resp.Sku == nil { return fmt.Errorf("Error retrieving Storage Account %q (Resource Group %q): `sku` was nil", name, resourceGrup) } - + if resp.Sku.Tier == storage.Standard { if resp.Kind == storage.Storage || resp.Kind == storage.StorageV2 { queueClient, err := storageClient.QueuesClient(ctx, *account) From f55c253f35b91c59d9bc4cffe633fb9882aefdfb Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Wed, 8 Jan 2020 17:25:07 +0100 Subject: [PATCH 4/4] r/storage_account: fixing the compilation error --- .../internal/services/storage/resource_arm_storage_account.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/storage/resource_arm_storage_account.go b/azurerm/internal/services/storage/resource_arm_storage_account.go index aacac91fe213..40bee5256a2d 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_account.go +++ b/azurerm/internal/services/storage/resource_arm_storage_account.go @@ -1241,7 +1241,7 @@ func resourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) err // queue is only available for certain tier and kind (as specified below) if resp.Sku == nil { - return fmt.Errorf("Error retrieving Storage Account %q (Resource Group %q): `sku` was nil", name, resourceGrup) + return fmt.Errorf("Error retrieving Storage Account %q (Resource Group %q): `sku` was nil", name, resGroup) } if resp.Sku.Tier == storage.Standard {