Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: always nil check resource group before deref #3986

Merged
merged 4 commits into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions azurerm/resource_arm_storage_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ func resourceArmStorageContainerCreate(d *schema.ResourceData, meta interface{})

resourceGroup, err := storageClient.FindResourceGroup(ctx, accountName)
if err != nil {
return fmt.Errorf("Error locating Resource Group: %s", err)
return fmt.Errorf("Error locating Resource Group for Storage Container %q (Account %s): %s", containerName, accountName, err)
}
if resourceGroup == nil {
return fmt.Errorf("Unable to locate Resource Group for Storage Container %q (Account %s)", containerName, accountName)
}

client, err := storageClient.ContainersClient(ctx, *resourceGroup, accountName)
Expand Down Expand Up @@ -135,10 +138,10 @@ func resourceArmStorageContainerUpdate(d *schema.ResourceData, meta interface{})

resourceGroup, err := storageClient.FindResourceGroup(ctx, id.AccountName)
if err != nil {
return fmt.Errorf("Error locating Resource Group for Storage Account %q: %s", id.AccountName, err)
return fmt.Errorf("Error locating Resource Group for Storage Container %q (Account %s): %s", id.ContainerName, id.AccountName, err)
}
if resourceGroup == nil {
log.Printf("[DEBUG] Unable to locate Resource Group for Storage Account %q - assuming removed & removing from state", id.AccountName)
log.Printf("[DEBUG] Unable to locate Resource Group for Storage Container %q (Account %s)", id.ContainerName, id.AccountName)
katbyte marked this conversation as resolved.
Show resolved Hide resolved
d.SetId("")
return nil
}
Expand Down Expand Up @@ -184,10 +187,10 @@ func resourceArmStorageContainerRead(d *schema.ResourceData, meta interface{}) e

resourceGroup, err := storageClient.FindResourceGroup(ctx, id.AccountName)
if err != nil {
return fmt.Errorf("Error locating Resource Group for Storage Account %q: %s", id.AccountName, err)
return fmt.Errorf("Error locating Resource Group for Storage Container %q (Account %s): %s", id.ContainerName, id.AccountName, err)
}
if resourceGroup == nil {
log.Printf("[DEBUG] Unable to locate Resource Group for Storage Account %q - assuming removed & removing from state", id.AccountName)
log.Printf("[DEBUG] Unable to locate Resource Group for Storage Container %q (Account %s)", id.ContainerName, id.AccountName)
katbyte marked this conversation as resolved.
Show resolved Hide resolved
d.SetId("")
return nil
}
Expand Down Expand Up @@ -239,10 +242,10 @@ func resourceArmStorageContainerDelete(d *schema.ResourceData, meta interface{})

resourceGroup, err := storageClient.FindResourceGroup(ctx, id.AccountName)
if err != nil {
return fmt.Errorf("Error locating Resource Group for Storage Account %q: %s", id.AccountName, err)
return fmt.Errorf("Error locating Resource Group for Storage Container %q (Account %s): %s", id.ContainerName, id.AccountName, err)
}
if resourceGroup == nil {
log.Printf("[DEBUG] Unable to locate Resource Group for Storage Account %q - assuming removed & removing from state", id.AccountName)
log.Printf("[DEBUG] Unable to locate Resource Group for Storage Container %q (Account %s)", id.ContainerName, id.AccountName)
katbyte marked this conversation as resolved.
Show resolved Hide resolved
d.SetId("")
return nil
}
Expand Down
12 changes: 9 additions & 3 deletions azurerm/resource_arm_storage_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@ func testCheckAzureRMStorageContainerExists(resourceName string) resource.TestCh

resourceGroup, err := storageClient.FindResourceGroup(ctx, accountName)
if err != nil {
return fmt.Errorf("Error finding Resource Group: %s", err)
return fmt.Errorf("Error locating Resource Group for Storage Container %q (Account %s): %s", containerName, accountName, err)
}
if resourceGroup == nil {
return fmt.Errorf("Unable to locate Resource Group for Storage Container %q (Account %s) - assuming removed & removing from state", containerName, accountName)
}

