From 7e578b358d64d5fd6f4673859f6edbcf0d03e074 Mon Sep 17 00:00:00 2001 From: Benjamin Weimer Date: Thu, 5 Dec 2019 10:13:30 +0100 Subject: [PATCH 1/2] iterate through pages returned by list storage accounts to get all storage accounts instead of all storage accounts of the first page --- azurerm/internal/services/storage/helpers.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/azurerm/internal/services/storage/helpers.go b/azurerm/internal/services/storage/helpers.go index f21e1218296f..d607deebb878 100644 --- a/azurerm/internal/services/storage/helpers.go +++ b/azurerm/internal/services/storage/helpers.go @@ -56,7 +56,7 @@ func (client Client) AddToCache(accountName string, props storage.Account) error accountsLock.Lock() defer accountsLock.Unlock() - account, err := client.populateAccountDetails(accountName, props) + account, err := populateAccountDetails(accountName, props) if err != nil { return err } @@ -80,17 +80,23 @@ func (client Client) FindAccount(ctx context.Context, accountName string) (*acco return &existing, nil } - accounts, err := client.AccountsClient.List(ctx) + accountsPage, err := client.AccountsClient.List(ctx) if err != nil { return nil, fmt.Errorf("Error retrieving storage accounts: %+v", err) } - for _, v := range accounts.Values() { + var accounts []storage.Account + for accountsPage.NotDone() { + accounts = append(accounts, accountsPage.Values()...) + accountsPage.NextWithContext(ctx) + } + + for _, v := range accounts { if v.Name == nil { continue } - account, err := client.populateAccountDetails(*v.Name, v) + account, err := populateAccountDetails(*v.Name, v) if err != nil { return nil, err } @@ -105,7 +111,7 @@ func (client Client) FindAccount(ctx context.Context, accountName string) (*acco return nil, nil } -func (client Client) populateAccountDetails(accountName string, props storage.Account) (*accountDetails, error) { +func populateAccountDetails(accountName string, props storage.Account) (*accountDetails, error) { if props.ID == nil { return nil, fmt.Errorf("`id` was nil for Account %q", accountName) } From 6d67fe4fef66955030311c394ebde9070e3b0421 Mon Sep 17 00:00:00 2001 From: Benjamin Weimer Date: Thu, 5 Dec 2019 10:58:07 +0100 Subject: [PATCH 2/2] checking error when moving to next page of storage accounts --- azurerm/internal/services/storage/helpers.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/azurerm/internal/services/storage/helpers.go b/azurerm/internal/services/storage/helpers.go index d607deebb878..eec04f5660d5 100644 --- a/azurerm/internal/services/storage/helpers.go +++ b/azurerm/internal/services/storage/helpers.go @@ -88,7 +88,10 @@ func (client Client) FindAccount(ctx context.Context, accountName string) (*acco var accounts []storage.Account for accountsPage.NotDone() { accounts = append(accounts, accountsPage.Values()...) - accountsPage.NextWithContext(ctx) + err = accountsPage.NextWithContext(ctx) + if err != nil { + return nil, fmt.Errorf("Error retrieving next page of storage accounts: %+v", err) + } } for _, v := range accounts {