Table of contents
- What is Terraform?
- Why do we use Terraform?
- How does Terraform manage infrastructures on so many different kinds of platforms?
- HCL [HashiCrop Configuration Language] :
- How Terraform Works?
- What is Resources?
- What is the state of Terraform?
- What is the Desired and Current State?
- What is a State file in Terraform? What’s the importance of it?
- Importance of Terraform State file :
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 💥🙌**!!**