Top Terraform Interview Questions and Answers
The rise of cloud computing has led to a surge in job opportunities, attracting a diverse range of professionals. With its increasing importance across various IT roles, cloud computing has become an essential skill set. Tools like Terraform have gained popularity due to the growing adoption of DevOps practices. As a result, understanding Terraform has become crucial for career advancement in this field. Here’s a curated list of commonly asked Terraform interview questions spanning different expertise levels.
1. What is Terraform?
Terraform is an infrastructure as code tool that allows you to specify cloud and on-premises resources in human-readable configuration files.
2. Who are Terraform’s main competitors?
Ansible, Packer, Cloud Foundry, and Kubernetes.
3. What is a Terraform provider?
A Terraform provider is responsible for API interactions with infrastructure resources like physical computers, VMs, network switches, and containers.
4. What is the Terraform workflow?
The Terraform workflow includes terraform init
, terraform plan
, terraform apply
, and terraform destroy
.
5. Explain the core Terraform workflow.
The core Terraform workflow consists of writing the configuration, planning the execution with terraform plan
, and applying the changes with terraform apply
.
6. Define Terragrunt.
Terragrunt is a thin layer that provides additional features and simplifies the use of Terraform configurations.
7. Explain the Terraform request flow architecture.
The Terraform request flow starts with the CLI, followed by the Backend, Configuration Loader, State Manager, Graph Builder, Graph Walk, and Vertex Evaluation.
8. What Terraform commands are most useful?
Useful Terraform commands include fmt
, init
, validate
, plan
, apply
, destroy
, output
, show
, state
, and version
.
9. Explain Resource Graph in Terraform.
A resource graph is a visual representation of accessible resources showing their interdependencies.
10. What is a Terraform Backend?
A Terraform Backend is a configuration option to store and manage the built infrastructure’s state data.
11. Explain the types of Terraform Backends.
Terraform supports Local Backend and Remote Backend.
12. Does Terraform support deploying multiple providers?
Yes, Terraform supports multi-provider installations.
13. How do you completely remove Terraform-managed infrastructure?
You can completely remove Terraform-managed infrastructure using the terraform destroy
command.
14. What is a “tainted resource” in Terraform?
A “tainted resource” in Terraform refers to a resource that has become inconsistent or corrupted.
15. How can we discover plugins with Terraform?
You can discover plugins with Terraform by running terraform init
.
16. Explain terraform -version
, terraform fmt
, terraform providers
.
terraform -version
identifies the installed Terraform version, terraform fmt
formats configuration files, and terraform providers
displays available providers.
17. Explain terraform validate
.
terraform validate
checks the configuration files for correct syntax and consistency.
18. How do you recover from a failed application in Terraform?
To recover from a failed application in Terraform, you can revert to a previous configuration version in version control.
19. Mention some use cases of Terragrunt.
Terragrunt can be used for DRY Infrastructure Code, Remote State Management, Environment-specific Configuration, and Dependencies Management.
20. Explain the terraform graph
command.
The terraform graph
command generates visual representations of resource dependencies.
21. What is a Terraform Directory?
A Terraform Directory contains all the Terraform configuration files.
22. What are provisioners in Terraform?
Provisioners in Terraform are scripts executed during resource creation or management.
23. What is Terraform Core?
Terraform Core is the essential part of Terraform responsible for core functionalities.
24. What is an external data source in Terraform?
An external data source in Terraform allows using an external program as a data source within Terraform.
25. Define dependencies in Terraform.
Dependencies in Terraform can be defined using depends_on
or relies_on
to specify resource dependencies.
26. What is State File Locking in Terraform?
State File Locking in Terraform prevents simultaneous actions on the same state file to avoid corruption.
27. Mention version control tools supported by Terraform.
Terraform supports version control tools like GitHub, GitLab CE, Bucket Cloud, and GitLab EE.
28. Define Terraform Cloud.
Terraform Cloud is a software enabling collaborative work on Terraform configurations with shared state and policy controls.
29. What are Modules in Terraform?
Modules in Terraform are containers for various resources used in collaboration.
30. How to ignore the error “Duplicate Resource” in Terraform?
To ignore the error “Duplicate Resource” in Terraform, remove the duplicate resources from the Terraform code.
31. What are some notable applications of Terraform?
Notable applications of Terraform include self-service clusters, multi-tier app development, environment creation, and resource allocation.
32. What is the purpose of Terraform in DevOps?
Terraform in DevOps is used for infrastructure provisioning and orchestration across various cloud providers.
33. What are the main characteristics of Terraform?
The main characteristics of Terraform include Infrastructure as Code, Execution Plan, and Resource Graph.
34. What is IaC?
IaC stands for Infrastructure as Code, a method to manage infrastructure using code.
35. Define a null resource in Terraform.
A null resource in Terraform does nothing but can execute arbitrary operations.
36. Is Terraform suitable for on-premise infrastructure?
Yes, Terraform can manage on-premise infrastructure.
37. What are built-in provisioners available in Terraform?
Built-in provisioners in Terraform include Salt-masterless, Puppet, File, Chef, Remote-exec, Local-exec, and Habitat.
38. What are the Elements of Terraform architecture?
The elements of Terraform architecture include Expression Evaluation, CLI, Vertex Evaluation, Sub-graphs, State Manager, Configuration Loader, Graph Walk, Graph Builder, and Backend.
39. What are some recent Terraform Azure Provider features?
Recent Terraform Azure Provider features include additional data resources and improvements in networking.
40. What is the relevance of Terraform variables?
Terraform variables enhance the reusability and flexibility of configurations.
41. Differentiate between terraform plan
and terraform apply
.
terraform plan
establishes an execution plan, while terraform apply
applies the changes.
42. Does Terraform allow managing resources across multiple cloud providers?
Yes, Terraform supports managing resources across multiple cloud providers.
43. How can you destroy infrastructure created with Terraform?
You can destroy infrastructure created with Terraform using the `terraform destroy
44. What does terraform init
do?
terraform init
initializes the working directory for Terraform configuration files and handles plugin installation, child module installation, and backend setup.
45. How does Terraform handle State Management?
Terraform manages state files to track the current state of infrastructure and uses them to apply changes and maintain historical records.
46. Does Terraform allow you to roll back changes?
Terraform does not support rolling back changes directly, but you can revert to a previous state file to restore the previous infrastructure state.
47. What does the “plan refresh” process of Terraform involve?
The “plan refresh” process in Terraform involves comparing configured resources, reading the current infrastructure state, and determining required changes to align with the desired state.
48. What are Terraform workspaces used for?
Terraform workspaces are used to manage multiple instances of infrastructure configurations across different environments without affecting the Terraform state.
49. When are Terraform workspaces beneficial?
Terraform workspaces are beneficial when managing different sets of resources for development, staging, and production environments separately.
50. What is the difference between a Terraform provisioner and a resource?
A Terraform resource defines infrastructure components, while a provisioner executes scripts or commands on those resources to configure or manage them further.