I have an Azure ASP.NET Core app and various Azure components (App Service, Function App, SQL DB) that were created manually via the Azure Portal UI. I want to reverse engineer the Azure resources to .bicep files but I get an error in VSC. Ideally I'd use Visual Studio (What I've been using for development) but there doesn't seem to be an option.
I do the following in VSC:
myresource.bicep
ctrl+shift+p / "Bicep: Insert resource" /
Paste in the Resource Id.The error is as follows: Caught exception fetching resource: The ChainedTokenCredential failed to retrieve a token from the included credentials.
- Azure CLI not installed
- Az.Account module >= 2.2.0 is not installed.
I've checked the following:
What am I doing wrong? I haven't typed any terminal/console messages. Am I supposed to?
To reverse engineer Azure resources to .bicep
files, no terminal/console messages are required. You can create an empty .bicep
file in Visual Studio Code
and then use the Azure extension
to acquire the Resource Id
of the entity you want to reverse engineer. Following that, you can use the "Bicep: Insert resource"
command to insert the resource declaration into the .bicep
file by specifying the Resource Id
of an existing resource.
And if the module issue occurs frequently, it indicates that a module was not properly installed.
Install Az accounts module in the VScode
terminal using
Install-module az.accounts
command and if it is already installed it shows output warning as below.
I also got the similar caught exception when I tried in my environment.
Though you added Azure CLI extensions in VScode it wont work. So I installed Azure CLI
latest release in my local windows. After the installation is done, I copied that cli folder
from downloads
to the .VScode
in file explorer.
I restarted my Visual Studio Code
once it is added in the corresponding folder. To check whether it is working fine, I gave az
in VScode
terminal and it shows all the commands as follows.
Then authorize it with the Azure account using
az login --scope https://management.azure.com//.default
command.
Inserted an existing resource successfully by going into Bicep: Insert a resource
from command palette.