π§± Terraform β 10 General Experience Interview Questions
β Q1 β What is Terraform and why is it used in DevOps?
Terraform is an Infrastructure as Code tool used to provision cloud and platform resources declaratively. It lets you define infra in code and apply it consistently across environments. It supports multiple providers like AWS, Azure, GCP, Kubernetes. Main benefit is repeatability and version control.
β Q2 β What is Terraform state and why is it important?
Terraform state is a file that maps your config to real-world resources. It tracks resource IDs and attributes. Terraform uses it to detect changes and plan updates. Without state, Terraform cannot safely manage existing infra.
β Q3 β Where should Terraform state be stored in production?
State should be stored in a remote backend like S3 with DynamoDB locking. This allows team collaboration and prevents concurrent writes. Local state is unsafe for teams. Remote state also supports versioning and recovery.
β Q4 β What is Terraform plan vs apply?
terraform plan shows what changes will happen before execution. It compares config vs state vs real infra. terraform apply actually creates or modifies resources. Plan is used for review and approval before apply.
β Q5 β What are Terraform providers?
Providers are plugins that let Terraform interact with APIs like AWS, Azure, Kubernetes. Each provider exposes resource types and data sources. You configure provider with credentials and region. Without provider, Terraform cannot manage that platform.
β Q6 β What is a Terraform module?
A module is a reusable Terraform code block that groups related resources. It helps standardize infrastructure patterns. Teams use modules for VPC, EKS, RDS, etc. Modules improve reuse and reduce duplication.
β Q7 β What is variable and output in Terraform?
Variables allow parameterizing configs for reuse across environments. Outputs expose values like IPs or ARNs after apply. Outputs are often used by other modules or CI pipelines. Both improve modular design.
β Q8 β What is terraform init actually doing?
terraform init initializes the working directory. It downloads providers and modules. It configures backend state settings. It must run before plan/apply when config changes.
β Q9 β What is resource dependency in Terraform?
Terraform builds a dependency graph automatically based on references. If resource A uses attribute of B, B is created first. You can also use depends_on explicitly. This ensures correct creation order.
β Q10 β How do you handle multiple environments in Terraform?
Use separate state files and variable files per environment. Can use workspaces or separate backend keys. Often structured as env folders with shared modules. Never share one state across dev and prod.