Interview Questions

Get ready for your next interview with our comprehensive question library

Terraform Interview Questions

Filter by Difficulty

1.

What is Terraform and how does it differ from other Infrastructure as Code tools?

beginner

Terraform is an open-source Infrastructure as Code (IaC) tool developed by HashiCorp that allows you to define and provision infrastructure using declarative configuration files. Unlike imperative tools that require you to specify step-by-step instructions, Terraform uses a declarative approach where you describe the desired end state.

Key differences from other IaC tools:

  • Provider-agnostic: Works with multiple cloud providers (AWS, Azure, GCP, etc.)
  • State management: Maintains a state file to track real-world resources
  • Plan and apply workflow: Shows changes before applying them
  • Immutable infrastructure: Replaces resources rather than modifying them in place
2.

Explain the basic Terraform workflow.

beginner

The Terraform workflow consists of four main steps:

  1. Write: Create configuration files (.tf) defining your infrastructure
  2. Initialize: Run terraform init to download providers and modules
  3. Plan: Run terraform plan to preview changes before applying
  4. Apply: Run terraform apply to create/modify/destroy infrastructure
terraform init
terraform plan
terraform apply
terraform destroy  # when cleanup is needed
3.

What are Terraform providers and how do you configure them?

beginner

Providers are plugins that enable Terraform to interact with cloud platforms, SaaS providers, and APIs. They define resource types and data sources available for use.

Example AWS provider configuration:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

provider "aws" {
  region = "us-west-2"
}
4.

What is the difference between a resource and a data source in Terraform?

beginner

Resources are infrastructure components that Terraform creates, manages, and destroys. They represent the desired state of infrastructure.

Data sources allow Terraform to fetch information about existing infrastructure or external systems without managing them.

# Resource - creates new EC2 instance
resource "aws_instance" "web" {
  ami           = "ami-12345678"
  instance_type = "t2.micro"
}

# Data source - fetches existing VPC info
data "aws_vpc" "default" {
  default = true
}
5.

Explain Terraform variables and their types.

beginner

Upgrade to Premium to see the answer

Upgrade to Premium
6.

What is the Terraform state file and why is it important?

beginner

Upgrade to Premium to see the answer

Upgrade to Premium
7.

How do you define outputs in Terraform and why are they useful?

beginner

Upgrade to Premium to see the answer

Upgrade to Premium
8.

What are the main Terraform configuration files and their purposes?

beginner

Upgrade to Premium to see the answer

Upgrade to Premium
9.

Explain the terraform init command and when you need to run it.

beginner

Upgrade to Premium to see the answer

Upgrade to Premium
10.

What is the difference between terraform plan and terraform apply?

beginner

Upgrade to Premium to see the answer

Upgrade to Premium
11.

Explain Terraform modules and their benefits.

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
12.

What are Terraform workspaces and when should you use them?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
13.

Explain remote state backends and their advantages.

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
14.

What are data sources and provide some practical examples?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
15.

Explain Terraform functions and provide examples.

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
16.

What are provisioners and when should you avoid them?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
17.

Explain dynamic blocks and provide an example.

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
18.

What are lifecycle rules and when do you use them?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
19.

How do you handle sensitive data in Terraform?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
20.

Explain count and for_each meta-arguments.

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
Showing 1 to 20 of 32 results

Premium Plan

$10.00 /monthly
  • Access all premium content - interview questions, and other learning resources

  • We regularly update our features and content, to ensure you get the most relevant and updated premium content.

  • 1000 monthly credits

  • Cancel anytime