Skip to content

Commit d97f7e5

Browse files
pmcatomineystack72
authored andcommitted
provider/azurerm: use configured environment for storage clients (hashicorp#11159)
This fixes storage related operations for all environments outside of the public Azure cloud, tested by deploying all storage resources in a German subscription.
1 parent 061925f commit d97f7e5

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

builtin/providers/azurerm/config.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type ArmClient struct {
3232
clientId string
3333
tenantId string
3434
subscriptionId string
35+
environment azure.Environment
3536

3637
StopContext context.Context
3738

@@ -131,13 +132,6 @@ func setUserAgent(client *autorest.Client) {
131132
// getArmClient is a helper method which returns a fully instantiated
132133
// *ArmClient based on the Config's current settings.
133134
func (c *Config) getArmClient() (*ArmClient, error) {
134-
// client declarations:
135-
client := ArmClient{
136-
clientId: c.ClientID,
137-
tenantId: c.TenantID,
138-
subscriptionId: c.SubscriptionID,
139-
}
140-
141135
// detect cloud from environment
142136
env, envErr := azure.EnvironmentFromName(c.Environment)
143137
if envErr != nil {
@@ -149,6 +143,14 @@ func (c *Config) getArmClient() (*ArmClient, error) {
149143
}
150144
}
151145

146+
// client declarations:
147+
client := ArmClient{
148+
clientId: c.ClientID,
149+
tenantId: c.TenantID,
150+
subscriptionId: c.SubscriptionID,
151+
environment: env,
152+
}
153+
152154
rivieraClient, err := riviera.NewClient(&riviera.AzureResourceManagerCredentials{
153155
ClientID: c.ClientID,
154156
ClientSecret: c.ClientSecret,
@@ -470,7 +472,8 @@ func (armClient *ArmClient) getBlobStorageClientForStorageAccount(resourceGroupN
470472
return nil, false, nil
471473
}
472474

473-
storageClient, err := mainStorage.NewBasicClient(storageAccountName, key)
475+
storageClient, err := mainStorage.NewClient(storageAccountName, key, armClient.environment.StorageEndpointSuffix,
476+
mainStorage.DefaultAPIVersion, true)
474477
if err != nil {
475478
return nil, true, fmt.Errorf("Error creating storage client for storage account %q: %s", storageAccountName, err)
476479
}
@@ -488,7 +491,8 @@ func (armClient *ArmClient) getFileServiceClientForStorageAccount(resourceGroupN
488491
return nil, false, nil
489492
}
490493

491-
storageClient, err := mainStorage.NewBasicClient(storageAccountName, key)
494+
storageClient, err := mainStorage.NewClient(storageAccountName, key, armClient.environment.StorageEndpointSuffix,
495+
mainStorage.DefaultAPIVersion, true)
492496
if err != nil {
493497
return nil, true, fmt.Errorf("Error creating storage client for storage account %q: %s", storageAccountName, err)
494498
}
@@ -506,7 +510,8 @@ func (armClient *ArmClient) getTableServiceClientForStorageAccount(resourceGroup
506510
return nil, false, nil
507511
}
508512

509-
storageClient, err := mainStorage.NewBasicClient(storageAccountName, key)
513+
storageClient, err := mainStorage.NewClient(storageAccountName, key, armClient.environment.StorageEndpointSuffix,
514+
mainStorage.DefaultAPIVersion, true)
510515
if err != nil {
511516
return nil, true, fmt.Errorf("Error creating storage client for storage account %q: %s", storageAccountName, err)
512517
}
@@ -524,7 +529,8 @@ func (armClient *ArmClient) getQueueServiceClientForStorageAccount(resourceGroup
524529
return nil, false, nil
525530
}
526531

527-
storageClient, err := mainStorage.NewBasicClient(storageAccountName, key)
532+
storageClient, err := mainStorage.NewClient(storageAccountName, key, armClient.environment.StorageEndpointSuffix,
533+
mainStorage.DefaultAPIVersion, true)
528534
if err != nil {
529535
return nil, true, fmt.Errorf("Error creating storage client for storage account %q: %s", storageAccountName, err)
530536
}

0 commit comments

Comments
 (0)