Terraform
Terraform is an Infrastructure as Code (IaC) tool for building, changing, and versioning infrastructure safely and efficiently.
Key Concepts
Core Components
- Provider: Plugin that interacts with cloud providers
- Resource: Infrastructure objects (servers, databases, etc.)
- Data Source: Read-only information about existing resources
- Module: Reusable configuration packages
- State: Terraform’s knowledge of managed resources
Workflow
- Write: Define infrastructure in HCL
- Plan: Preview changes before applying
- Apply: Create or modify infrastructure
- Destroy: Remove infrastructure when no longer needed
State Management
- Local State: Stored in local files
- Remote State: Stored in remote backends (S3, Azure Storage, etc.)
- State Locking: Prevents concurrent modifications
- State Backend: Configuration for state storage
Common Interview Questions
- What is Infrastructure as Code and its benefits?
- Explain the difference between Terraform and CloudFormation
- How does Terraform state management work?
- What are Terraform providers and how do they work?
- Explain Terraform modules and their benefits
- How to handle sensitive data in Terraform?
- What is Terraform workspace and when to use it?
- How to implement Terraform best practices?
- Explain Terraform data sources vs resources
- How to handle Terraform state conflicts?
- What are Terraform variables and their types?
- How to implement Terraform remote state?
- Explain Terraform destroy and its implications
- How to handle Terraform version constraints?