From 85f935dbc47399467fe769ac4f2de5a580ec5f88 Mon Sep 17 00:00:00 2001 From: fujiwara Date: Thu, 16 Nov 2023 10:48:57 +0900 Subject: [PATCH 1/2] rename functions for azure --- tfstate/remote_azurerm.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tfstate/remote_azurerm.go b/tfstate/remote_azurerm.go index 0a5754a..81b855f 100644 --- a/tfstate/remote_azurerm.go +++ b/tfstate/remote_azurerm.go @@ -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 { @@ -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 } @@ -114,13 +114,13 @@ 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 } @@ -134,12 +134,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") } From 8daeac21e87fbfe0c3172ea992717abcaf4e58c5 Mon Sep 17 00:00:00 2001 From: fujiwara Date: Thu, 16 Nov 2023 10:49:17 +0900 Subject: [PATCH 2/2] add err check --- tfstate/remote_azurerm.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tfstate/remote_azurerm.go b/tfstate/remote_azurerm.go index 81b855f..cd820ca 100644 --- a/tfstate/remote_azurerm.go +++ b/tfstate/remote_azurerm.go @@ -126,6 +126,9 @@ func getDefaultAzureAccessKey(ctx context.Context, resourceGroupName string, acc } 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")