0
votes

I have an Azure DevOps pipeline to rotate Cosmos DB account keys. To do this, I'm using PowerShell and the New-AzCosmosDBAccountKey cmdlet.

For some unknown reason, the Az.CosmosDB module is not installed with Az, so it needs to be installed manually each time the pipeline is run.

Install-Module -Name Az.CosmosDb -AllowClobber -Force

When I run this locally everything works as expected, but within Azure DevOps I see an error

The 'Get-AzCosmosDBAccountKey' command was found in the module 'Az.CosmosDB', but the module could not be loaded.

What might be happening in Azure DevOps that differs from what is happening locally?

3

3 Answers

1
votes

The answer here is that an update was made to the Az.CosmosDb module so that it specifically requires version 1.9.4 (or higher) of Az.Accounts. However, on the Azure DevOps hosted agent they use version 1.9.3.

To fix, I changed the command that manually installs the Az.CosmosDb module -

Install-Module -Name Az.CosmosDb -RequiredVersion 0.1.6 -AllowClobber -Force

Note

When I found on the PowerShell Gallery that all versions of the Az.CosmosDb module were < 1.0.0 I did some investigation and it turns out that the module is still in preview, despite Cosmos DB having existed for years. This explains why the module is not installed along side all other Az.* modules when installing Az.

What is very frustrating is that there is no mention anywhere on the documentation for the module that it is in preview. If there were, it would probably have saved me a good chunk of time!

0
votes

Please check when you run DevOps Pipeline, which agent pool you are using. If you use microsoft-hosted agent, each time you run a pipeline, you get a fresh virtual machine. The virtual machine is discarded after one use. So you need to install the Az.CosmosDB module manually each time.

You could also deploy an agent on your local machine, in this way, it's supposed not need to nstall the Az.CosmosDB module manually each time.

https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/agents?view=azure-devops&tabs=browser

0
votes

Seems today Azure DevOps finally broke everything, old variant with

Install-Module Az.CosmosDB -RequiredVersion 0.1.6 -Force

has stopped working. Amazing, the whole experience with Az DevOps and Azure technologies are pretty the same, each time they just suddenly have stopped working at random places!

UPD: The gallery source address is dead https://www.powershellgallery.com/packages/Az.CosmosDB/0.1.6 , looks that is the reason