Terraform Init (Initializing the Working Directory)

1 minute read

Welcome to this lesson on Terraform Init.

The name init is short for initializing and it initializes something in the Terraform workflow. So, let’s find out what it does. The terraform init is a command, which initializes the working directory that contains your Terraform Code.

Now that’s a simplistic approach to understanding Terraform init, so let’s break it down.

Then terraform init does 2 imporant things! First, it download the supporting or ancillary(providing necessary support to the primary activities) components required for your code to work. Like the providers, which provide the libraries and code for your resources to be able to make API calls to whatever infrastructure you’re deploying into, and also modules, which we’ll learn more about in the course later.

And Second, this also sets up the backend for storing data from state files.

The Terraform state file will be discussed in much more detail later in the course. For now just know that, it is a mechanism by which Terraform tracks resources, so that it knows when to deploy or destroy a resource, depending on how you change the code.

The terraform init is a critical command to any data from the project, because this is the first command that you’ll be running when you’re done writing your initial code.

This command goes and fetches the providers, also known as plugins, which are going to provide the resources that your Terraform code is going to use. The terraform init can either go and download the plugins and modules from the Terraform public registry over the internet or from your custom URLs where you might’ve uploaded your custom modules written for Terraform.

It caches those plugins and modules. However, if a newer version of the module is available, it’s going to download it and install that version by default.

There’s a lot of nice functionality available with the switches or flags available with the Terraform init command, which I’ll urge you to go and have a look at.

Thank you for going through this lesson.

Updated: