From 242c61f0cb2d4efe1672b1915a84ed86830f9040 Mon Sep 17 00:00:00 2001 From: amanenk Date: Fri, 12 Aug 2022 17:52:55 +0300 Subject: [PATCH 1/3] fix: Fixed azure cli authorization --- client/client.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/client.go b/client/client.go index 90678a2a..0002d6eb 100644 --- a/client/client.go +++ b/client/client.go @@ -3,8 +3,8 @@ package client import ( "context" "errors" - "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/azure-sdk-for-go/services/subscription/mgmt/2020-09-01/subscription" // Import all autorest modules @@ -72,6 +72,10 @@ func Configure(logger hclog.Logger, config interface{}) (schema.ClientMeta, diag logger.Info("Trying to authenticate via CLI (azidentity)") var azCred azcore.TokenCredential azCred, err = azidentity.NewAzureCLICredential(nil) + if err == nil { + // check token generation + _, err = azCred.GetToken(context.Background(), policy.TokenRequestOptions{Scopes: []string{"https://management.core.windows.net//.default"}}) + } if err != nil { logger.Info("Trying to authenticate via environment variables (azidentity)") azCred, err = azidentity.NewEnvironmentCredential(nil) From 97826d630c6fea44192181c005a92acc1ba1a05b Mon Sep 17 00:00:00 2001 From: amanenk Date: Fri, 12 Aug 2022 19:01:55 +0300 Subject: [PATCH 2/3] lint --- client/client.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/client.go b/client/client.go index 0002d6eb..7eed5e5e 100644 --- a/client/client.go +++ b/client/client.go @@ -3,10 +3,12 @@ package client import ( "context" "errors" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/azure-sdk-for-go/services/subscription/mgmt/2020-09-01/subscription" + // Import all autorest modules _ "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/azure/auth" From 1136b7fec3a90cfd9ee90284a422b13ef2175323 Mon Sep 17 00:00:00 2001 From: amanenk Date: Fri, 12 Aug 2022 19:34:35 +0300 Subject: [PATCH 3/3] lint --- client/client.go | 1 - 1 file changed, 1 deletion(-) diff --git a/client/client.go b/client/client.go index 7eed5e5e..ebf65bdb 100644 --- a/client/client.go +++ b/client/client.go @@ -8,7 +8,6 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/azure-sdk-for-go/services/subscription/mgmt/2020-09-01/subscription" - // Import all autorest modules _ "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/azure/auth"