Day 1 - About IAC and Terraform

Day 1 - About IAC and Terraform

10 Days of Terraform

What is Infrastructure as Code?

Infrastructure as Code (IaC) is a must-have requirement to manage infrastructure efficiently and effectively. With IaC tools, you can manage infrastructure using code, just like how developers manage their source code. The code used in IaC has its own format and syntax, which must comply with the rules of the system. Any code that doesn't adhere to the rules will not create the desired resources. Once the code is written, it is stored in version management to track changes. If the code is compliant and executes successfully, the system creates the required resources. This process is repeatable and reliable, ensuring that the infrastructure can be deployed with confidence. To manage infrastructure using code, you need to use IaC tools like Terraform, Ansible, Chef, Puppet, and CloudFormation.

Advantages of IAC:

  • Standardizing infrastructure setup reduces errors, incompatibility, and promotes smooth operations

  • Removing manual tasks frees up time to focus on other work.

  • "Improve the speed of configuring by enabling faster execution, allowing you to complete your tasks more efficiently."

  • It delivers a stable environment rapidly, avoiding the need for manual configuration of environments and enforcing consistency.

  • By versioning IAC (Infrastructure as Code) configuration files, any changes made can be traced and monitored easily. This also improves security as all compute, storage and networking services are provisioned via code, which means they are deployed consistently every time. As a result, security standards are applied consistently across the company without the need for a security gatekeeper.

IAC Architecture:


What is Terraform?

Terraform is an open-source Infrastructure as Code (IAC) tool that enables users to define and provision infrastructure as code, thus allowing the automation of the entire infrastructure deployment process. Developed by HashiCorp, Terraform allows you to easily build and manage your cloud infrastructure in a safe, efficient, and versioned manner. It is designed to work with a variety of service providers and custom in-house solutions, making it a versatile tool for managing infrastructure. Written in Go language.

Features:

  • Enhanced multi-cloud infrastructure deployment

  • Automated management

  • Infrastructure as a Code

  • Faster provisioning

  • Lower development costs.

Life Cycle of Terraform:


Installation of Terraform

Terraform Installation

wget https://releases.hashicorp.com/terraform/1.5.3/terraform_1.5.3_linux_amd64.zip
sudo unzip terraform_1.5.3_linux_amd64.zip -d /usr/local/bin/ 
rm terraform_1.5.3_linux_amd64.zip 
terraform --version
  • wgethttps://releases.hashicorp.com/terraform/1.5.3/terraform_1.5.3_linux_amd64.zip: This command uses the wget utility to download the Terraform binary from HashiCorp's releases server. The version being downloaded is 1.5.3, and it's for a Linux system with an AMD64 architecture.

  • sudo unzip terraform_1.5.3_linux_amd64.zip-d /usr/local/bin/: This command uses sudo (superuser do) to run the unzip command with root privileges. The unzip command extracts the contents of the downloaded zip file. The -d /usr/local/bin/ option tells unzip to place the extracted files into the /usr/local/bin/ directory, which is a common location for user-installed binaries.

  • rm terraform_1.5.3_linux_amd64.zip: This command removes the downloaded zip file, as it's no longer needed after the Terraform binary has been extracted.

  • terraform --version: This command runs the newly installed terraform binary with the --version option, which causes Terraform to print its version number. This serves to verify that Terraform was installed correctly and is working as expected.

Azure CLI Installation -This will be needed to authenticate to your azure account

Step 1

curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
az login --use-device-code --tenant TENANT_ID
  • This command downloads the Azure CLI installation script from Microsoft's server using the curl utility. The -s option enables silent mode, and the -L option follows any redirects.

  • The second part of the command pipes the installation script to sudo bash, which runs Bash with root privileges. This installs the Azure CLI on the system.

How to Get TENANT ID

Did you find this article valuable?

Support Venkatesh Krishnan R by becoming a sponsor. Any amount is appreciated!