Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix function names for azure #145

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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