An existing deployment can be exported as a template that you can use to regenerate the environment or to just gain a better understanding of how the deployment is configured. There are two ways of exporting a template from a deployment.
The first way is to export the actual template used by the Azure portal for the deployment.
When you use the Azure portal to deploy a resource, it still creates and submits the ARM template to the service for deployment. On the Review tab of most deployments, there is a Download A Template For Automation option, as shown in Figure 3-5 for a storage account.
This method exports the template exactly as you customized it in the Azure portal, includ- ing the values for parameters and variables during the original execution. This approach does not capture any changes made to the deployment after it was deployed.
FIGURE 3-5 The Review tab of a deployment with the option to download the template
Clicking Download A Template For Automation opens the Template deployment view, as shown in Figure 3-6. From here, click Download to download the template locally, click Deploy to deploy the template, or click Add To Library to save to your template gallery for later deployment.
The second approach to generating an ARM template is to use the Export Template menu option for a resource or the resource group. It generates a template that represents the current state of the context you selected. The state might have been updated by multiple templates,or it might have been updated by changes from the Azure portal or changes via the REST API or command line. It might include many hard-coded values and not as many parameters as you would expect in a template that was designed for reusability. This template is useful for redeploying to the same resource group because of the hard-coded values. Using it for other new deployments typically requires a significant amount of editing to customize parameters and values. You can access this template by navigating to the resource or resource group and clicking Export Template on the left, as shown in Figure 3-7.
FIGURE 3-6 The Template view for a deployment
FIGURE 3-7 The Export Template blade of a resource group
Interpret and modify a Bicep file
Bicep is a domain-specific language that uses an easy-to-read, declarative syntax to deploy Azure resources. Bicep is not a replacement for ARM templates but builds on top of ARM with its features and benefits. Bicep has integration as an extension with Visual Studio Code, which provides IntelliSense to help you author new Bicep files.