AWS IaaS and CICD using Infrastructure as a Code

PratulPratul
4 min read

DevOps Insights for the Week of August 19-24, 2024

Hello Guys, I am back with my daily update on my weekly learning to master DevOps Tools & Technologies.

AWS

This week, I expanded my learning by getting deep dive into one of the widely used feature in industry.

Since our work demands to be flexible, not only among team management but also in our technical work as well where we wanted to reduce the expenditure of resources in terms of cost & validity. This is where EC2 Autoscaling comes into the play!

EC2 AutoScaling

In EC2 Autoscaling, we can scale out or scale in our EC2 instances based on the user requirement on those particular day based on users work. Basically, we can dynamically allocate & deallocate EC2 instances & do not have to manually create or destroy instances every time which is unreliable in terms of cost & productivity.

Scenario:

To get acquainted with EC2 autoscaling, I created EC2 Autoscaling group & simultaneously referred to this documentation published by AWS which gave me a detailed concept about it.

What is Amazon EC2 Auto Scaling? - Amazon EC2 Auto Scaling

To start with this, First I created EC2 instance within a public subnet of VPC as I learned on my last week. I configured the instance by taking Windows Server 2022 as AMI with VM size as t3.micro.

It's an important note that autoscaling require a launch template. A launch template consists of AMIs of EC2 instance, which is a customized form. This is similar to concept of snapshot, which take saves the configuration of VM at that point of time with installed apps & software's. This snapshot can later be used as on OS image to create another EC2 instance. So, I followed the same steps & configured EC2 autoscaling. On the process of setting of EC2 autoscaling, I also encountered with Scaling feature, which is the core of autoscaling, where the term comes at the first place! I got to understand the term minimum instance count, maximum instance & desired instance count.

  • Desired instance count - It refers to the no of instance during ideal/normal traffic load of usage.

  • Minimum instance count - It refers to the no of instance that can get scale down to during least traffic load of usage.

  • Maximum instance count - It refers to the no of instance that can get scale up to during high traffic load of usage.

CICD

Since I have the hands-on experience in building, managing & deploying the poject to cloud & on-prem infrastructure. Now I wanted the infrastructure to be deployed to respective environment be it cloud like Azure or On-Prem

So, I relied on declarative codes rather than imperative codes like Javascript, Python for quick deployment by putting certain tags of the cloud services.

NOTE: Imperative codes are those codes which needs to be defined & created right from scratch. Unlike declarative codes like Terraform, Ansible & ARM Templates which is called & defined from particular cloud services.

To understand this, I have taken Azure ARM Template to create resources in cloud. Since I am proficient in creating ARM Templates & I have created Azure resources with it quite a number of times.

TASK:

To test out the resource through Piplining, I created a YAML pipeline in Azure showcasing an ARM Template

In ARM Template, I configured VM with its related resources (VNET, Storage, Routes..)

trigger:
  branches:
    include:
    - main

steps:

- task: AzureResourceManagerTemplateDeployment@3
  inputs:
    deploymentScope: 'Resource Group'
    azureResourceManagerConnection: 'Lifeline233-SP'
    subscriptionId: '436f92e2-6b30-4307-a390-a64596abd106'
    action: 'Create Or Update Resource Group'
    resourceGroupName: 'pratul233'
    location: 'East Asia'
    templateLocation: 'Linked artifact'
    deploymentMode: 'Incremental'
    csmFile: 'VMScript.json'
    csmParametersFile: 'VMScript.parameters.json'

CHALLENGES:

I was facing this issue which highlighted the path. I was passing the $(Build.ArtifactsDirectory) to the 'csmFile' & 'csmParametersFile' which was not taking as valid path.

So, to tackle this I simply configured Classic Build Pipeline. And I inserted same inputs. On the top right I got show 'YAML' & it gave me the code & by taking that reference I corrected my YAML script & it worked!!!

Sometimes, a simple hack is enough rather than browsing for solution.

0
Subscribe to my newsletter

Read articles from Pratul directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Pratul
Pratul