Terraform Init Command
Hello. In this tutorial, we will understand the basics of Terraform Init command that engineers use on daily basis.
1. Introduction
Terraform is an open-source tool developed by HashiCorp for building, changing, and versioning the infrastructure safely and efficiently. It is used to manage the infrastructure of the popular cloud service providers and custom in-house solutions. It helps manage both low-level (Compute, Storage, Networking, etc.) and high-level components (such as SaaS, DNS, etc.) Terraform deployment automation is divided into different sections i.e. –
- IaaC – IaaC is popularly known as the Infrastructure as a Code wherein the infrastructure is described using a high-level configuration syntax. This allows a blueprint of the infrastructure which can be deployed, versioned, and shared for re-use
- Execution Plans – Terraform has a planning step where it generates an execution plan. The execution plan tells the administrator what Terraform will do once applied and helps to avoid any surprises when it creates the infrastructure
- Resource Graph – Terraform builds a graph of all the resources and parallelizes the creation and modification of non-dependent resources. This offers insights into learning the dependencies in their infrastructure
- Change Automation – Terraform allows to apply of complex changesets to the infrastructure with minimal human intervention
1.1 Configuration language
Terraform has its configuration language designed to meet the infrastructure automation requirements. The main purpose of this language is to declare resources and a group of resources (gathered into a module) represents a larger unit of configuration. Language syntax consists of a few elements i.e. – Blocks, Arguments, and Expressions.
- Blocks – Containers for other contents and represents the object configuration
- Arguments – Assign a value to the name and appear within the blocks
- Expressions – Represents a single value, referenced value, or combination of other values
1.2 Steps
To create the infrastructure via the Terraform scripts, the following commands need to be executed in a sequence. However, details and actions may differ between workflows.
terraform init
– Initializing the new or existing terraform configurationterraform plan
– Generate the execution plan from the resources specified in the fileterraform apply
– Create the infrastructure from the resources specified in the fileterraform destroy
– Destroy the created infrastructure
2. Terraform Init Command
Terraform init is the first place after writing the code. This command is used to initialize the new or existing terraform configuration. Due to the idempotent nature of the command, it is safe to run it multiple times in the working directory. This command is used for:
- Plugin installation
- Child module installation
- Backend initialization
Remember that if any changes are made in the configuration files then we need to run the initialization command again. Once we run the terraform init
command the initialization process will begin as shown in Fig. 2.
That is all for this tutorial and I hope the article served you with whatever you were looking for. Happy Learning and do not forget to share!
3. Summary
In this tutorial, we learned an introduction to Terraform and the initialization command which acts as the primary step for the terraform configuration files.