Lecture 02 – TERRAFORM AND INSTALLATION

TERRAFORM

What Is Terraform?

Terraform is an open-source infrastructure as code (IaC) tool developed by HashiCorp. It allows you to define and manage your infrastructure in a declarative manner, using configuration files. With Terraform, you can create, modify, and version your cloud resources and infrastructure components across various cloud providers, data centers, and even on-premises environments.

Using Terraform, you can create complex and scalable infrastructure deployments with a single set of configuration files. This makes it easier to manage and version your infrastructure code, and it provides a reliable and consistent way to provision and manage resources across different environments.

Key features of Terraform include:

1.- Declarative Configuration: Infrastructure is described using a simple, human-readable language called HashiCorp Configuration Language (HCL) or JSON. You specify the desired state of your infrastructure, and Terraform takes care of managing the resources to achieve that state.

2.- Resource Management: Terraform supports a wide range of cloud providers, including AWS, Azure, Google Cloud Platform (GCP), and many others. It also supports various resource types such as virtual machines, networks, storage, databases, security groups, and more.

3.- Dependency Management: Terraform automatically determines the dependencies between resources and provisions them in the correct order. This ensures that resources are created or modified in a way that satisfies their interdependencies.

4.- State Management: Terraform maintains the state of your infrastructure in a state file. This file keeps track of the resources that have been created or modified, allowing Terraform to perform incremental changes on subsequent runs.

5.- Execution Plans: Before making any changes to your infrastructure, Terraform generates an execution plan that shows what actions will be taken. This allows you to review and validate changes before applying them.

6.- Idempotent Operations: Terraform ensures that the desired state of the infrastructure is achieved, regardless of how many times the configuration is applied. It only makes changes if there are differences between the current state and the desired state.

hands-on_image

TERRAFORM INSTALLATION ON CLOUD SERVER

Pre-Requisites

Launch an Ubuntu EC2 instance t2.small.

To download Terraform latest version, visit terraform official website

 

Steps To Install Terraform On EC2 Instance.

Step 01: To downloads and installs the HashiCorp GPG public key to the “/usr/share/keyrings/” directory using wget and gpg.

COPY & RUN –>$ the below command

				
					wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
				
			

Step 02: To adds a new repository entry to the “/etc/apt/sources.list.d/hashicorp.list” file, specifying the HashiCorp repository URL with the GPG key located at “/usr/share/keyrings/hashicorp-archive-keyring.gpg”.

COPY & RUN –>$ the below command

				
					echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
				
			

Step 03: To updates the package index on your system and installs the Terraform software using the package manager.

COPY & RUN –>$ the below command

				
					sudo apt update && sudo apt install terraform
				
			

To verify terraform installation

COPY & RUN –>$ the below command

				
					terraform --version