Skip to content

Commit 509724a

Browse files
committed
Eliminating SA list when the full ARM ID is available (using GET instead)
1 parent 511903c commit 509724a

File tree

5 files changed

+36
-11
lines changed

5 files changed

+36
-11
lines changed

internal/services/storage/client/helpers.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,32 @@ func (c Client) FindAccount(ctx context.Context, subscriptionIdRaw, accountName
184184
return nil, nil
185185
}
186186

187+
func (c Client) GetAccount(ctx context.Context, id commonids.StorageAccountId) (*AccountDetails, error) {
188+
cacheAccountsLock.Lock()
189+
defer cacheAccountsLock.Unlock()
190+
191+
if existing, ok := storageAccountsCache[id.StorageAccountName]; ok {
192+
return &existing, nil
193+
}
194+
195+
resp, err := c.ResourceManager.StorageAccounts.GetProperties(ctx, id, storageaccounts.DefaultGetPropertiesOperationOptions())
196+
if err != nil {
197+
return nil, fmt.Errorf("retrieving %s: %v", id, err)
198+
}
199+
200+
if resp.Model == nil {
201+
return nil, fmt.Errorf("unexpected null model of %s", id)
202+
}
203+
204+
account, err := populateAccountDetails(id, *resp.Model)
205+
if err != nil {
206+
return nil, fmt.Errorf("populating details for %s: %+v", id, err)
207+
}
208+
209+
storageAccountsCache[id.StorageAccountName] = *account
210+
return account, nil
211+
}
212+
187213
func populateAccountDetails(accountId commonids.StorageAccountId, account storageaccounts.StorageAccount) (*AccountDetails, error) {
188214
out := AccountDetails{
189215
Kind: pointer.From(account.Kind),

internal/services/storage/storage_account_resource.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ func resourceStorageAccountCreate(d *pluginsdk.ResourceData, meta interface{}) e
14921492
// Start of Data Plane access - this entire block can be removed for 5.0, as the data_plane_available flag becomes redundant at that time.
14931493
if !features.FivePointOhBeta() && dataPlaneAvailable {
14941494
dataPlaneClient := meta.(*clients.Client).Storage
1495-
dataPlaneAccount, err := storageUtils.FindAccount(ctx, id.SubscriptionId, id.StorageAccountName)
1495+
dataPlaneAccount, err := storageUtils.GetAccount(ctx, id)
14961496
if err != nil {
14971497
return fmt.Errorf("retrieving %s: %+v", id, err)
14981498
}
@@ -1925,7 +1925,7 @@ func resourceStorageAccountUpdate(d *pluginsdk.ResourceData, meta interface{}) e
19251925
return fmt.Errorf("`queue_properties` aren't supported for account kind %q in sku tier %q", accountKind, accountTier)
19261926
}
19271927

1928-
account, err := dataPlaneClient.FindAccount(ctx, id.SubscriptionId, id.StorageAccountName)
1928+
account, err := dataPlaneClient.GetAccount(ctx, *id)
19291929
if err != nil {
19301930
return fmt.Errorf("retrieving %s: %+v", *id, err)
19311931
}
@@ -1953,7 +1953,7 @@ func resourceStorageAccountUpdate(d *pluginsdk.ResourceData, meta interface{}) e
19531953
return fmt.Errorf("`static_website` aren't supported for account kind %q in sku tier %q", accountKind, accountTier)
19541954
}
19551955

1956-
account, err := dataPlaneClient.FindAccount(ctx, id.SubscriptionId, id.StorageAccountName)
1956+
account, err := dataPlaneClient.GetAccount(ctx, *id)
19571957
if err != nil {
19581958
return fmt.Errorf("retrieving %s: %+v", *id, err)
19591959
}
@@ -2030,7 +2030,7 @@ func resourceStorageAccountRead(d *pluginsdk.ResourceData, meta interface{}) err
20302030
}
20312031

20322032
// we then need to find the storage account
2033-
account, err := storageUtils.FindAccount(ctx, id.SubscriptionId, id.StorageAccountName)
2033+
account, err := storageUtils.GetAccount(ctx, *id)
20342034
if err != nil {
20352035
return fmt.Errorf("retrieving %s: %+v", *id, err)
20362036
}

internal/services/storage/storage_account_static_website_data_plane_resource.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (a AccountStaticWebsiteResource) Create() sdk.ResourceFunc {
103103
}
104104
accountReplicationType := accountReplicationTypeParts[1]
105105

106-
accountDetails, err := storageClient.FindAccount(ctx, accountID.SubscriptionId, accountID.StorageAccountName)
106+
accountDetails, err := storageClient.GetAccount(ctx, *accountID)
107107
if err != nil {
108108
return err
109109
}
@@ -157,7 +157,7 @@ func (a AccountStaticWebsiteResource) Read() sdk.ResourceFunc {
157157

158158
state.StorageAccountId = id.ID()
159159

160-
accountDetails, err := storageClient.FindAccount(ctx, id.SubscriptionId, id.StorageAccountName)
160+
accountDetails, err := storageClient.GetAccount(ctx, *id)
161161
if err != nil {
162162
return metadata.MarkAsGone(id)
163163
}
@@ -193,7 +193,7 @@ func (a AccountStaticWebsiteResource) Delete() sdk.ResourceFunc {
193193
return err
194194
}
195195

196-
accountDetails, err := storageClient.FindAccount(ctx, id.SubscriptionId, id.StorageAccountName)
196+
accountDetails, err := storageClient.GetAccount(ctx, *id)
197197
if err != nil {
198198
return nil // lint:ignore nilerr If we don't find the account we can safely assume we don't need to remove the website since it must already be deleted
199199
}
@@ -233,7 +233,7 @@ func (a AccountStaticWebsiteResource) Update() sdk.ResourceFunc {
233233
return err
234234
}
235235

236-
accountDetails, err := storageClient.FindAccount(ctx, id.SubscriptionId, id.StorageAccountName)
236+
accountDetails, err := storageClient.GetAccount(ctx, *id)
237237
if err != nil {
238238
return err
239239
}

internal/services/storage/storage_account_static_website_data_plane_resource_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (r AccountStaticWebsiteResource) Exists(ctx context.Context, client *client
105105
return nil, err
106106
}
107107

108-
accountDetails, err := client.Storage.FindAccount(ctx, id.SubscriptionId, id.StorageAccountName)
108+
accountDetails, err := client.Storage.GetAccount(ctx, *id)
109109
if err != nil {
110110
return nil, fmt.Errorf("retrieving %s: %+v", *id, err)
111111
}

internal/services/storage/storage_containers_data_source.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ func (r storageContainersDataSource) Read() sdk.ResourceFunc {
8989

9090
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
9191
blobContainersClient := metadata.Client.Storage.ResourceManager.BlobContainers
92-
subscriptionId := metadata.Client.Account.SubscriptionId
9392

9493
var plan storageContainersDataSourceModel
9594
if err := metadata.Decode(&plan); err != nil {
@@ -101,7 +100,7 @@ func (r storageContainersDataSource) Read() sdk.ResourceFunc {
101100
return err
102101
}
103102

104-
account, err := metadata.Client.Storage.FindAccount(ctx, subscriptionId, id.StorageAccountName)
103+
account, err := metadata.Client.Storage.GetAccount(ctx, *id)
105104
if err != nil {
106105
return fmt.Errorf("retrieving Storage Account %q: %v", id.StorageAccountName, err)
107106
}

0 commit comments

Comments
 (0)