Azure is the buzzword for any developer whether you are working on-premise or online systems. In recent time any project you are involved, you can’t avoid seeing project artefacts hosted in Azure in some form, whether it is a storage, repository, api, batch jobs, virtual machines, etc. Develop using Azure makes life easy compared to the hardware/software constrain when we do the same in on-premise environments. Having said that not only developing using Azure, deploying is also seamless and hassle free. The other jargon that closely knit with cloud deployment is “CI/CD”. It is another fascinating topic to discuss but in this one I am going old school and talk about how to deploy resources manually using template deployment.
Now that you have setup your Azure Subscription, created your Resource Group, added your Resource(s) in it and it is up and running in your development environment. The next step is to roll-out your changes to the other environments like test, uat, prod. There are many ways Azure makes you achieve it.
- Template deployment
- ARM Template or Terraform
- Azure Command-Line Interface [CLI]
- PowerShell
Template deployment is easy and faster way to implement for small projects where there is less number of components to move and maintain. If there is not much of changes in the environment then it is good not to introduce much complexity to the deployment process involving automation scripts and maintaining them along with your component codes. Even if your deployment is targeting a new environment setup or an existing environment the template deployment help you to deploy easily and with minimal intervention.
Enough of the talking, lets cut to the chase. Template deployment doesn’t need any special configuration or tools needed to perform the deployment like the other methods. It can be performed in the Azure Portal itself.
Lets assume that you have a Resource Group func-dev-rg that sits in Azure comprises of Azure Function App. This needs to be moved from the development environment to test and uat, in those, test environment is already available and uat needs to be created from scratch.
Following are the steps to perform in order to achieve our scenario.
Export the template
- Login to your Azure portal.
- Locate your Resource Group, in our case it is func-dev-rg.
- In the left panel, you can see an option “Export template”. Click on that option. This will get you to the template export page.
- Click download button, this will download a file. The downloaded file will be a .zip file containing two files one is the template.json and parameter.json.
The template.json contains all the configuration information of the resources.
The paramter.json file contains the variables that are used in the template.json file. This helps to pass in the environment related values for different environment while we are deploying.
Import the template to test/uat environments
- Login to the Azure portal.
- Click + Create a resource button on the home page.
- In the Azure marketplace page, search for “Template deployment”. This will navigate to template deployment stage.
- Click on Create button to move to Custom deployment wizard.
- Click on Load file to select the template.json file that is downloaded in the export template stage.
- Once the template.json is selected, it will take you to the Customized template stage which loads the json file in a presentable format. In the left panel it will group by each resources in the resource group.
- Click the Save button on the bottom, you are now allowed to select to which subscription, resource group you need to deploy this resources.
- In the Resource group option choose the target resource group that we are deploying. In our case it will be func-test-rg, select the resource group and it will fix the location option based on the resource group location.
- Next step is to fill in the parameter values, click on the Edit parameters option next to Edit template. This will open up the parameter json file.
- Before click Save, download a copy of this parameter.json and save a copy of the parameter file and store it in a repo or deployment folders. This parameters file is vital during the next cycle of deployments.
If the name of the resources are misspelled or typo then it will create a new resource instead of updating the existing one.
- Check the agreement policies and click the Purchase button, the deployment will kickstart.
- Once the deployment is completed the whole list of resource that get updated/inserted are listed. You also been presented with an option to navigate to the resource.
- If the deployment failed, it will give the failure log. You can fix the problem and Redeploy it from the same stage.
- Follow the same steps for the uat environment to import, as it is a new environment the resource group needs to be created func-uat-rg in the Custom deployment stage. The new parameter.json file needs to formed with the new unique names for each resources in the group.