Top 100+ Most Asked Terraform Interview Questions

Comprehensive technical guide covering Terraform HCL, State Management, Modules, Providers, and CI/CD best practices.

0%

Overall Progress

0/141

1.What is Terraform?

2.What is Terraform's primary purpose?

3.What is Infrastructure as Code (IaC) and its main benefits?

4.Explain the difference between declarative and imperative IaC.

5.What makes Terraform a cloud-agnostic tool?

6.How does Terraform differ from configuration management tools like Ansible?

7.What is the difference between Terraform and CloudFormation?

8.Who are some key players that compete with Terraform in the infrastructure as code (IaC) market?

9.Can Terraform be utilized to manage infrastructure that is hosted on-premises?

10.Could you describe the different parts that make up Terraform's architecture?

11.Explain the basic structure of a Terraform configuration file.

12.What are the main Terraform configuration files?

13.What is a Terraform provider?

14.What are Terraform providers and resources?

15.What is a resource in Terraform?

16.What is a data source in Terraform?

17.What is the difference between a resource and a data source?

18.Describe the core Terraform workflow.

19.What is the purpose of terraform init?

20.What does terraform init do?

21.Explain what terraform plan does and why it's important.

22.What is terraform apply?

23.What is the difference between terraform apply and terraform apply tfplan?

24.What does terraform destroy do?

25.What are the roles of terraform validate and terraform fmt?

26.What is the function of terraform refresh?

27.What is the terraform state command used for?

28.What is the purpose of the terraform graph command?

29.What does terraform taint do?

30.What is the difference between terraform plan and terraform apply?

31.What is the purpose of the Terraform state file?

32.What is terraform.tfstate?

33.Why is storing state remotely a best practice?

34.What are remote backends in Terraform?

35.How do you manage remote state in Terraform?

36.What is state locking and why is it important for collaboration?

37.How can you lock the Terraform state file?

38.How do you manage state locking and concurrency issues in Terraform when working with large teams?

39.How can you secure sensitive data within the Terraform state file?

40.What happens if you manually edit the terraform.tfstate file?

41.How does Terraform handle resource drift?

42.What are the different backend types available in Terraform?

43.What are variables in Terraform?

44.How do you define variables in Terraform?

45.Explain the difference between input variables and local variables (locals).

46.What are three common ways to assign values to Terraform variables?

47.What is a .tfvars file and how is it used?

48.What are the different variable types in Terraform?

49.How do you pass variables to Terraform?

50.What is the precedence order for variable assignment in Terraform?

51.What are environment variables in Terraform?

52.What is the purpose of output values in Terraform?

53.How do you define outputs in Terraform?

54.When would you use output values?

55.How do you use conditional expressions in Terraform?

56.How can you conditionally create a resource in Terraform?

57.What is the count meta-argument?

58.What is the for_each meta-argument?

59.What is the difference between the count and for_each meta-arguments?

60.When would you choose for_each over count?

61.What are dynamic blocks and provide a common use case?

62.What is a Terraform module and why are they used?

63.Describe the typical file structure of a Terraform module.

64.What is the difference between a root module and a child module?

65.How do you call a module in Terraform?

66.Why is it important to lock module versions, and how do you do it?

67.How do you handle module versioning in Terraform?

68.What are some best practices for Terraform module development?

69.How do you reuse code across multiple Terraform projects?

70.Where can you store and reference Terraform modules?

71.What is the Terraform Registry?

72.How does Terraform handle dependencies between resources?

73.What is implicit dependency in Terraform?

74.What is explicit dependency in Terraform?

75.How do you create explicit dependencies using depends_on?

76.What is the lifecycle block in Terraform?

77.What is the purpose of the lifecycle block in a resource?

78.What are the different lifecycle arguments available?

79.What are Terraform workspaces and how do they differ from modules?

80.When would you use Terraform workspaces?

81.How do you create and switch between workspaces?

82.What is the default workspace in Terraform?

83.What are Terraform provisioners, and why are they considered a 'last resort'?

84.What is the difference between local-exec and remote-exec provisioners?

85.When would you use a provisioner?

86.What are the types of provisioners in Terraform?

87.How do you import existing infrastructure into Terraform?

88.What is the terraform import command?

89.What is a null_resource in Terraform?

90.What is the difference between null_resource and regular resources?

91.What is the difference between null_resource and regular resources?

92.What is a resource target in Terraform and how is it used?

93.How do you perform a rolling update in Terraform?

94.How can Terraform handle and disregard duplicate resource errors when executing a terraform apply command?

95.What is Terraform Cloud?

96.What is the difference between Terraform Cloud and Terraform Enterprise?

97.What are the benefits of using Terraform Cloud?

98.What is Sentinel in Terraform?

99.What is policy as code in Terraform?

100.How do you manage multiple providers in a single Terraform configuration?

101.How do you configure multiple provider instances?

102.What is provider aliasing?

103.How do you implement custom Terraform providers, and when would you need one?

104.What is the Terraform Plugin SDK?

105.How should you manage sensitive information in Terraform?

106.How do you handle secrets in Terraform?

107.What are some security best practices for Terraform?

108.How can you secure the Terraform state file?

109.What is the principle of least privilege in Terraform?

110.How do you debug and troubleshoot Terraform configurations?

111.What environment variables can help with debugging Terraform?

112.How do you enable verbose logging in Terraform?

113.What is TF_LOG and how do you use it?

114.How do you integrate Terraform with CI/CD pipelines?

115.What are the best practices for running Terraform in a CI/CD pipeline?

116.How do you automate Terraform deployments?

117.What are Terraform functions?

118.What are some commonly used Terraform functions?

119.How do you use the lookup function?

120.How do you use the concat function?

121.What is the file function used for?

122.How do you test Terraform configurations?

123.What tools are available for testing Terraform code?

124.What is Terratest?

125.How do you perform unit testing in Terraform?

126.Scenario 1: Handling Manual Changes Outside Terraform. How can you detect and reconcile this change?

127.Scenario 2: A developer mistakenly removed a resource from the config. How can you prevent accidental deletions?

128.Scenario 3: Multiple engineers are applying changes on a shared project causing state conflicts. How can you prevent this?

129.Scenario 4: Your configuration needs database credentials. How should you store and manage sensitive information?

130.Scenario 5: Deployment failed because a dependency was not created in time. How do you ensure correct management?

131.Scenario 6: Modifying a parameter causes Terraform to plan a delete/recreate. How do you avoid downtime?

132.Scenario 7: Each team needs to create an S3 bucket with the same policies. How do you avoid repeating code?

133.Scenario 8: How should you set up a CI/CD pipeline for Terraform?

134.Scenario 9: A Terraform state file became corrupted. How do you recover it?

135.Scenario 10: Your terraform apply fails with an error saying a required resource doesn't exist. How do you troubleshoot?

136.Scenario 11: You need to provision infrastructure across multiple AWS regions. How would you structure your Terraform configuration?

137.Scenario 12: A team member accidentally ran terraform destroy on production. How do you prevent this in the future?

138.Scenario 13: You need to migrate from one backend to another. What are the steps?

139.Scenario 14: Your Terraform state is out of sync with actual infrastructure. How do you fix it?

140.Scenario 15: You need to create 10 identical EC2 instances. What's the best approach?

141.Scenario 16: A resource creation is taking too long and timing out. How do you handle this?