Infrastructure as Code
- This is an approach of managing infrastructure where infrastructure is described in configuration files and then used to create the infra automatically.
- Tools:
- Advantages:
- Reusability
- managing multiple environments
- Every change in infra is version controlled
Azure Resource Manager (ARM)
- This is the basis for Azure IaC Capabilities via ARM templates.
- Azure provides capabilities by Resource Providers which are registered to subscription.
- Resource Providers provide services and operations
- refer the below image

- When we are using Azure either from portal/CLI/Powershell/SDK we interact with Resource providers
- Experiment: Create a vm in Azure Portal.
- After succesful creation, Navigate to Resource Group and then deployments, select deployment and view template



- So when we create something from azure portal it is creating template.
-
Azure CLI/Powershell and SDK directly interact with Management API of Azure to create resources where as portal tries to create a template.
-
To create custom templates for our infrastructure we need to express infrastructure as a code using ARM/Bicep.
- ARM uses json
- ARM has json Refer Here
- Workflow for creating infra as code

- We use IaC Whenever we need to work with creating/modifying infrastructure on various environments
ARM Templates
- Template is used to Create infrastructure. This template can be applied at multiple levels
- Resource Group Deployment
- Subscription Deployment
- Management Group Deployment
- Tenant Deployment
- ARM Template is a json file Refer Here for the basic structure
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "",
"apiProfile": "",
"parameters": { },
"variables": { },
"functions": [ ],
"resources": [ ],
"outputs": { }
}
- In the above not every field is required. Bare minimum template
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "",
"resources": [ ]
}
Exercise