Skip to content

Commit

Permalink
Merge pull request #145 from fujiwara/fix/remote-azure
Browse files Browse the repository at this point in the history
Fix function names for azure
  • Loading branch information
fujiwara authored Nov 16, 2023
2 parents cbe77de + 8daeac2 commit 6ab2c4c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tfstate/remote_azurerm.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func readAzureRM(ctx context.Context, resourceGroupName string, accountName stri
for _, gen := range []func() (string, error){
func() (string, error) { return opt.accessKey, nil },
func() (string, error) { return os.Getenv("AZURE_STORAGE_ACCESS_KEY"), nil },
func() (string, error) { return getDefaultAccessKey(ctx, resourceGroupName, accountName, opt) },
func() (string, error) { return getDefaultAzureAccessKey(ctx, resourceGroupName, accountName, opt) },
} {
key, err := gen()
if err != nil {
Expand Down Expand Up @@ -94,7 +94,7 @@ func readAzureRM(ctx context.Context, resourceGroupName string, accountName stri
return r, nil
}

func getDefaultSubscription() (string, error) {
func getDefaultAzureSubscription() (string, error) {
if value, ok := os.LookupEnv("AZURE_SUBSCRIPTION_ID"); ok {
return value, nil
}
Expand All @@ -114,18 +114,21 @@ func getDefaultSubscription() (string, error) {
return subscriptionID, nil
}

func getDefaultAccessKey(ctx context.Context, resourceGroupName string, accountName string, opt azureRMOption) (string, error) {
func getDefaultAzureAccessKey(ctx context.Context, resourceGroupName string, accountName string, opt azureRMOption) (string, error) {
cred, err := getDefaultAzureCredential()
if err != nil {
return "", err
}

subscriptionID, err := getSubscription(opt)
subscriptionID, err := getAzureSubscription(opt)
if err != nil {
return "", err
}

clientFactory, err := armstorage.NewClientFactory(subscriptionID, cred, nil)
if err != nil {
return "", errors.Wrap(err, "failed to create client factory")
}
keys, err := clientFactory.NewAccountsClient().ListKeys(ctx, resourceGroupName, accountName, nil)
if err != nil {
return "", errors.Wrap(err, "failed to list keys")
Expand All @@ -134,12 +137,12 @@ func getDefaultAccessKey(ctx context.Context, resourceGroupName string, accountN
return *keys.Keys[0].Value, nil
}

func getSubscription(opt azureRMOption) (string, error) {
func getAzureSubscription(opt azureRMOption) (string, error) {
if opt.subscriptionID != "" {
return opt.subscriptionID, nil
}

subscriptionID, err := getDefaultSubscription()
subscriptionID, err := getDefaultAzureSubscription()
if err != nil {
return "", errors.Wrap(err, "failed to get default subscription")
}
Expand Down

0 comments on commit 6ab2c4c

Please sign in to comment.