Terraform Interview Questions
Top Terraform interview questions and answers covering Infrastructure as Code, Terraform State, Modules, Providers, Workspaces, Remote State, Terraform Cloud, Security, CI/CD, and production troubleshooting.
Introduction
Terraform has become one of the most widely used Infrastructure as Code (IaC) tools in enterprise cloud environments.
Interviewers typically assess your understanding of Terraform architecture, state management, modules, remote backends, CI/CD integration, security, and troubleshooting production infrastructure.
This guide covers the most frequently asked Terraform interview questions for:
- DevOps Engineers
- Cloud Engineers
- Platform Engineers
- Site Reliability Engineers (SRE)
- Solution Architects
Enterprise Terraform Workflow
flowchart LR
Developer --> GitHub --> CI/CD --> TerraformPlan --> Approval --> TerraformApply --> AWS --> Monitoring
Terraform Basics
1. What is Terraform?
Answer
Terraform is an Infrastructure as Code (IaC) tool developed by HashiCorp that provisions and manages cloud infrastructure using declarative configuration files.
Benefits
- Automation
- Version Control
- Repeatability
- Multi-Cloud
- Consistency
2. What is Infrastructure as Code (IaC)?
Infrastructure is managed using code instead of manually creating resources through cloud consoles.
Examples
- VPC
- EC2
- Kubernetes
- Databases
- IAM
3. Why is Terraform popular?
Advantages
- Multi-Cloud Support
- Declarative Language
- Large Provider Ecosystem
- Reusable Modules
- Infrastructure Versioning
- Easy Automation
4. What language does Terraform use?
Terraform uses HashiCorp Configuration Language (HCL).
Example
resource "aws_s3_bucket" "logs" {
bucket = "company-logs"
}
5. What is a Provider?
Providers allow Terraform to communicate with external platforms.
Examples
- AWS
- Azure
- Google Cloud
- Kubernetes
- GitHub
- Datadog
Resources
6. What is a Resource?
Resources represent infrastructure objects.
Examples
- EC2 Instance
- S3 Bucket
- IAM Role
- VPC
- Kubernetes Deployment
7. What is a Data Source?
Data Sources read existing infrastructure without creating resources.
Example
data "aws_caller_identity" "current" {}
Variables & Outputs
8. What are Variables?
Variables make Terraform reusable.
Example
variable "region" {
default = "us-east-1"
}
9. What are Outputs?
Outputs display useful information after deployment.
Example
output "instance_ip" {
value = aws_instance.web.public_ip
}
State Questions
10. What is Terraform State?
Terraform State records the current infrastructure.
Default file
terraform.tfstate
11. Why is the State file important?
State tracks
- Resource IDs
- Dependencies
- Metadata
- Infrastructure Changes
Without state Terraform cannot determine what has changed.
12. Why should state never be committed to Git?
Reasons
- Secrets
- Sensitive Data
- Team Conflicts
- Security Risks
13. What is Remote State?
Store Terraform state remotely.
Examples
- Amazon S3
- Azure Storage
- GCS
- Terraform Cloud
14. What is State Locking?
State locking prevents multiple users from updating infrastructure simultaneously.
flowchart LR
DeveloperA --> StateLock
DeveloperB
-.Waiting.->StateLock
AWS commonly uses
- S3
- DynamoDB
Modules
15. What is a Module?
A module is a reusable collection of Terraform resources.
Benefits
- Reusability
- Standardization
- Easier Maintenance
16. Why should enterprises use modules?
Instead of repeating infrastructure code, organizations create reusable modules for:
- VPC
- EKS
- IAM
- RDS
- Monitoring
Workspaces
17. What are Terraform Workspaces?
Workspaces separate environments.
Examples
dev
qa
stage
prod
Commands
18. Explain the Terraform workflow.
flowchart LR
WriteCode --> Init --> Plan --> Apply --> Infrastructure
19. Explain Terraform commands.
| Command | Purpose |
|---|---|
| terraform init | Initialize Project |
| terraform fmt | Format Code |
| terraform validate | Validate Configuration |
| terraform plan | Generate Execution Plan |
| terraform apply | Apply Changes |
| terraform destroy | Delete Infrastructure |
Architecture
20. Explain Terraform Architecture.
flowchart LR
TerraformCLI --> Provider --> CloudAPI --> Infrastructure
21. What is Dependency Graph?
Terraform automatically creates a dependency graph.
flowchart TD
VPC --> Subnet
Subnet --> EC2
EC2 --> Application
Lifecycle
22. What is Lifecycle?
Lifecycle customizes resource behavior.
Example
lifecycle {
create_before_destroy = true
}
Other options
- ignore_changes
- prevent_destroy
Security
23. How do you secure Terraform?
Best Practices
- IAM Roles
- Remote State
- State Encryption
- Secrets Manager
- Least Privilege
- No Hardcoded Credentials
24. Where should secrets be stored?
Never store inside Terraform code.
Use
- AWS Secrets Manager
- Azure Key Vault
- HashiCorp Vault
- GCP Secret Manager
Enterprise Questions
25. What is Terraform Cloud?
Terraform Cloud provides
- Remote State
- Collaboration
- State Locking
- Run History
- Cost Estimation
26. What is Terraform Enterprise?
Enterprise version with
- SSO
- RBAC
- Sentinel
- Private Module Registry
- Governance
27. What is Sentinel?
Sentinel is Policy as Code.
Examples
- Mandatory Tags
- Encryption
- Approved Instance Types
- Compliance Rules
CI/CD Questions
28. How does Terraform fit into CI/CD?
flowchart LR
GitHub --> GitHubActions --> TerraformInit --> TerraformValidate --> TerraformPlan --> Approval --> TerraformApply
29. Which CI/CD tools support Terraform?
- GitHub Actions
- Jenkins
- GitLab CI
- Azure DevOps
- CircleCI
Production Scenarios
30. Terraform Apply failed. What would you check?
- Syntax Errors
- Provider Configuration
- IAM Permissions
- State File
- Resource Limits
- API Errors
31. Someone manually deleted an EC2 instance.
What happens?
Terraform detects infrastructure drift during:
terraform plan
Terraform will recreate the resource during the next apply unless the configuration has changed.
32. Two engineers executed Terraform Apply simultaneously.
What prevents corruption?
State Locking
AWS Example
- S3 Backend
- DynamoDB Lock
33. Terraform Plan shows unexpected changes.
Possible reasons
- Manual Changes
- Drift
- Variable Changes
- Provider Updates
- State Corruption
34. Existing infrastructure must be managed by Terraform.
What would you do?
Import it.
Example
terraform import aws_instance.web i-123456
35. How do you organize Terraform code in large enterprises?
Recommended Structure
terraform/
environments/
modules/
network/
security/
database/
compute/
monitoring/
Common Production Problems
| Problem | Solution |
|---|---|
| State Corruption | Restore Backup |
| Drift | terraform plan |
| Parallel Execution | State Locking |
| Hardcoded Secrets | Vault / Secrets Manager |
| Duplicate Resources | Import Existing Resources |
| Manual Changes | GitOps + IaC |
Enterprise Best Practices
- Remote State
- Versioned Modules
- Separate Environments
- GitOps Workflow
- Infrastructure Reviews
- Pull Requests
- terraform validate
- terraform fmt
- Security Scanning
- Automated CI/CD
Common Terraform Providers
| Provider | Purpose |
|---|---|
| AWS | Infrastructure |
| Azure | Infrastructure |
| GCP | Infrastructure |
| Kubernetes | Cluster Resources |
| Helm | Helm Charts |
| GitHub | Repository |
| Cloudflare | DNS |
| Datadog | Monitoring |
Real-World Scenario
A company manages infrastructure for a microservices platform.
Workflow
- Infrastructure code is committed to GitHub.
- GitHub Actions runs
terraform fmt,terraform validate, andterraform plan. - The infrastructure team reviews the execution plan.
- After approval,
terraform applyprovisions the VPC, EKS cluster, RDS database, IAM roles, and Application Load Balancer. - State is stored remotely in Amazon S3 with DynamoDB state locking.
- Kubernetes workloads are deployed using ArgoCD.
- CloudWatch and Datadog monitor infrastructure health.
Quick Revision Cheat Sheet
| Topic | Key Point |
|---|---|
| Terraform | Infrastructure as Code |
| HCL | Configuration Language |
| Provider | Cloud Integration |
| Resource | Infrastructure Object |
| Data Source | Read Existing Resources |
| Variable | Reusable Configuration |
| Output | Display Values |
| State | Infrastructure Record |
| Backend | State Storage |
| Remote State | Team Collaboration |
| State Lock | Prevent Concurrent Updates |
| Module | Reusable Infrastructure |
| Workspace | Multiple Environments |
| Lifecycle | Resource Behavior |
| Terraform Cloud | Managed Terraform |
| Sentinel | Policy as Code |
Interview Tips
Remember these keywords
- Infrastructure as Code
- HCL
- Provider
- Resource
- State
- Backend
- Remote State
- DynamoDB Lock
- Module
- Workspace
- Terraform Cloud
- Terraform Enterprise
- Sentinel
- Drift Detection
- Import
- Lifecycle
- Dependency Graph
- GitOps
Summary
Terraform interviews focus heavily on Infrastructure as Code principles, state management, reusable modules, CI/CD integration, security, and enterprise infrastructure automation. Beyond syntax, interviewers expect candidates to understand how Terraform fits into production environments, including remote state management, policy enforcement, GitOps workflows, and multi-cloud deployments.
Hands-on experience provisioning AWS, Azure, Kubernetes, or OpenShift infrastructure using Terraform will significantly strengthen your ability to answer architecture and troubleshooting questions in DevOps, Platform Engineering, Cloud Engineering, SRE, and Solution Architect interviews.