What is Terraform?
Table of contents
Infrastructure as a code
What is Terraform?
Terraform is an infrastructure as code (IaC) tool for building, changing, and versioning infrastructure safely and efficiently. It uses a domain-specific language (DSL) to define infrastructure as code (IAC), enabling users to create, modify, and destroy infrastructure resources in a repeatable and scalable manner. Terraform supports multiple cloud providers, including AWS, Azure, and Google Cloud, and can also be used to manage on-premise infrastructure.
Why do we use terraform?
-**Manage any infrastructure-**Find providers for many of the platforms and services you already use in the Terraform Registry. You can also write your own. Terraform takes an immutable approach to infrastructure, reducing the complexity of upgrading or modifying your services and infrastructure.
-**Track your infrastructure-**Terraform generates a plan and prompts you for your approval before modifying your infrastructure. It also keeps track of your real infrastructure in a state file.
-**Automate changes-**Terraform configuration files are declarative, meaning that they describe the end state of your infrastructure. You do not need to write step-by-step instructions to create resources because Terraform handles the underlying logic.
- What are resources?
-Resources are defined by resource blocks. A resource can define one or more infrastructure resource objects, such as VPCs, virtual machines etc.
- What is Terraform module?
-A module is a container for multiple resources that are used together. Every Terraform configuration has at least one module known as its root module, which consists of the resources defined in the .tf
files in the main working directory.
- What is a state in Terraform and why is it important?
-In Terraform, a state is a representation of the current state of your infrastructure. It is a JSON-formatted file that keeps track of the resources that Terraform is managing. Terraform uses the state to determine what changes need to be made to your infrastructure to achieve the desired configuration and to track the progress of those changes.
Some key benefits of the state include:
1. Idempotent operations: Terraform uses the state to ensure that the desired infrastructure configuration is always in sync with the actual infrastructure. If there are any discrepancies, Terraform can automatically apply the necessary changes to bring the infrastructure into compliance with the desired state.
2. Collaboration: The state file is designed to be shared among team members, allowing for better collaboration and easier tracking of changes to the infrastructure.
3. Reusability: Terraform's state can be easily used across different environments, such as development, staging, and production, allowing for consistent infrastructure across multiple environments.
Overall, the state is a critical component of Terraform that allows it to effectively manage infrastructure and keep it in the desired configuration.
- What is the difference between Ansible and Terraform?
- Infrastructure management approach:
-Ansible uses a push-based approach, where configuration changes are pushed to target servers.
-Terraform uses a pull-based approach where infrastructure resources are provisioned based on a configuration file.
2. Scope of management:
-Ansible focuses on configuration management.
-Terraform is designed for infrastructure management.
3. Resource management:
-Ansible can manage software configuration.
-Terraform can manage both software and hardware resources.
4. DSL(domain-specific language):
-Ansible uses a YAML-based declarative language.
-Terraform uses its own HCL (Hashi-Corp Configuration Language) DSL.
In summary, Ansible is best suited for configuration management tasks, while Terraform is ideal for managing infrastructure resources across multiple cloud platforms. Depending on your specific needs, you may choose to use one or both of these tools in your infrastructure automation workflows.
Install Terraform on your system
Step1- create an EC2 instance
Step2- SSH your instance (EC2)
<< The Official Terraform website is >> https://www.terraform.io/downloads.html
Download the appropriate package for the system
Go to the website ---Select Linux as the operating system and Ubuntu as the package manager.
Step3- Copy and paste below three commands to the instance terminal.
- Verify that Terraform is installed correctly
Step4- To check the version of Terraform run the command
terraform --version
Thanks for Reading !!
Subscribe to my newsletter
Read articles from shubhlaxmi S directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by