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

Bicep Insert resource command fails fetching resource #6762

Closed
kevball2 opened this issue May 3, 2022 · 21 comments · Fixed by #6808
Closed

Bicep Insert resource command fails fetching resource #6762

kevball2 opened this issue May 3, 2022 · 21 comments · Fixed by #6808

Comments

@kevball2
Copy link

kevball2 commented May 3, 2022

Bicep version
run bicep --version via the Bicep CLI, az bicep version via the AZ CLI or via VS code by navigating to the extensions tab and searching for Bicep
Bicep CLI version 0.4.1272 (a69022d) PS
Bicep plugin - v0.6.1
powershell - 7.2.3
AZ CLI - 2.36.0
Describe the bug
When attempting to insert a new resource into a bicep file I receive the attached error.

To Reproduce
ctrl + shift + P to open vscode pallet - run Bicep: Insert Resource
Choose any resource ID and attempt to add. Error occurs

Additional context
See attached screen shot of error
attempted in multiple bicep files with 2 different resources.
I confirmed I was logged in az login as well as logged in with powershell
image

@ghost ghost added the Needs: Triage 🔍 label May 3, 2022
@kevball2
Copy link
Author

kevball2 commented May 4, 2022

Rolling back the VScode extension to 0.5.6 I can insert resources again successfully.

@brwilkinson
Copy link
Collaborator

@kevball2

Are you using anything in your bicepconfig.json file for the credentialPrecedence?

https://docs.microsoft.com/en-us/azure/azure-resource-manager/bicep/bicep-config#credential-precedence

e.g.

  "cloud": {
    "currentProfile": "AzureCloud",
    "credentialPrecedence": [
      // "AzureCLI"
      "AzurePowerShell"
    ]
  }

It can also be confusing if the terminal is the powershell integrated terminal or the standard terminal, to pickup the fresh credentials, also the difference between powershell 7 versus Windows PowerShell for the login.

@kevball2
Copy link
Author

kevball2 commented May 5, 2022

@brwilkinson I do not have precedence set in the config file for this project.

@brwilkinson
Copy link
Collaborator

Okay @kevball2 without that set it's very hard to track exactly which cred will be used.

Since it chains on the list below. The issues comes, that if you were logged into one of these, however the credential is not fresh, it tries to use it and fails.

To avoid this either:

a) set the credentialPrecedence to the one you are freshly logged into
b) start at the top and either log in or log our until you get to the one you actually want to use daily.

The available credential types are:

  • AzureCLI
  • AzurePowerShell
  • Environment
  • ManagedIdentity
  • VisualStudio
  • VisualStudioCode

Of course, if you are not logged in and you are still seeing issue, we can look further into this one for you, can collect logs from you, however this does tend to be a common side effect, of having so many options available to login with.

@kevball2
Copy link
Author

kevball2 commented May 5, 2022

No luck unfortunately @brwilkinson,

  • Added the Credential precedence settings you provided
  • restarted my machine to confirm no extra logins
  • launched VsCode
  • ran Insert command which failed with the same error

@brwilkinson
Copy link
Collaborator

Thanks @kevball2

I have also been able to repro this scenario.

extension version

[email protected]

    "credentialPrecedence": [
      "AzurePowerShell"
    ]

2022-05-05T21:30:59.941Z info: Current log level: debug.
2022-05-05T21:30:59.950Z info: Launching Bicep language service...
2022-05-05T21:30:59.950Z info: Acquiring dotnet runtime...
2022-05-05T21:31:00.023Z debug: Found dotnet command at 'c:\Users\benwilk\AppData\Roaming\Code - Insiders\User\globalStorage\ms-dotnettools.vscode-dotnet-runtime\.dotnet\6.0.4\dotnet.exe'.
2022-05-05T21:31:00.023Z debug: Found language server at 'c:\Users\benwilk\.vscode-insiders\extensions\ms-azuretools.vscode-bicep-0.6.1\bicepLanguageServer\Bicep.LangServer.dll'.
2022-05-05T21:31:00.034Z info: Bicep language service started.
2022-05-05T21:31:10.142Z info: Bicep language service ready.
[Info  - 2:31:10 PM] Running on processId 44668

