Hydromast
Hydromast

Reputation: 312

Print Output of Module Deployments Status in Bicep

Let's say I have a bicep template that has multiple modules like the following:

module storageAccount ".../location" = {
 ...
}
output storageAccountStatus string = 'SA deployed!'
module keyVault ".../location" = {
     ...
}
output keyVaultStatus string = 'kv deployed!'
module functionApp ".../location" = {
     ...
}
output functionApp string = 'fa deployed!'

If I were to execute this template and it fails, how would I get the output of the statuses?

The MS Learn documentation on this says that you can only get the output of a successful deployment: https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/outputs?tabs=azure-powershell

It can also be cumbersome to me to have to manually get the output of the individual module deployment's output.

Is there an easy way to know which module fails to deploy if you put them all in one bicep template?

Upvotes: 0

Views: 1731

Answers (1)

bmoore-msft
bmoore-msft

Reputation: 8737

A module in bicep creates a deployment resource in Azure. You can always look up the result of the module/deployment in Azure. This will depend a bit on your targetScope but you can do something like:

Get-AzResourceGroupDeployment -ResourceGroupName $rgName | Where-Object{$_.ProvisioningState -eq "Failed"}

You can then drill down further into each operation that was attempted, e.g.

Get-AzResourceGroupDeploymentOperation -ResourceGroupName $rgName -Name $deploymentName

The name of a deployment will be the name of the module in bicep.

One caveat here is that those commands will show you all of the deployments in the given scope - so for example if a resourceGroup has been around for a long time, you might see a lot of deployments there. If you're using the same names all the time, then the old deployments will be overwritten (so you only see the latest) aside from that you may want to add other filters.

Upvotes: 2

Related Questions