Azure IaaC – Part1 (Infrastructure as a code)

Santosh Gaikwad

Santosh Gaikwad

Connect on LinkedIn      Follow SCI Page

Write to admin@sharecareinspire.com
Santosh Gaikwad

Latest posts by Santosh Gaikwad (see all)

<<ARM      >> Azure IaC – Part 2

What is Infrastructure as a code (IaaC)?

Traditionally, development and operations are two distinct departments in an Independent Software Vendor, developers concern themselves with writing applications, and the folks in operations are concerned with keeping the applications running. However, for an application to function correctly, there are always explicit or implicit requirements regarding how the supporting infrastructure is configured. Unfortunately, such requirements are often lost during communication, which leads to many problems such as service outages because of misconfigurations, frictions between development and operations, and difficulties in recreating and diagnosing issues. All these problems are unacceptable in an Agile environment.

Why Infrastructure as a Code (IaaC)?

The boundary between development and operations is shifting. The developers are required to provide consistently deployable applications instead of just application code; thus, the deployment process can be automated to rollout fixes and upgrades quickly. This shift changed the definition of application. An application is no longer just code. Instead, an application is made up of both application code and explicit, executable description of its infrastructural requirements.

What are the benefits of Infrastructure as a Code (IaaC)?

1. Consistency: Consistently achieve standardised provisioning or deployment
2. Accelerating: Accelerating provisioning or deployment rapidly
3. Reusability: JSON code for repeatable or similar provisioning or deployment
4. Extensibility: JSON code for incorporating with additional items

Have any developer ever waited for weeks or months to get a development environment delivered by their internal IT operations? This demand has driven IT industry to deliver new tool set to ensure that one can deliver on time and meet the standard requirement constantly.

How Infrastructure is implemented

A short list of some of the Infrastructure as Code frameworks / platforms available

  • PowerShell & PowerShell Desired State Configuration (DSC)
  • Azure Resource Manager Portal
  • Puppet
  • Chef
  • Otter
  • SaltStack
  • Ansible
  • CFEngine

There are many Infrastructure as Code platforms / frameworks available. Each one will have its own set of benefits and drawbacks compare to the others, as is the case when comparing any set of similar tools.

On the Windows and Microsoft Azure platforms, the answers to implementing Infrastructure as Code provided by Microsoft are largely the PowerShell DSC, and even more so with Azure the Azure Resource Manager.

When implementing Infrastructure as Code in the Microsoft Azure and Azure Stack platform ecosystem the Azure Resource Manager is the tool of choice.

Additionally, there has been some market traction within the Microsoft Azure ecosystem in the adoption of Puppet and Chef. Microsoft even recognizes this with their Azure certifications by having questions on the exams expecting knowledge of what Puppet and Chef are, and what they are used for.

Azure Resource Manager Template (ARM)

Azure Resource Templates are JSON files that capture infrastructure as code. You can capture all the Azure resources your application needs in a single JSON document that you can consistently deploy to different environments. All resources defined in an Azure Resource Template are provisioned within a Resource Group.

Provision resources using ARM template in ARM portal

1. Search “Templates” on ARM portal
Templates is a preview service currently (May 17) available on ARM portal. select “Templates” service and it will provide you the list of existing templates available in current subscription and gives you option to create/add new.

Search Templates
Search Templates

2. Add New Template
Click on add button to add new template and use following code to provision web and database.

ARM JSON Template
ARM JSON Template
{ 
   "$schema":"http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
   "contentVersion":"1.0.0.0",
   "parameters":{ 
      "siteName":{ 
         "type":"string",
         "metadata":{ 
            "description":"Name of azure web app"
         }
      },
      "administratorLogin":{ 
         "type":"string",
         "minLength":1,
         "metadata":{ 
            "description":"Database administrator login name"
         }
      },
      "administratorLoginPassword":{ 
         "type":"securestring",
         "minLength":8,
         "maxLength":128,
         "metadata":{ 
            "description":"Database administrator password"
         }
      },
      "databaseDTU":{ 
         "type":"int",
         "allowedValues":[ 
            50,
            100
         ],
         "defaultValue":50,
      "metadata":{ 
            "description":"Azure database for MySQL pricing tier"
         }
      },
      "databaseSkuName":{ 
         "type":"string",
         "allowedValues":[ 
            "MYSQLB100",
            "MYSQLB50"
         ],
         "defaultValue":"MYSQLB100",
         "metadata":{ 
            "description":"Azure database for MySQL sku name: MySQL Basic 50 DTU (MYSQLB50)or 100 DTU (MYSQLB100)"
         }
      },
      "databaseSkuSizeMB":{ 
         "type":"int",
         "allowedValues":[
            102400,
            51200
         ],
         "defaultValue":51200,
         "metadata":{ 
            "description":"Azure database for MySQL Sku Size "
         }
      },
      "databaseSkuTier":{ 
         "type":"string",
         "allowedValues":[ 
            "Basic"
         ],
         "defaultValue":"Basic",
         "metadata":{ 
            "description":"Azure database for MySQL pricing tier"
         }
      },
      "mysqlVersion":{ 
         "type":"string",
         "allowedValues":[ 
            "5.6",
            "5.7"
         ],
         "defaultValue":"5.6",
         "metadata":{ 
            "description":"MySQL version"
         }
      }
   },
   "variables":{ 
      "databaseName":"[concat(parameters('siteName'), 'database')]",
      "serverName":"[concat(parameters('siteName'), 'pgserver')]",
      "hostingPlanName":"[concat(parameters('siteName'), 'serviceplan')]"
   },
   "resources":[ 
      { 
         "apiVersion":"2016-09-01",
         "name":"[variables('hostingPlanName')]",
         "type":"Microsoft.Web/serverfarms",
         "location":"[resourceGroup().location]",
         "properties":{ 
            "name":"[variables('hostingPlanName')]",
            "workerSizeId":"1",
            "reserved":true,
            "numberOfWorkers":0,
            "hostingEnvironment":""
         },
         "sku":{ 
            "Tier":"Standard",
            "Name":"S1"
         }
      },
      { 
         "apiVersion":"2015-02-01",
         "name":"[parameters('siteName')]",
         "type":"Microsoft.Web/sites",
         "location":"[resourceGroup().location]",
         "dependsOn":[ 
            "[concat('Microsoft.Web/serverfarms/', variables('hostingPlanName'))]"
         ],
         "properties":{ 
            "name":"[parameters('siteName')]",
            "serverFarmId":"[variables('hostingPlanName')]",
            "hostingEnvironment":""
         },
         "resources":[ 
            { 
               "apiVersion":"2015-04-01",
               "name":"connectionstrings",
               "type":"config",
               "dependsOn":[ 
                  "[concat('Microsoft.Web/sites/', parameters('siteName'))]"
               ],
               "properties":{ 
                  "defaultConnection":{ 
                     "value":"[concat('Database=', variables('databaseName'), ';Data Source=', variables('serverName'), '.mysql.database.azure.com;User Id=', parameters('administratorLogin'),'@', variables('serverName'),';Password=', parameters('administratorLoginPassword'))]",
                     "type":"MySQL"
                  }
               }
            }
         ]
      },
      { 
         "apiVersion":"2016-02-01-privatepreview",
         "kind":"",
         "location":"[resourceGroup().location]",
         "name":"[variables('serverName')]",
         "properties":{ 
            "version":"[parameters('mysqlVersion')]",
            "administratorLogin":"[parameters('administratorLogin')]",
            "administratorLoginPassword":"[parameters('administratorLoginPassword')]",
            "storageMB":"[parameters('databaseSkuSizeMB')]"
         },
         "sku":{ 
            "name":"[parameters('databaseSkuName')]",
            "tier":"[parameters('databaseSkuTier')]",
            "capacity":"[parameters('databaseDTU')]",
            "size":"[parameters('databaseSkuSizeMB')]",
            "family":"SkuFamily"
         },
         "type":"Microsoft.DBforMySQL/servers",
         "resources":[ 
            { 
               "type":"firewallrules",
               "apiVersion":"2016-02-01-privatepreview",
               "dependsOn":[ 
                  "[concat('Microsoft.DBforMySQL/servers/', variables('serverName'))]"
               ],
               "location":"[resourceGroup().location]",
               "name":"[concat(variables('serverName'),'firewall')]",
               "properties":{ 
                  "startIpAddress":"0.0.0.0",
                  "endIpAddress":"255.255.255.255"
               }
            },
            { 
               "name":"[variables('databaseName')]",
               "type":"databases",
               "apiVersion":"2016-02-01-privatepreview",
               "properties":{ 
                  "charset":"utf8",
                  "collation":"utf8_general_ci"
               },
               "dependsOn":[ 
                  "[concat('Microsoft.DBforMySQL/servers/', variables('serverName'))]"
               ]
            }
         ]
      }
   ]
}

3. Deploy existing template
Once template is created, it gets displayed in the list under templates service. click on the … button in-front of the template to deploy the same to provision defined resources in template.

Deploy ARM Template
Deploy ARM Template

 

4. Purchase resources / Custom deployment
Deployment will prompt for the list of parameters specified in the JSON Template. provide all the required details and click on purchase button

Purchase Resources
Purchase Resources

 

5. Provisioned resources
purchase resources button click start the ARM template deployment and resources provisioning process gets started, wait for some time to complete the provisioning process and open “Resource Groups” blade to see all the provisioned resources.

Resources provisioned
Resources provisioned

Deployment of ARM Templates using PowerShell is another popular practice followed by experts, will be covering same in another article.

 

<<ARM      >> Azure IaC – Part 2


Check Articles From Categories      Health and Parenting      Inspiring Stories      Technology      Microsoft Azure      SharePoint O365

Leave a Reply

Your email address will not be published. Required fields are marked *