# First try in unsaved file

TRACE: Building semantic model for untitled:Untitled-1
TRACE: Azure-Identity: [Informational] AzureCliCredential.GetToken invoked. Scopes: [ https://management.azure.com/.default/.default ] ParentRequestId: 9680fbea-48d2-443b-a24c-2d2af3208dc4
TRACE: Azure-Identity: [Informational] AzureCliCredential.GetToken was unable to retrieve an access token. Scopes: [ https://management.azure.com/.default/.default ] ParentRequestId: 9680fbea-48d2-443b-a24c-2d2af3208dc4 Exception: Azure.Identity.CredentialUnavailableException (0x80131500): Please run 'az login' to set up account
TRACE: Azure-Identity: [Informational] AzurePowerShellCredential.GetToken invoked. Scopes: [ https://management.azure.com/.default/.default ] ParentRequestId: 9680fbea-48d2-443b-a24c-2d2af3208dc4
TRACE: Azure-Identity: [Informational] AzurePowerShellCredential.GetToken was unable to retrieve an access token. Scopes: [ https://management.azure.com/.default/.default ] ParentRequestId: 9680fbea-48d2-443b-a24c-2d2af3208dc4 Exception: Azure.Identity.CredentialUnavailableException (0x80131500): PowerShell is not installed.

# Second try with a file in the same path as by bicepconfig.json to ensure it was picking up my preference for AzurePowerShell

TRACE: Building semantic model for file:https:///d:/Repos/scapim-adf/ADF/bicep/test.bicep
TRACE: Azure-Identity: [Informational] AzurePowerShellCredential.GetToken invoked. Scopes: [ https://management.azure.com/.default/.default ] ParentRequestId: 42ecf546-d4dc-4fa7-ad14-c0c291be942e
TRACE: Azure-Identity: [Informational] AzurePowerShellCredential.GetToken was unable to retrieve an access token. Scopes: [ https://management.azure.com/.default/.default ] ParentRequestId: 42ecf546-d4dc-4fa7-ad14-c0c291be942e Exception: Azure.Identity.CredentialUnavailableException (0x80131500): PowerShell is not installed.

Also tested with this

    "credentialPrecedence": [
      "AzureCLI",
      "AzurePowerShell"
    ]
TRACE: Building semantic model for file:https:///d:/Repos/scapim-adf/ADF/bicep/test.bicep
TRACE: Azure-Identity: [Informational] AzureCliCredential.GetToken invoked. Scopes: [ https://management.azure.com/.default/.default ] ParentRequestId: 813d93f0-363e-4514-b468-77235f2dd31f
TRACE: Azure-Identity: [Informational] AzureCliCredential.GetToken was unable to retrieve an access token. Scopes: [ https://management.azure.com/.default/.default ] ParentRequestId: 813d93f0-363e-4514-b468-77235f2dd31f Exception: Azure.Identity.CredentialUnavailableException (0x80131500): Please run 'az login' to set up account
TRACE: Azure-Identity: [Informational] AzurePowerShellCredential.GetToken invoked. Scopes: [ https://management.azure.com/.default/.default ] ParentRequestId: 813d93f0-363e-4514-b468-77235f2dd31f
TRACE: Azure-Identity: [Informational] AzurePowerShellCredential.GetToken was unable to retrieve an access token. Scopes: [ https://management.azure.com/.default/.default ] ParentRequestId: 813d93f0-363e-4514-b468-77235f2dd31f Exception: Azure.Identity.CredentialUnavailableException (0x80131500): PowerShell is not installed.

Also tested with

    "credentialPrecedence": [
      "VisualStudioCode"
    ]
TRACE: Building semantic model for file:https:///d:/Repos/scapim-adf/ADF/bicep/test.bicep
TRACE: Azure-Identity: [Informational] VisualStudioCodeCredential.GetToken invoked. Scopes: [ https://management.azure.com/.default/.default ] ParentRequestId: 8ab3b2b3-6f1d-49c5-a46b-82e122ecb292
TRACE: Azure-Identity: [Informational] False MSAL 4.39.0.0 MSAL.NetCore .NET 6.0.4 Microsoft Windows 10.0.22616 [05/05 21:45:24.90 - ca71c1d1-1c1d-41a0-8328-e9992078f641] MSAL MSAL.NetCore with assembly version '4.39.0.0'. CorrelationId(ca71c1d1-1c1d-41a0-8328-e9992078f641)
TRACE: Azure-Identity: [Informational] False MSAL 4.39.0.0 MSAL.NetCore .NET 6.0.4 Microsoft Windows 10.0.22616 [05/05 21:45:24.96 - ca71c1d1-1c1d-41a0-8328-e9992078f641] Using 1 scopes for acquire token by refresh token request
TRACE: Azure-Identity: [Informational] False MSAL 4.39.0.0 MSAL.NetCore .NET 6.0.4 Microsoft Windows 10.0.22616 [05/05 21:45:24.97 - ca71c1d1-1c1d-41a0-8328-e9992078f641] 
=== Request Data ===
Authority Provided? - True
Scopes - https://management.azure.com/.default/.default
Extra Query Params Keys (space separated) - 
ApiId - AcquireTokenByRefreshToken
IsConfidentialClient - False
SendX5C - False
LoginHint ? False
IsBrokerConfigured - False
HomeAccountId - False
CorrelationId - ca71c1d1-1c1d-41a0-8328-e9992078f641
UserAssertion set: False
LongRunningOboCacheKey set: False

TRACE: Azure-Identity: [Informational] False MSAL 4.39.0.0 MSAL.NetCore .NET 6.0.4 Microsoft Windows 10.0.22616 [05/05 21:45:24.97 - ca71c1d1-1c1d-41a0-8328-e9992078f641] === Token Acquisition (ByRefreshTokenRequest) started:
	 Scopes: https://management.azure.com/.default/.default
	Authority Host: login.microsoftonline.com
TRACE: Azure-Identity: [Informational] False MSAL 4.39.0.0 MSAL.NetCore .NET 6.0.4 Microsoft Windows 10.0.22616 [05/05 21:45:24.97 - ca71c1d1-1c1d-41a0-8328-e9992078f641] [Region discovery] Not using a regional authority. 
TRACE: Azure-Identity: [Informational] False MSAL 4.39.0.0 MSAL.NetCore .NET 6.0.4 Microsoft Windows 10.0.22616 [05/05 21:45:24.98 - ca71c1d1-1c1d-41a0-8328-e9992078f641] Fetching instance discovery from the network from host login.microsoftonline.com. 
TRACE: Azure-Core: [Informational] Request [07dbbda4-fd5e-443a-81f6-c02a96d60e87] GET https://login.microsoftonline.com/common/discovery/instance?api-version=1.1&authorization_endpoint=REDACTED
client assembly: Azure.Identity
TRACE: Azure-Core: [Informational] Response [07dbbda4-fd5e-443a-81f6-c02a96d60e87] 200 OK (00.6s)

TRACE: Azure-Identity: [Informational] False MSAL 4.39.0.0 MSAL.NetCore .NET 6.0.4 Microsoft Windows 10.0.22616 [05/05 21:45:25.70 - ca71c1d1-1c1d-41a0-8328-e9992078f641] Authority validation enabled? True. 
TRACE: Azure-Identity: [Informational] False MSAL 4.39.0.0 MSAL.NetCore .NET 6.0.4 Microsoft Windows 10.0.22616 [05/05 21:45:25.70 - ca71c1d1-1c1d-41a0-8328-e9992078f641] Authority validation - is known env? True. 
TRACE: Azure-Core: [Informational] Request [f0eb7af3-bfb0-4675-8042-f27a2c2648a4] POST https://login.microsoftonline.com/organizations/oauth2/v2.0/token
client assembly: Azure.Identity
TRACE: Azure-Core: [Warning] Error response [f0eb7af3-bfb0-4675-8042-f27a2c2648a4] 400 Bad Request (00.8s)

TRACE: Azure-Identity: [Informational] False MSAL 4.39.0.0 MSAL.NetCore .NET 6.0.4 Microsoft Windows 10.0.22616 [05/05 21:45:26.57 - ca71c1d1-1c1d-41a0-8328-e9992078f641] Response status code does not indicate success: 400 (BadRequest). 
TRACE: Azure-Identity: [Warning] False MSAL 4.39.0.0 MSAL.NetCore .NET 6.0.4 Microsoft Windows 10.0.22616 [05/05 21:45:26.57 - ca71c1d1-1c1d-41a0-8328-e9992078f641] Request retry failed.
TRACE: Azure-Identity: [Informational] False MSAL 4.39.0.0 MSAL.NetCore .NET 6.0.4 Microsoft Windows 10.0.22616 [05/05 21:45:26.58 - ca71c1d1-1c1d-41a0-8328-e9992078f641] HttpStatusCode: 400: BadRequest
TRACE: Azure-Identity: [Error] False MSAL 4.39.0.0 MSAL.NetCore .NET 6.0.4 Microsoft Windows 10.0.22616 [05/05 21:45:26.58 - ca71c1d1-1c1d-41a0-8328-e9992078f641] Exception type: Microsoft.Identity.Client.MsalUiRequiredException
, ErrorCode: invalid_grant
HTTP StatusCode 400
CorrelationId ca71c1d1-1c1d-41a0-8328-e9992078f641

TRACE: Azure-Identity: [Error] False MSAL 4.39.0.0 MSAL.NetCore .NET 6.0.4 Microsoft Windows 10.0.22616 [05/05 21:45:26.84 - ca71c1d1-1c1d-41a0-8328-e9992078f641] Exception type: Microsoft.Identity.Client.MsalUiRequiredException
, ErrorCode: invalid_grant
HTTP StatusCode 400
CorrelationId ca71c1d1-1c1d-41a0-8328-e9992078f641

   at Microsoft.Identity.Client.OAuth2.OAuth2Client.ThrowServerException(HttpResponse response, RequestContext requestContext)
   at Microsoft.Identity.Client.OAuth2.OAuth2Client.CreateResponse[T](HttpResponse response, RequestContext requestContext)
   at Microsoft.Identity.Client.OAuth2.OAuth2Client.ExecuteRequestAsync[T](Uri endPoint, HttpMethod method, RequestContext requestContext, Boolean expectErrorsOn200OK, Boolean addCommonHeaders)
   at Microsoft.Identity.Client.OAuth2.OAuth2Client.GetTokenAsync(Uri endPoint, RequestContext requestContext, Boolean addCommonHeaders)
   at Microsoft.Identity.Client.OAuth2.TokenClient.SendHttpAndClearTelemetryAsync(String tokenEndpoint, ICoreLogger logger)
   at Microsoft.Identity.Client.OAuth2.TokenClient.SendHttpAndClearTelemetryAsync(String tokenEndpoint, ICoreLogger logger)
   at Microsoft.Identity.Client.OAuth2.TokenClient.SendTokenRequestAsync(IDictionary`2 additionalBodyParameters, String scopeOverride, String tokenEndpointOverride, CancellationToken cancellationToken)
   at Microsoft.Identity.Client.Internal.Requests.ByRefreshTokenRequest.ExecuteAsync(CancellationToken cancellationToken)
   at Microsoft.Identity.Client.Internal.Requests.RequestBase.RunAsync(CancellationToken cancellationToken)
TRACE: Azure-Identity: [Informational] VisualStudioCodeCredential.GetToken was unable to retrieve an access token. Scopes: [ https://management.azure.com/.default/.default ] ParentRequestId: 8ab3b2b3-6f1d-49c5-a46b-82e122ecb292 Exception: Azure.Identity.CredentialUnavailableException (0x80131500): VisualStudioCodeCredential authentication unavailable. Token acquisition failed. Ensure that you have authenticated in VSCode Azure Account. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/vscodecredential/troubleshoot
 ---> Microsoft.Identity.Client.MsalUiRequiredException (0x80131500): AADSTS700082: The refresh token has expired due to inactivity. The token was issued on 2022-01-09T01:08:31.6083815Z and was inactive for 100.00:00:00.
Trace ID: da8bf06d-62c5-4b32-b521-3fc32e720000
Correlation ID: ca71c1d1-1c1d-41a0-8328-e9992078f641
Timestamp: 2022-05-05 21:45:26Z

This was all directly after updating the extension version to the latest.

it was running in

[Info - 2:31:10 PM] Running on processId 44668

gps -id 44668 | select *

Name                       : dotnet
Id                         : 44668
Path                       : c:\Users\benwilk\AppData\Roaming\Code - Insiders\User\globalStorage\ms-dotnettools.vscode-dotnet-runtime\.dotnet\6.0.4\dotnet.exe
CommandLine                : "c:\Users\benwilk\AppData\Roaming\Code - Insiders\User\globalStorage\ms-dotnettools.vscode-dotnet-runtime\.dotnet\6.0.4\dotnet.exe" c:\Users\benwilk\.vscode-insiders\extensions\ms-azuretools.vscode-bicep-0.6.1\bicepLanguageServer\Bicep.LangServer.dll
                             --pipe=\\.\pipe\vscode-jsonrpc-de1accbc315680583e21a5a9640bf935cf43442eab-sock --clientProcessId=22256
Parent                     : System.Diagnostics.Process (Code - Insiders)
Company                    : Microsoft Corporation
CPU                        : 6.390625
ProcessName                : dotnet

so I figured I would try restarting VSCode all together to test/confirm.

Tested again with PowerShell same error.

Azure.Identity.CredentialUnavailableException (0x80131500): PowerShell is not installed

2022-05-05T21:49:15.492Z info: Current log level: debug.
2022-05-05T21:49:15.497Z info: Launching Bicep language service...
2022-05-05T21:49:15.497Z info: Acquiring dotnet runtime...
2022-05-05T21:49:15.603Z debug: Found dotnet command at 'c:\Users\benwilk\AppData\Roaming\Code - Insiders\User\globalStorage\ms-dotnettools.vscode-dotnet-runtime\.dotnet\6.0.4\dotnet.exe'.
2022-05-05T21:49:15.603Z debug: Found language server at 'c:\Users\benwilk\.vscode-insiders\extensions\ms-azuretools.vscode-bicep-0.6.1\bicepLanguageServer\Bicep.LangServer.dll'.
2022-05-05T21:49:15.605Z info: Bicep language service started.
2022-05-05T21:49:27.829Z info: Bicep language service ready.
[Info  - 2:49:27 PM] Running on processId 21208
TRACE: Building semantic model for file:https:///d:/Repos/scapim-adf/ADF/bicep/test.bicep
TRACE: Azure-Identity: [Informational] AzurePowerShellCredential.GetToken invoked. Scopes: [ https://management.azure.com/.default/.default ] ParentRequestId: 8594f09b-98d0-42ef-abff-ed1fa45bc852
TRACE: Azure-Identity: [Informational] AzurePowerShellCredential.GetToken was unable to retrieve an access token. Scopes: [ https://management.azure.com/.default/.default ] ParentRequestId: 8594f09b-98d0-42ef-abff-ed1fa45bc852 Exception: Azure.Identity.CredentialUnavailableException (0x80131500): PowerShell is not installed.

@pb111111
Copy link

pb111111 commented May 6, 2022

Our build pipelines began to fail this week as Bicep v0.6.1 was rolled out on the MS-Hosted Build Images (ubuntu-20.04) in Azure Pipelines. We make the use of Template Specs and started getting this error with Bicep v0.6.1. We were able to work around the issue by overriding the (now-default) Bicep version with the previous version (v0.5.6).

Error message for reference:
The ChainedTokenCredential failed to retrieve a token from the included credentials. - Please run 'az login' to set up account - PowerShell is not installed.

@janegilring
Copy link

+1

I`m authenticated using the same user account in Azure CLI, Azure PowerShell, and the VS Code extension. I can perform actions such as list resources using all 3 tools, so authentication should be fine. Regardless, the error is the same when trying to use the "Bicep: Insert resource" function. This is reproed on both MacOS and Windows 11.

Would trying MSAL instead of ADAL be worth a shot?

image

I only see this option on the Windows machine though, so not sure what is used on MacOS.

@alex-frankel alex-frankel added this to the v0.7 milestone May 9, 2022
@anthony-c-martin
Copy link
Member

@brwilkinson since you're able to repro this, I'd like to rule out the Azure.Identity package upgrade as the cause of this issue. Would you mind testing with the VSIX extensions attached to the following releases:

If "before" succeeds and "after" fails, then I think it's likely to be related.

@brwilkinson
Copy link
Collaborator

brwilkinson commented May 9, 2022

@anthony-c-martin Unfortunately both of these versions are still working for me.

Both of these work.

vsix: [email protected]
vsix: [email protected]

2022-05-09T17:58:03.624Z info: Current log level: debug.
2022-05-09T17:58:03.633Z info: Launching Bicep language service...
2022-05-09T17:58:03.633Z info: Acquiring dotnet runtime...
2022-05-09T17:58:03.681Z debug: Found dotnet command at 'c:\Users\benwilk\AppData\Roaming\Code\User\globalStorage\ms-dotnettools.vscode-dotnet-runtime\.dotnet\6.0.4\dotnet.exe'.
2022-05-09T17:58:03.682Z debug: Found language server at 'c:\Users\benwilk\.vscode\extensions\ms-azuretools.vscode-bicep-0.5.1-gba04d28b11\bicepLanguageServer\Bicep.LangServer.dll'.
2022-05-09T17:58:03.692Z info: Bicep language service started.
2022-05-09T17:58:13.932Z info: Bicep language service ready.
[Info  - 10:58:14 AM] Running on processId 65876
TRACE: Building semantic model for file:https:///d:/Repos/scapim-ps/aaworking/test.bicep
TRACE: Azure-Identity: [Informational] AzurePowerShellCredential.GetToken invoked. Scopes: [ https://management.azure.com/.default ] ParentRequestId: 8928dbcf-0f9b-4418-876e-2d9d859adaac
TRACE: Azure-Identity: [Informational] AzurePowerShellCredential.GetToken succeeded. Scopes: [ https://management.azure.com/.default ] ParentRequestId: 8928dbcf-0f9b-4418-876e-2d9d859adaac ExpiresOn: 2022-05-09T19:20:33.0000000+00:00
TRACE: Azure-Core: [Informational] Request [8928dbcf-0f9b-4418-876e-2d9d859adaac] GET https://management.azure.com/subscriptions/b8f402aa-20f7-4888-b45c-3cf086dad9c3/providers/Microsoft.Storage?api-version=2021-04-01
client assembly: Azure.ResourceManager
TRACE: Azure-Core: [Informational] Response [8928dbcf-0f9b-4418-876e-2d9d859adaac] 200 OK (00.7s)

TRACE: Azure-Core: [Informational] Request [1fc628ca-c273-4854-a8a9-5f52bdd63e03] GET https://management.azure.com/subscriptions/b8f402aa-20f7-4888-b45c-3cf086dad9c3/resourceGroups/ACU1-BRW-PST-RG-P0/providers/Microsoft.Storage/storageAccounts/acu1brwpstp0sadiag?api-version=2021-09-01
client assembly: Azure.ResourceManager
TRACE: Azure-Core: [Informational] Response [1fc628ca-c273-4854-a8a9-5f52bdd63e03] 200 OK (00.4s)

TRACE: Building semantic model for inmemory:https:///generated.bicep
TRACE: Building semantic model for inmemory:https:///generated.bicep
TRACE: Building semantic model for inmemory:https:///generated.bicep
TRACE: Building semantic model for inmemory:https:///generated.bicep
TRACE: Building semantic model for file:https:///d:/Repos/scapim-ps/aaworking/test.bicep
TRACE: Building semantic model for file:https:///d:/Repos/scapim-ps/aaworking/test.bicep
also works

vsix: [email protected]

2022-05-09T18:04:15.048Z info: Current log level: debug.
2022-05-09T18:04:15.052Z info: Launching Bicep language service...
2022-05-09T18:04:15.052Z info: Acquiring dotnet runtime...
2022-05-09T18:04:15.087Z debug: Found dotnet command at 'c:\Users\benwilk\AppData\Roaming\Code\User\globalStorage\ms-dotnettools.vscode-dotnet-runtime\.dotnet\6.0.4\dotnet.exe'.
2022-05-09T18:04:15.088Z debug: Found language server at 'c:\Users\benwilk\.vscode\extensions\ms-azuretools.vscode-bicep-0.5.2-g02d9b31216\bicepLanguageServer\Bicep.LangServer.dll'.
2022-05-09T18:04:15.095Z info: Bicep language service started.
2022-05-09T18:04:25.857Z info: Bicep language service ready.
[Info  - 11:04:25 AM] Running on processId 56068
TRACE: Building semantic model for file:https:///d:/Repos/scapim-ps/aaworking/test.bicep
TRACE: Azure-Identity: [Informational] AzurePowerShellCredential.GetToken invoked. Scopes: [ https://management.azure.com/.default ] ParentRequestId: 46b1d6ea-48af-4587-af53-c6f7794e77b7
TRACE: Azure-Identity: [Informational] AzurePowerShellCredential.GetToken succeeded. Scopes: [ https://management.azure.com/.default ] ParentRequestId: 46b1d6ea-48af-4587-af53-c6f7794e77b7 ExpiresOn: 2022-05-09T19:20:33.0000000+00:00
TRACE: Azure-Core: [Informational] Request [46b1d6ea-48af-4587-af53-c6f7794e77b7] GET https://management.azure.com/subscriptions/b8f402aa-20f7-4888-b45c-3cf086dad9c3/providers/Microsoft.Storage?api-version=2021-04-01
client assembly: Azure.ResourceManager
TRACE: Azure-Core: [Informational] Response [46b1d6ea-48af-4587-af53-c6f7794e77b7] 200 OK (00.6s)

TRACE: Azure-Core: [Informational] Request [a9810bd2-d55e-45f3-9596-5c8e55225dd0] GET https://management.azure.com/subscriptions/b8f402aa-20f7-4888-b45c-3cf086dad9c3/resourceGroups/ACU1-BRW-PST-RG-P0/providers/Microsoft.Storage/storageAccounts/acu1brwpstp0sadiag?api-version=2021-09-01
client assembly: Azure.ResourceManager
TRACE: Azure-Core: [Informational] Response [a9810bd2-d55e-45f3-9596-5c8e55225dd0] 200 OK (00.2s)

TRACE: Building semantic model for inmemory:https:///generated.bicep
TRACE: Building semantic model for inmemory:https:///generated.bicep
TRACE: Building semantic model for inmemory:https:///generated.bicep
TRACE: Building semantic model for inmemory:https:///generated.bicep
TRACE: Building semantic model for file:https:///d:/Repos/scapim-ps/aaworking/test.bicep
Moving back to latest does not work.

[email protected]

2022-05-09T18:08:38.003Z info: Current log level: debug.
2022-05-09T18:08:38.006Z info: Launching Bicep language service...
2022-05-09T18:08:38.006Z info: Acquiring dotnet runtime...
2022-05-09T18:08:38.026Z debug: Found dotnet command at 'c:\Users\benwilk\AppData\Roaming\Code\User\globalStorage\ms-dotnettools.vscode-dotnet-runtime\.dotnet\6.0.4\dotnet.exe'.
2022-05-09T18:08:38.026Z debug: Found language server at 'c:\Users\benwilk\.vscode\extensions\ms-azuretools.vscode-bicep-0.6.1\bicepLanguageServer\Bicep.LangServer.dll'.
2022-05-09T18:08:38.028Z info: Bicep language service started.
2022-05-09T18:08:47.062Z info: Bicep language service ready.
[Info  - 11:08:47 AM] Running on processId 69068
TRACE: Building semantic model for file:https:///d:/Repos/scapim-ps/aaworking/test.bicep
TRACE: Azure-Identity: [Informational] AzurePowerShellCredential.GetToken invoked. Scopes: [ https://management.azure.com/.default/.default ] ParentRequestId: ba5e4f8b-5ada-4724-b358-88c770a906f1
TRACE: Azure-Identity: [Informational] AzurePowerShellCredential.GetToken was unable to retrieve an access token. Scopes: [ https://management.azure.com/.default/.default ] ParentRequestId: ba5e4f8b-5ada-4724-b358-88c770a906f1 Exception: Azure.Identity.CredentialUnavailableException (0x80131500): PowerShell is not installed.

@MichielCornilleKenze
Copy link

@pb111111 The workaround you suggested in #6770 gives me a CHMOD: operation not permitted error on hosted agents.

@MichielCornilleKenze
Copy link

   - task: PowerShell@2
            inputs:
              targetType: 'inline'
              script: 
               $bicepPath = which bicep
               $url = "https://github.com/Azure/bicep/releases/download/v0.5.6/bicep-linux-x64"
               curl -Lo $bicepPath $url
               chmod +x $bicepPath
               exit 0

@pb111111
Copy link

pb111111 commented May 9, 2022

CHMOD: operation not permitted error on hosted agents.

Sorry, you only need to run chmod if the downloaded file didn't already exist.

@MichielCornilleKenze
Copy link

MichielCornilleKenze commented May 10, 2022

@pb111111 Thanks. Even after removing the CHMOD statements the original error still persists. I'll look further into why that worked for you but not for us. I hope microsoft rolls back the bicep version on their agents or manages to somehow fix forward a bicep version that works.

Update: Microsoft support suggested a similar approach which also does not work.

@MichielCornilleKenze
Copy link

After the workaround, this the output of bicep-v printed right before the what-if

Bicep CLI version 0.5.6 (5f2f88f)
ERROR: /home/vsts/work/1/s/bicep/main.bicep(11,25) : Error BCP192: Unable to restore the module with reference "ts:xxx/rg-shared-templatespecs/monitoring:0.2": The ChainedTokenCredential failed to retrieve a token from the included credentials.

Notice the version! the powershell workaround by @pb111111 correctly replaces the version, but then the consecutive azure deployment does not seem to use that bicep version?

@anthony-c-martin
Copy link
Member

@brwilkinson - I narrowed the issue down to between these two builds:

  1. https://github.com/Azure/bicep/actions/runs/2221714516 - works for me (v0.5.106)
  2. https://github.com/Azure/bicep/actions/runs/2221816090 - fails for me (v0.5.107)

So it seems like this issue was introduced with this commit: 14fd377

I'll keep digging, but it would be great if you have the time to confirm that you see the same

@brwilkinson
Copy link
Collaborator

brwilkinson commented May 10, 2022

@anthony-c-martin confirmed the failure and I can see the Scopes is incorrect.

image

should be:

image

This is also visible in the above logs ealier in the thread.

@anthony-c-martin
Copy link
Member

@brwilkinson great spot!

@bhsubra would you mind taking a look?

@anthony-c-martin
Copy link
Member

We'll be publishing a new Bicep release shortly with the fix!

@bhsubra
Copy link
Contributor

bhsubra commented May 11, 2022

This issue should be fixed with today's 0.6.11 release. Let us know if there are any concerns. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators May 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants