๐Ÿš€ Day 22: DevOps Interview Preparation Challenge โ€“ Terraform Basics (Provider, Init, Plan)

Series: 30 Days DevOps Interview Preparation
Author: Tathagat Gaikwad

Welcome to Day 22 of the 30 Days of DevOps Interview Preparation Challenge. Today, we dive into Terraform basics โ€” specifically the concepts of Provider, Init, and Plan. These are the foundation of working with Terraform and are often asked in interviews to check your understanding of Infrastructure as Code (IaC).


๐ŸŒ What is Terraform?

Terraform is an open-source Infrastructure as Code (IaC) tool created by HashiCorp. It allows you to define, provision, and manage infrastructure across multiple cloud providers using a declarative configuration language (HCL โ€“ HashiCorp Configuration Language).

Instead of manually creating resources via cloud consoles, Terraform helps automate the entire process in a repeatable and consistent way.


โšก Key Terraform Concepts (Interview-Oriented)

1. Provider

  • Definition: A provider is a plugin that lets Terraform interact with cloud platforms or services (AWS, Azure, GCP, Kubernetes, GitHub, etc.).

  • Role: Providers serve as the bridge between Terraform and the API of the service you want to manage.

  • Example:

provider "aws" {
  region = "us-east-1"
}

This snippet tells Terraform to use the AWS provider in the us-east-1 region.

๐Ÿ‘‰ Interview Tip: Be ready to explain how Terraform uses providers to manage resources across different clouds. Interviewers might ask you to compare it with tools like Ansible or CloudFormation.


2. Init (terraform init)

  • Definition: The command terraform init initializes the Terraform working directory.

  • What it does:

    • Downloads the required provider plugins

    • Sets up the backend configuration (where Terraform stores state)

    • Prepares the environment for future commands

  • Usage Example:

terraform init
  • Output: Youโ€™ll see messages about provider plugins being downloaded.

๐Ÿ‘‰ Interview Tip: Be ready to explain why skipping terraform init will cause Terraform to fail (because it doesnโ€™t know how to communicate with providers without initialization).


3. Plan (terraform plan)

  • Definition: The command terraform plan shows what Terraform will do before making any actual changes.

  • Role: It acts like a dry run โ€“ previewing actions (create, update, delete) without applying them.

  • Usage Example:

terraform plan
  • Why it matters: Helps avoid unintended resource deletions or costly infrastructure changes.

๐Ÿ‘‰ Interview Tip: If asked why terraform plan is important in production, emphasize its role in change validation and collaboration within teams (e.g., generating a plan file for review).


๐ŸŽฏ Interview Questions with Detailed Answers

Q1. What is a Terraform provider, and why is it important?

Answer: A provider in Terraform is a plugin that allows Terraform to communicate with APIs of cloud platforms or services. Without a provider, Terraform cannot manage any resources. Providers define the available resource types and data sources. For example, the AWS provider lets Terraform manage EC2, S3, RDS, etc.


Q2. What happens when you run terraform init?

Answer: Running terraform init performs initialization tasks like:

  • Downloading and installing required provider plugins

  • Configuring backends for storing the Terraform state

  • Setting up the working directory so that further Terraform commands (plan, apply) can run
    If skipped, Terraform will not know how to interact with the infrastructure provider.


Q3. How does terraform plan differ from terraform apply?

Answer:

  • terraform plan: Shows the execution plan (preview of what will be changed). No actual changes are made.

  • terraform apply: Applies the changes to the infrastructure based on the plan.
    ๐Ÿ‘‰ Best practice: Always run terraform plan before apply to avoid surprises.


Q4. Why should you review a Terraform plan before applying?

Answer: Reviewing a plan prevents unintended changes, like accidentally deleting resources or provisioning costly infrastructure. It also enables peer review in teams, ensuring safer deployments.


Q5. How does Terraform know which provider plugin to use?

Answer: Terraform determines providers based on the provider block in the configuration file and the terraform init process, which installs and configures them. The provider version can also be pinned using required_providers to ensure consistency across environments.


๐Ÿ’ก Pro Tips for Interview & Practice

  • Always pin provider versions to avoid unexpected behavior:
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}
  • Run terraform plan -out=tfplan to save the plan and apply it later (terraform apply tfplan).

  • Compare Terraformโ€™s declarative style with imperative tools like Ansible when asked in interviews.


๐Ÿ“Œ Summary

  • Provider: Defines which service/cloud Terraform interacts with.

  • Init: Prepares Terraform by downloading providers and setting up the backend.

  • Plan: Previews changes before applying, ensuring safety and control.

These three steps are the core building blocks of working with Terraform and form the foundation for advanced features like modules, state management, and workspaces.


๐Ÿ”— Follow the full series for more DevOps interview prep content!
Stay tuned for Day 23, where weโ€™ll continue diving deeper into Terraform.

#DevOps #Terraform #InterviewPreparation #AWS #Cloud #IaC

0
Subscribe to my newsletter

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

Written by

Tathagat Gaikwad
Tathagat Gaikwad