Day 60 - Terraform🔥
Task 1 : Install Terraform on your system
Step 1: Update the package repository:
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common

Step -2 :Install the HashiCorp GPG key.
wget -O- https://apt.releases.hashicorp.com/gpg | \
gpg --dearmor | \
sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg

Step - 3 Verify the key's fingerprint.
gpg --no-default-keyring \
--keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg \
--fingerprint

step - 4 Add the official HashiCorp repository to your system.
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- 5 Download the package information from HashiCorp.
sudo apt update

step- 6 Install Terraform from the new repository.
sudo apt-get install terraform


Q : Why we use terraform?
A : We use Terraform for infrastructure provisioning and management. It allows us to define and automate the creation, modification, and deletion of infrastructure resources in a declarative and version-controlled manner. With Terraform, we can easily create and manage complex infrastructure setups across various cloud providers, reducing manual effort, ensuring consistency, and enabling infrastructure as code practices. It provides a unified workflow, scalability, and the ability to manage infrastructure changes efficiently.
Q : What is Infrastructure as Code (IaC)?
A : Infrastructure as Code (IaC) is an approach to infrastructure provisioning and management using machine-readable configuration files. It allows infrastructure resources to be defined, deployed, and managed using code rather than manual processes. With IaC, infrastructure setups can be version controlled, shared, and treated as software, enabling consistent, repeatable, and scalable deployments. It brings automation, speed, and reliability to infrastructure management, reducing manual errors and enabling efficient collaboration between development and operations teams.
Q : What is Resource?
A : A resource refers to any component or entity that can be provisioned or managed within an infrastructure environment. It can be a physical or virtual entity, such as a server, network device, database, storage volume, or any other infrastructure component. Resources in infrastructure management are typically defined and configured using code or configuration files, allowing them to be easily provisioned, modified, or destroyed programmatically. Resources are the building blocks of an infrastructure setup and are managed and orchestrated using tools like Terraform, allowing for consistent and scalable infrastructure deployments.
Q : What is Provider?
A : A provider is a plugin or integration that allows Terraform to interact with a specific infrastructure or service provider. Providers are responsible for understanding the API and features of the target provider and translating Terraform configurations into actions and resources supported by that provider. They act as a bridge between Terraform and the underlying infrastructure, enabling users to manage and provision resources across different cloud platforms, virtualization platforms, or services using a consistent and declarative approach. Providers handle authentication, API calls, and resource lifecycle management, making it easier for users to define and manage their infrastructure as code.
Q: What is State file in terraform? What’s the importance of it ?
A: The state file in Terraform is a JSON-formatted file that keeps track of the current state of the infrastructure resources managed by Terraform. It is important because it allows Terraform to understand the desired state, enables collaboration among team members, helps with change management, and maintains the correct order of operations when provisioning or modifying resources.
Q: What is Desired and Current State?
A: The desired state in Terraform refers to the configuration specified in the Terraform code, which defines how the infrastructure should be provisioned. It represents the end goal or the intended configuration of the resources.
The current state, on the other hand, refers to the actual state of the infrastructure resources as tracked by Terraform. It includes information such as the resource IDs, metadata, and attributes.
Terraform continuously compares the desired state with the current state and takes actions to reconcile any differences, ensuring that the infrastructure matches the desired configuration. This allows for infrastructure management and automation, making it easier to maintain and modify infrastructure over time.



