Followers

Azure - ARM Templates

Azure - ARM Templates  To implement infrastructure as code for your Azure solutions, use Azure Resource Manager templates (ARM templates). T...

Azure - ARM Templates

 To implement infrastructure as code for your Azure solutions, use Azure Resource Manager templates (ARM templates). The template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. The template uses declarative syntax, which lets you state what you intend to deploy without having to write the sequence of programming commands to create it. In the template, you specify the resources to deploy and the properties for those resources.

ARM Template For Storage Account

Step 1: Search for the service Template Custom Deployment.

Step 2: select 


Step 3: It will open the Edit Template and Click on 

Step 4: Select a resource --> storage account and provide some unique storage account name and click on Save.

Step 5: Select the subscription and resource group and click on Review + Create. And a storage account will be created.


ARM Template for creating Virtual Machine using Powershell.

Step 1: Search for the service Template Custom Deployment.

Step 2: Select Create Windows VM 

Step 3: Enter the required values like subscription, Resource Group, username, password etc.

Step 4: Download the template.json file and Parametersfile.json(remove the code which requires some dynamic properties) by clicking on Edit Template and Edit ParameterFile button.

Step 5: Start the cloud shell and upload the above JSON files to the cloud shell.

Step 6: Run the below PowerShell command to create VM

az deployment group create --resource-group MyRG --template-file template.json --parameters parametersFile.json

Step 7: Verify the VM is created.

Nested ARM Templates

The main benefit of the Nested template is that in a JSON file you can create resources in multiple Resource groups.

In the below example, 2 storage accounts are created in different resource groups.

Step 1: Search for the service Template Custom Deployment.

Step 2: select 


Step 3: It will open the Edit Template and replace with the below code

{
  "$schema""https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion""1.0.0.0",
  "parameters": {
    "innerResourceGroup": {
      "type""string"
    },
    "innerSubscriptionID": {
      "type""string",
      "defaultValue"""
    }
  },
  "resources": [
    {
      "type""Microsoft.Storage/storageAccounts",
      "apiVersion""2019-06-01",
      "name""demostoreprimary1000",
      "location""East US",
      "sku":{
        "name""Standard_LRS"
      },
      "kind""Storage",
      "properties": {
      }
    },
    {
      "type""Microsoft.Resources/deployments",
      "apiVersion""2019-10-01",
      "name""nestedTemplate",
      "resourceGroup""[parameters('innerResourceGroup')]",
      "subscriptionId""[parameters('innerSubscriptionID')]",
      "properties": {
      "mode""Incremental",
      "template": {
          "$schema""https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
          "contentVersion""1.0.0.0",
          "parameters": {},
          "variables": {},
          "resources": [
          {
            "type""Microsoft.Storage/storageAccounts",
            "apiVersion""2019-06-01",
            "name""demostoresecondary1000",
            "location""Central US",
            "sku":{
              "name""Standard_LRS"
            },
            "kind""Storage",
            "properties": {
            }
          }
          ]
      },
      "parameters": {}
      }
    }
  ]
}

Step 4: Click on Save and then provide the subscription and resource group for the main storage account. Also, provide an inner storage account subscription id and resource group.

Step 5: Click on Review + Create. And storage accounts will be created.


ARM Template with Key Vault.

Let's store the password in a key vault's secret and refer to the ARM Template.

1. Create a key vault in the Azure portal

2. Add a secret (Generate/Import option) with the password value.

3. Goto key Vault --->Properties and select the resource id value which is something like below.

/subscriptions/ec3fb11f-9a3e-4457-a370-5105e306c58a/resourceGroups/MYRG/providers/Microsoft.KeyVault/vaults/keyvault1239

4. Select Key Vault --> Access Policies --> check Azure Resource Manager for template deployment

5. Use the default template.json file and change the Parameter file as below

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "adminUsername": {
      "value": "raman"
    },
    "adminPassword": {
      "reference": {
          "keyVault": {
          "id": "/subscriptions/ec3fb11f-9a3e-4457-a370-5105e306c58a/resourceGroups/MYRG/providers/Microsoft.KeyVault/vaults/keyvault1239"
          },
          "secretName": "pass2"
        }
    },
   
    "publicIpName": {
      "value": "myPublicIP"
    },
    "publicIPAllocationMethod": {
      "value": "Dynamic"
    },
    "publicIpSku": {
      "value": "Basic"
    },
    "OSVersion": {
      "value": "2019-datacenter-gensecond"
    },
    "vmSize": {
      "value": "Standard_D2s_v3"
    },
    
    "vmName": {
      "value": "simple-vm"
    }
  }
}

6. Upload it to the cloud shell and Run the command

az deployment group create --resource-group MyRG --template-file template.json --parameters parametersFile.json

7. The virtual machine should be created with the defined secret password.

 


COMMENTS

Name

Ansible,6,AWS,1,Azure DevOps,1,Containerization with docker,2,DevOps,2,Docker Quiz,1,Docker Swarm,1,DockerCompose,1,ELK,2,git,2,Jira,1,Kubernetes,1,Kubernetes Quiz,5,SAST DAST Security Testing,1,SDLC Quiz,3,SonarQube,3,Splunk,2,vagrant kubernetes,1,YAML Basics,1,
ltr
item
DevOpsWorld: Azure - ARM Templates
Azure - ARM Templates
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgt0U288pS027jNmZMlSLsCpqRVAULL-Kb_cDAQcdu5dipSnNoQBhGqiLaG5cSAl51ik74mQyrxqjO2UdS8LFelVJoFETVCPGtm5KjjeKoUUlD-IhO3D9V8uF0nanUFvGN1R5YhGGsX_5ZWrtgSeKLFzu4VibHISI7Zw5a5j4j8IVGA8Be6b66GPLHU/s320/Test.JPG
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgt0U288pS027jNmZMlSLsCpqRVAULL-Kb_cDAQcdu5dipSnNoQBhGqiLaG5cSAl51ik74mQyrxqjO2UdS8LFelVJoFETVCPGtm5KjjeKoUUlD-IhO3D9V8uF0nanUFvGN1R5YhGGsX_5ZWrtgSeKLFzu4VibHISI7Zw5a5j4j8IVGA8Be6b66GPLHU/s72-c/Test.JPG
DevOpsWorld
https://www.devopsworld.co.in/2022/06/azure-arm-templates.html
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/2022/06/azure-arm-templates.html
true
5997357714110665304
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content