Saturday, 22 May 2021

Resolving "The deployment 'main' already exist" error in Bicep

 We have started exploring the Bicep language for Azure infrastructure automation with the post "Azure Infrastructure as Code (IaC) with Bicep - Getting Started with Development". However, as practice if you use the name main.bicep for the infrastructure template main file, you might run into error "The deployment 'main' already exist" in another infrastructure project where you are using the same main.bicep name. This is because of the way we have executed the deployment command.

The deployment command just specifies a location and a bicep file name as template with parameters if any. THis would result in the deployment to be created with main. So fi you try to deploy another project infrastructure to same Azure subscription, you would encounter the error "The deployment 'main' already exist".

If you list the available deployment in the subscription you would see main already available as shown above. Therefore, you may need to delete the current deployment with name main to make sure you can do the other project deployment. However, that's not feasible solution in many cases as you would be losing the information regarding the deployments done to the subscription. To delete a deployment you can execute az deployment sub delete -n nameofdeployment. If you delete all, the list command will show an empty array.

To avoid the issue of getting already exist error message while using main.bicpe as main template file in multiple projects, you can deploy as named deployment by providing, name parameter to deployment create command. For example, below deployment would have the name mytestqa even though it uses main.bicep file as template file.

No comments:

Popular Posts