client, err := storageClient.ContainersClient(ctx, *resourceGroup, accountName)
Expand Down Expand Up @@ -285,7 +288,10 @@ func testAccARMStorageContainerDisappears(resourceName string) resource.TestChec

resourceGroup, err := storageClient.FindResourceGroup(ctx, accountName)
if err != nil {
return fmt.Errorf("Error finding Resource Group: %s", err)
return fmt.Errorf("Error locating Resource Group for Storage Container %q (Account %s): %s", containerName, accountName, err)
}
if resourceGroup == nil {
return fmt.Errorf("Unable to locate Resource Group for Storage Container %q (Account %s) - assuming removed & removing from state", containerName, accountName)
}

client, err := storageClient.ContainersClient(ctx, *resourceGroup, accountName)
Expand Down Expand Up @@ -315,7 +321,7 @@ func testCheckAzureRMStorageContainerDestroy(s *terraform.State) error {

resourceGroup, err := storageClient.FindResourceGroup(ctx, accountName)
if err != nil {
return fmt.Errorf("Error finding Resource Group: %s", err)
return fmt.Errorf("Error locating Resource Group for Storage Container %q (Account %s): %s", containerName, accountName, err)
}

if resourceGroup == nil {
Expand Down
10 changes: 4 additions & 6 deletions azurerm/resource_arm_storage_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,10 @@ func resourceArmStorageQueueRead(d *schema.ResourceData, meta interface{}) error

resourceGroup, err := storageClient.FindResourceGroup(ctx, id.AccountName)
if err != nil {
return fmt.Errorf("Error locating Resource Group: %s", err)
return fmt.Errorf("Error locating Resource Group for Storage Container %q (Account %s): %s", id.QueueName, id.AccountName, err)
katbyte marked this conversation as resolved.
Show resolved Hide resolved
}

if resourceGroup == nil {
log.Printf("[WARN] Unable to determine Resource Group for Storage Account %q (assuming removed) - removing from state", id.AccountName)
log.Printf("[WARN] Unable to determine Resource Group for Storage Container %q (Account %s)", id.QueueName, id.AccountName)
katbyte marked this conversation as resolved.
Show resolved Hide resolved
d.SetId("")
return nil
}
Expand Down Expand Up @@ -181,11 +180,10 @@ func resourceArmStorageQueueDelete(d *schema.ResourceData, meta interface{}) err

resourceGroup, err := storageClient.FindResourceGroup(ctx, id.AccountName)
if err != nil {
return fmt.Errorf("Error locating Resource Group: %s", err)
return fmt.Errorf("Error locating Resource Group for Storage Container %q (Account %s): %s", id.QueueName, id.AccountName, err)
katbyte marked this conversation as resolved.
Show resolved Hide resolved
}

if resourceGroup == nil {
log.Printf("[WARN] Unable to determine Resource Group for Storage Account %q (assuming removed) - removing from state", id.AccountName)
log.Printf("[WARN] Unable to determine Resource Group for Storage Container %q (Account %s)", id.QueueName, id.AccountName)
katbyte marked this conversation as resolved.
Show resolved Hide resolved
d.SetId("")
return nil
}
Expand Down
17 changes: 10 additions & 7 deletions azurerm/resource_arm_storage_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ func resourceArmStorageShareCreate(d *schema.ResourceData, meta interface{}) err

resourceGroup, err := storageClient.FindResourceGroup(ctx, accountName)
if err != nil {
return fmt.Errorf("Error locating Resource Group: %s", err)
return fmt.Errorf("Error locating Resource Group for Storage Share %q (Account %s): %s", shareName, accountName, err)
}
if resourceGroup == nil {
return fmt.Errorf("Unable to locate Resource Group for Storage Share %q (Account %s) - assuming removed & removing from state", shareName, accountName)
}

client, err := storageClient.FileSharesClient(ctx, *resourceGroup, accountName)
Expand Down Expand Up @@ -175,10 +178,10 @@ func resourceArmStorageShareRead(d *schema.ResourceData, meta interface{}) error

resourceGroup, err := storageClient.FindResourceGroup(ctx, id.AccountName)
if err != nil {
return fmt.Errorf("Error locating Resource Group for Storage Account %q: %s", id.AccountName, err)
return fmt.Errorf("Error locating Resource Group for Storage Share %q (Account %s): %s", id.ShareName, id.AccountName, err)
}
if resourceGroup == nil {
log.Printf("[DEBUG] Unable to locate Resource Group for Storage Account %q - assuming removed & removing from state", id.AccountName)
log.Printf("[WARN] Unable to determine Resource Group for Storage Share %q (Account %s)", id.ShareName, id.AccountName)
katbyte marked this conversation as resolved.
Show resolved Hide resolved
d.SetId("")
return nil
}
Expand Down Expand Up @@ -234,10 +237,10 @@ func resourceArmStorageShareUpdate(d *schema.ResourceData, meta interface{}) err

resourceGroup, err := storageClient.FindResourceGroup(ctx, id.AccountName)
if err != nil {
return fmt.Errorf("Error locating Resource Group for Storage Account %q: %s", id.AccountName, err)
return fmt.Errorf("Error locating Resource Group for Storage Share %q (Account %s): %s", id.ShareName, id.AccountName, err)
}
if resourceGroup == nil {
log.Printf("[DEBUG] Unable to locate Resource Group for Storage Account %q - assuming removed & removing from state", id.AccountName)
log.Printf("[WARN] Unable to determine Resource Group for Storage Share %q (Account %s)", id.ShareName, id.AccountName)
katbyte marked this conversation as resolved.
Show resolved Hide resolved
d.SetId("")
return nil
}
Expand Down Expand Up @@ -297,10 +300,10 @@ func resourceArmStorageShareDelete(d *schema.ResourceData, meta interface{}) err

resourceGroup, err := storageClient.FindResourceGroup(ctx, id.AccountName)
if err != nil {
return fmt.Errorf("Error locating Resource Group for Storage Account %q: %s", id.AccountName, err)
return fmt.Errorf("Error locating Resource Group for Storage Share %q (Account %s): %s", id.ShareName, id.AccountName, err)
}
if resourceGroup == nil {
log.Printf("[DEBUG] Unable to locate Resource Group for Storage Account %q - assuming removed & removing from state", id.AccountName)
log.Printf("[WARN] Unable to determine Resource Group for Storage Share %q (Account %s)", id.ShareName, id.AccountName)
katbyte marked this conversation as resolved.
Show resolved Hide resolved
d.SetId("")
return nil
}
Expand Down
20 changes: 14 additions & 6 deletions azurerm/resource_arm_storage_share_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ func resourceArmStorageShareDirectoryCreate(d *schema.ResourceData, meta interfa

resourceGroup, err := storageClient.FindResourceGroup(ctx, accountName)
if err != nil {
return fmt.Errorf("Error locating Resource Group: %s", err)
return fmt.Errorf("Error locating Resource Group for Storage Share Directory %q (Share %s, Account %s): %s", directoryName, shareName, accountName, err)
}
if resourceGroup == nil {
return fmt.Errorf("Unable to locate Resource Group for Storage Share Directory %q (Share %s, Account %s) ", directoryName, shareName, accountName)
}

client, err := storageClient.FileShareDirectoriesClient(ctx, *resourceGroup, accountName)
Expand Down Expand Up @@ -106,7 +109,12 @@ func resourceArmStorageShareDirectoryUpdate(d *schema.ResourceData, meta interfa

resourceGroup, err := storageClient.FindResourceGroup(ctx, id.AccountName)
if err != nil {
return fmt.Errorf("Error locating Resource Group: %s", err)
return fmt.Errorf("Error locating Resource Group for Storage Share Directory %q (Share %s, Account %s): %s", id.DirectoryName, id.ShareName, id.AccountName, err)
}
if resourceGroup == nil {
log.Printf("[WARN] Unable to determine Resource Group for Storage Share Directory %q (Share %s, Account %s)", id.DirectoryName, id.ShareName, id.AccountName)
katbyte marked this conversation as resolved.
Show resolved Hide resolved
d.SetId("")
return nil
}

client, err := storageClient.FileShareDirectoriesClient(ctx, *resourceGroup, id.AccountName)
Expand All @@ -132,10 +140,10 @@ func resourceArmStorageShareDirectoryRead(d *schema.ResourceData, meta interface

resourceGroup, err := storageClient.FindResourceGroup(ctx, id.AccountName)
if err != nil {
return fmt.Errorf("Error locating Resource Group for Storage Account %q: %s", id.AccountName, err)
return fmt.Errorf("Error locating Resource Group for Storage Share Directory %q (Share %s, Account %s): %s", id.DirectoryName, id.ShareName, id.AccountName, err)
}
if resourceGroup == nil {
log.Printf("[DEBUG] Unable to locate Resource Group for Storage Account %q - assuming removed & removing from state", id.AccountName)
log.Printf("[WARN] Unable to determine Resource Group for Storage Share Directory %q (Share %s, Account %s)", id.DirectoryName, id.ShareName, id.AccountName)
katbyte marked this conversation as resolved.
Show resolved Hide resolved
d.SetId("")
return nil
}
Expand Down Expand Up @@ -172,10 +180,10 @@ func resourceArmStorageShareDirectoryDelete(d *schema.ResourceData, meta interfa

resourceGroup, err := storageClient.FindResourceGroup(ctx, id.AccountName)
if err != nil {
return fmt.Errorf("Error locating Resource Group for Storage Account %q: %s", id.AccountName, err)
return fmt.Errorf("Error locating Resource Group for Storage Share Directory %q (Share %s, Account %s): %s", id.DirectoryName, id.ShareName, id.AccountName, err)
}
if resourceGroup == nil {
log.Printf("[DEBUG] Unable to locate Resource Group for Storage Account %q - assuming removed already", id.AccountName)
log.Printf("[WARN] Unable to determine Resource Group for Storage Share Directory %q (Share %s, Account %s)", id.DirectoryName, id.ShareName, id.AccountName)
katbyte marked this conversation as resolved.
Show resolved Hide resolved
d.SetId("")
return nil
}
Expand Down
7 changes: 5 additions & 2 deletions azurerm/resource_arm_storage_share_directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ func testCheckAzureRMStorageShareDirectoryExists(resourceName string) resource.T

resourceGroup, err := storageClient.FindResourceGroup(ctx, accountName)
if err != nil {
return fmt.Errorf("Error finding Resource Group: %s", err)
return fmt.Errorf("Error locating Resource Group for Storage Share Directory %q (Share %s, Account %s): %s", name, shareName, accountName, err)
}
if resourceGroup == nil {
return fmt.Errorf("Unable to locate Resource Group for Storage Share Directory %q (Share %s, Account %s) ", name, shareName, accountName)
}

client, err := storageClient.FileShareDirectoriesClient(ctx, *resourceGroup, accountName)
Expand Down Expand Up @@ -204,7 +207,7 @@ func testCheckAzureRMStorageShareDirectoryDestroy(s *terraform.State) error {

resourceGroup, err := storageClient.FindResourceGroup(ctx, accountName)
if err != nil {
return fmt.Errorf("Error finding Resource Group: %s", err)
return fmt.Errorf("Error locating Resource Group for Storage Share Directory %q (Share %s, Account %s): %s", name, shareName, accountName, err)
}

// not found, the account's gone
Expand Down
12 changes: 9 additions & 3 deletions azurerm/resource_arm_storage_share_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ func testCheckAzureRMStorageShareExists(resourceName string) resource.TestCheckF

resourceGroup, err := storageClient.FindResourceGroup(ctx, accountName)
if err != nil {
return fmt.Errorf("Error finding Resource Group: %s", err)
return fmt.Errorf("Error locating Resource Group for Storage Share %q (Account %s): %s", shareName, accountName, err)
}
if resourceGroup == nil {
return fmt.Errorf("Unable to locate Resource Group for Storage Share %q (Account %s) - assuming removed & removing from state", shareName, accountName)
}

client, err := storageClient.FileSharesClient(ctx, *resourceGroup, accountName)
Expand Down Expand Up @@ -239,7 +242,10 @@ func testCheckAzureRMStorageShareDisappears(resourceName string) resource.TestCh

resourceGroup, err := storageClient.FindResourceGroup(ctx, accountName)
if err != nil {
return fmt.Errorf("Error finding Resource Group: %s", err)
return fmt.Errorf("Error locating Resource Group for Storage Share %q (Account %s): %s", shareName, accountName, err)
}
if resourceGroup == nil {
return fmt.Errorf("Unable to locate Resource Group for Storage Share %q (Account %s) - assuming removed & removing from state", shareName, accountName)
}

client, err := storageClient.FileSharesClient(ctx, *resourceGroup, accountName)
Expand Down Expand Up @@ -269,7 +275,7 @@ func testCheckAzureRMStorageShareDestroy(s *terraform.State) error {

resourceGroup, err := storageClient.FindResourceGroup(ctx, accountName)
if err != nil {
return fmt.Errorf("Error finding Resource Group: %s", err)
return fmt.Errorf("Error locating Resource Group for Storage Share %q (Account %s): %s", shareName, accountName, err)
}
if resourceGroup == nil {
return nil
Expand Down
18 changes: 11 additions & 7 deletions azurerm/resource_arm_storage_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ func resourceArmStorageTableCreate(d *schema.ResourceData, meta interface{}) err

resourceGroup, err := storageClient.FindResourceGroup(ctx, accountName)
if err != nil {
return fmt.Errorf("Error locating Resource Group: %s", err)
return fmt.Errorf("Error locating Resource Group for Storage Table %q (Account %s): %s", tableName, accountName, err)
}
if resourceGroup == nil {
return fmt.Errorf("Unable to locate Resource Group for Storage Share %q (Account %s) - assuming removed & removing from state", tableName, accountName)
}

client, err := storageClient.TablesClient(ctx, *resourceGroup, accountName)
Expand Down Expand Up @@ -153,11 +156,11 @@ func resourceArmStorageTableRead(d *schema.ResourceData, meta interface{}) error

resourceGroup, err := storageClient.FindResourceGroup(ctx, id.AccountName)
if err != nil {
return fmt.Errorf("Error locating Resource Group: %s", err)
return fmt.Errorf("Error locating Resource Group for Storage Table %q (Account %s): %s", id.TableName, id.AccountName, err)
}

if resourceGroup == nil {
log.Printf("Unable to determine Resource Group for Storage Account %q (assuming removed)", id.AccountName)
log.Printf("Unable to determine Resource Group for Storage Storage Table %q (Account %s)", id.TableName, id.AccountName)
katbyte marked this conversation as resolved.
Show resolved Hide resolved
d.SetId("")
return nil
}
Expand Down Expand Up @@ -205,11 +208,12 @@ func resourceArmStorageTableDelete(d *schema.ResourceData, meta interface{}) err

resourceGroup, err := storageClient.FindResourceGroup(ctx, id.AccountName)
if err != nil {
return fmt.Errorf("Error locating Resource Group: %s", err)
return fmt.Errorf("Error locating Resource Group for Storage Table %q (Account %s): %s", id.TableName, id.AccountName, err)
}

if resourceGroup == nil {
log.Printf("Unable to determine Resource Group for Storage Account %q (assuming removed)", id.AccountName)
log.Printf("Unable to determine Resource Group for Storage Storage Table %q (Account %s)", id.TableName, id.AccountName)
katbyte marked this conversation as resolved.
Show resolved Hide resolved
d.SetId("")
katbyte marked this conversation as resolved.
Show resolved Hide resolved
return nil
}

Expand Down Expand Up @@ -237,11 +241,11 @@ func resourceArmStorageTableUpdate(d *schema.ResourceData, meta interface{}) err

resourceGroup, err := storageClient.FindResourceGroup(ctx, id.AccountName)
if err != nil {
return fmt.Errorf("Error locating Resource Group: %s", err)
return fmt.Errorf("Error locating Resource Group for Storage Table %q (Account %s): %s", id.TableName, id.AccountName, err)
}

if resourceGroup == nil {
log.Printf("Unable to determine Resource Group for Storage Account %q (assuming removed)", id.AccountName)
log.Printf("Unable to determine Resource Group for Storage Storage Table %q (Account %s)", id.TableName, id.AccountName)
katbyte marked this conversation as resolved.
Show resolved Hide resolved
d.SetId("")
return nil
}
Expand Down
19 changes: 14 additions & 5 deletions azurerm/resource_arm_storage_table_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,16 @@ func resourceArmStorageTableEntityCreateUpdate(d *schema.ResourceData, meta inte

resourceGroup, err := storageClient.FindResourceGroup(ctx, accountName)
if err != nil {
return fmt.Errorf("Error locating Resource Group: %s", err)
return fmt.Errorf("Error locating Resource Group for Storage Stable %q (Account %s): %s", tableName, accountName, err)
}
if resourceGroup == nil {
if d.IsNewResource() {
return fmt.Errorf("Unable to locate Resource Group for Storage Table %q (Account %s)", tableName, accountName)
} else {
log.Printf("[DEBUG] Unable to locate Resource Group for Storage Table %q (Account %s) - assuming removed & removing from state", tableName, accountName)
d.SetId("")
return nil
}
}

client, err := storageClient.TableEntityClient(ctx, *resourceGroup, accountName)
Expand Down Expand Up @@ -123,10 +132,10 @@ func resourceArmStorageTableEntityRead(d *schema.ResourceData, meta interface{})

resourceGroup, err := storageClient.FindResourceGroup(ctx, id.AccountName)
if err != nil {
return fmt.Errorf("Error locating Resource Group for Storage Account %q: %s", id.AccountName, err)
return fmt.Errorf("Error locating Resource Group for Storage Table %q (Account %s): %s", id.TableName, id.AccountName, err)
}
if resourceGroup == nil {
log.Printf("[DEBUG] Unable to locate Resource Group for Storage Account %q - assuming removed & removing from state", id.AccountName)
log.Printf("[WARN] Unable to determine Resource Group for Storage Table %q (Account %s)", id.TableName, id.AccountName)
katbyte marked this conversation as resolved.
Show resolved Hide resolved
d.SetId("")
return nil
}
Expand Down Expand Up @@ -169,10 +178,10 @@ func resourceArmStorageTableEntityDelete(d *schema.ResourceData, meta interface{

resourceGroup, err := storageClient.FindResourceGroup(ctx, id.AccountName)
if err != nil {
return fmt.Errorf("Error locating Resource Group for Storage Account %q: %s", id.AccountName, err)
return fmt.Errorf("Error locating Resource Group for Storage Table %q (Account %s): %s", id.TableName, id.AccountName, err)
}
if resourceGroup == nil {
log.Printf("[DEBUG] Unable to locate Resource Group for Storage Account %q - assuming removed already", id.AccountName)
log.Printf("[WARN] Unable to determine Resource Group for Storage Table %q (Account %s)", id.TableName, id.AccountName)
katbyte marked this conversation as resolved.
Show resolved Hide resolved
d.SetId("")
katbyte marked this conversation as resolved.
Show resolved Hide resolved
return nil
}
Expand Down
Loading