Video Thumbnail for Lesson
3.1: Terraform Providers + Init

Understanding Terraform Providers and the Init Command

In this lesson, we will dive deeper into Terraform providers and the terraform init command. We will explore the general sequence of Terraform commands, discuss the architecture of Terraform providers, and provide a detailed walkthrough of the init command.

The General Sequence of Terraform Commands:

  1. terraform init: Initializes your project
  2. terraform plan: Checks your configuration against the current state and generates a plan
  3. terraform apply: Applies the plan to create or update your infrastructure
  4. terraform destroy: Removes resources when no longer needed

Terraform Provider Architecture:

  • Terraform Core: Provides the engine for parsing configurations and state files
  • Providers: Connects Terraform Core with specific cloud services
Architecture diagram for web application

Terraform Providers:

  • Visit registry.terraform.io to explore available providers
  • Official providers have the "official" tag and are maintained by the respective cloud service
  • In your configuration file, specify required providers and pin their versions within a terraform block

Terraform Init Command:

In an empty working directory, create a main.tf file containing your configuration

File tree before running terraform init

Run terraform init to download the necessary providers and store them in the .terraform directory. The .terraform.lock.hcl file contains information about the installed dependencies and providers

Modules, reusable Terraform code bundles, are also downloaded and stored in the .terraform directory.

File tree before running terraform init

In this lesson, we have covered the essential aspects of Terraform providers and the terraform init command. You now have a deeper understanding of the Terraform command sequence, provider architecture, and the process of initializing Terraform projects