Exploring Infrastructure as Code

Arun Prakash
4 min readJan 20, 2021

--

The post is about my recent project involving the deployment of the customizable and scalable web server for Azure.

This post can be found on my blog as well.

Before the advent of DevOps automation, deployment of an application in the server is a complex process that requires server setup, network configuration, route table creation, software, and DB configuration. It requires a lot of manual effort and at the same time, prone to human errors. The manual process may result in scalability, availability, and consistency issues. The fast-paced improvements happening in the DevOps world present a solution to this problem in the form of potential automation. Infrastructure automation has become crucial nowadays, as it becomes common that application deployment happens multiple times per day with a variety of configuration requirements.

Generally, infrastructure management includes key terms like networks, virtual machines, and load balancers. Infrastructure-as-code (IaC) is the key DevOp practice used for defining, deploying, updating, and destroying the infrastructure. IaC ensures that the target environment is deployed with the same configuration irrespective of the environment’s starting state, thus solving the problem of environment drift in the release pipeline.

Wikipedia says Infrastructure as Code (IaC) is the process of managing and provisioning computer data centers through machine-readable definition files, rather than physical hardware configuration or interactive configuration tools. The IT infrastructure managed by this process comprises both physical equipment, such as bare-metal servers, as well as virtual machines, and associated configuration resources

IaC has the environment description and version configurations in precisely documented code formats such as JSON and enables a declarative configuration model that can be relied on for quick configuration and consistent deployments avoiding any manual errors during the deployment. Thus, the team can get the benefit of creating a stable, rapidly reliable, and scalable infrastructure with ease.

As the system is configurable, the infrastructure maintenance like addition/removal of servers, software updates, software reconfigurations can be done with minimal changes to the configuration files alone.

The Infrastructure as code can be achieved with the help of several tools. Infrastructure provisioning and management can be done with the help of tools like Terraform, Red Hat Ansible, Chef, Puppet, Salt Stack, and AWS CloudFormation.Terraform helps in initial installation and configuration. To configure and deploy the application, the tools like Chef, puppet, and ansible can be used.

Infrastructure as Code

To explore Infrastructure-as-code with a simple project, I have created a scalable and customizable webserver using Azure, terraform, and packer.

I have created a custom policy in Azure that restricts the usage of resources without tags. I have assigned the policy to my resource group. I have specified the resource group in my server template and created the image using the free and open-source server templating software called Packer.

Packer helps in creating images for the virtual machines thus helps in launching completely provisioned and configured machines in seconds. This is cross-platform compatible and has the capability to create multiple images in parallel. In the packer template, I have used builders, packer version, provisioners, and variables. Builders are basically an array of objects that defines the creation of images. Provisioners is an array that is used to run the scripts or commands over the image. Variables are the key-value pairs that define the user variables in the server template.

After building the image with the required configuration using the packer, I have used the provisioning tool Terraform to create the infrastructure based on the provided configuration. Terraform uses the domain-specific language called HashiCorp Language (HCL) to interact with the cloud providers. The biggest advantage of Terraform is, it is cross-functional thus supports multiple cloud providers. Terraform allows the developer to create, update and destroy the infrastructure with ease. I have used the same resource group that I have used when creating the packer image here. The created packer image is used in the terraform configuration.

Terraform configuration includes resource group, virtual network, network security group, network interface, public IP, and load balancer. I have used a configurable file called variable.tf where you can configure the number of VMs to deploy, tags to include, name of the resource group, location preferences, etc.

Terraform can be initialized with the command ``terraform init`. We can see the plan by using the command ``terraform plan -out solution. plan`` . After the confirmation, we can apply the changes and deploy using the command ``terraform apply``.

More details about the project can be found at https://github.com/arunprakashpj/Azure-Infrastructure-Operations-Project

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Arun Prakash
Arun Prakash

Written by Arun Prakash

I write about Cloud, DevOps and SRE Stuffs! Passionate about Security !

No responses yet

Write a response