Terraform

Unnati GuptaUnnati Gupta
3 min read

What is Terraform?

Terraform is a widely used open-source Infrastructure as Code (IaC) tool, developed by HashiCorp, that is specifically designed for provisioning and managing infrastructure.

Why do we use Terraform?

Terraform provides an automated way to provision infrastructure resources such as virtual machines, networks, and storage.

By using Terraform, you can work, deploy, and manage infrastructure on multiple platforms including private or public clouds such as on-premise, AWS, GCP, and Azure.

How does Terraform manage infrastructures on so many different kinds of platforms?

Terraform is achieved through Providers. Providers enable Terraform to manage Cloud Platforms like AWS, GCP, and Azure and network infrastructure like CloudFlare, DNS, and Networks.

In the case of monitoring also, it manages data management tools like DataDog, Grafana, and WaveFront.

HCL [HashiCrop Configuration Language] :

Terraform uses HCL which is simple, declarative language to define the infrastructure.

All the infrastructure resources can be defined within configuration files that have a “.tf“ extension.

The code we defined is the state that we want our infrastructure to be in that desired state.

How Terraform Works?

Terraform works in three phases.

a) Init

b) Plan

c) Apply

a) Init Phase:

During the init phase, Terraform initializes the project and identifies the provider to be used for the target environment.

b) Plan Phase:

Terraform drafts a Plan to get a target state.

c) Apply Phase:

Terraform makes the necessary changes required on the target environment to bring it to the desired state.

What is Resources?

Every object that Terraform manages is called a resource.

The resource can be a compute instance, a database server in the cloud, or a physical server. Terraform manages the lifecycle of resources from its provisioning to configuration to decommissioning.

What is the state of Terraform?

The state is a blueprint of the infrastructure deployed by Terraform.

Terraform can ensure that the entire configuration as it always in the defined state all the time.

What is the Desired and Current State?

The desired state is always defined in the Terraform file & it defines HOW YOU WANT TO INFRASTRUCTURE LOOK.

The current state refers to THE ACTUAL STATE OF THE INFRASTRUCTURE.

What is a State file in Terraform? What’s the importance of it?

The state file (terraform.tfstate) is a JSON file that stores the current state of your infrastructure as known by Terraform.

It contains detailed information about each resource created and managed by Terraform, such as resource IDs, properties, dependencies, and more.

The state file is automatically created after running terraform apply and gets updated each time Terraform makes a change to the infrastructure.

Importance of Terraform State file :

The state file in Terraform consistently records the current state of your infrastructure. This ensures that when subsequent changes are made, Terraform has up-to-date information about the existing infrastructure. Based on this recorded state, Terraform can generate a plan and apply the necessary modifications to align the infrastructure with the updated configuration.

Thank you for giving your precious time to read this blog/article and if any suggestions or improvements are required on my blogs feel free to connect on LinkedIn Unnati Gupta. Happy Learning 💥🙌**!!**

10
Subscribe to my newsletter

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

Written by

Unnati Gupta
Unnati Gupta

👨‍💻 DevOps Engineer at 6D Technology Passionate about bridging the gap between development and operations, I'm a dedicated DevOps Engineer at 6D Technology. With a strong belief in the power of automation, continuous integration, and continuous delivery, I thrive in optimizing software development pipelines for efficiency and reliability. 🚀 Exploring the DevOps Universe In my articles, I delve into the fascinating world of DevOps, where I share insights, best practices, and real-world experiences. From containerization and orchestration to CI/CD pipelines and infrastructure as code, I'm here to demystify the complex and empower fellow developers and ops enthusiasts. 📝 Blogging for Knowledge Sharing As a tech enthusiast and a lifelong learner, I'm committed to sharing knowledge. My articles aim to simplify complex concepts and provide practical tips that help teams and individuals streamline their software delivery processes. 🌐 Connect with Me Let's connect and explore the ever-evolving landscape of DevOps together. Feel free to reach out, comment, or share your thoughts on my articles. Together, we can foster a culture of collaboration and innovation in the DevOps community. 🔗 Social Links LinkedIn: https://www.linkedin.com/in/unnati-gupta-%F0%9F%87%AE%F0%9F%87%B3-a62563183/ GitHub: https://github.com/DevUnnati 📩 Contact Have questions or looking to collaborate? You can reach me at unnatigupta527@gmail.com Happy Learning!!