Terraform Interview Questions

Terraform Interview Questions


Terraform Beginner

Question
Can you explain what is Terraform? How it works?
Read [here](https://www.terraform.io/intro/index.html#what-is-terraform-)
                    

Question
What benefits infrastructure-as-code has?

- fully automated process of provisioning, modifying and deleting your infrastructure
- version control for your infrastructure which allows you to quickly rollback to previous versions
- validate infrastructure quality and stability with automated tests and code reviews
- makes infrastructure tasks less repetitive
                    

Question
Why Terraform and not other technologies? (e.g. Ansible, Puppet, CloufFormation)

A common *wrong* answer is to say that Ansible and Puppet are configuration management tools
and Terraform is a provisioning tool. While technically true, it doesn't mean Ansible and Puppet can't
be used for provisioning infrastructure. Also, it doesn't explain why Terraform should be used over
CloudFormation if at all.

The benefits of Terraform over the other tools:

  * It follows the immutable infrastructure approach which has benefits like avoiding a configuration drift over time
  * Ansible and Puppet are more procedural (you mention what to execute in each step) and Terraform is declarative since you describe the overall desired state and not per resource or task. You can give the example of going from 1 to 2 servers in each tool. In Terraform you specify 2, in Ansible and puppet you have to only provision 1 additional server so you need to explicitly make sure you provision only another one server.
                    

Question
Explain what is "Terraform configuration"
                    

Question
Explain each of the following: * Provider * Resource * Provisioner
                    

Question
What terraform.tfstate file is used for?
It keeps track of the IDs of created resources so that Terraform knows what it is managing.
                    

Question
Explain what the following commands do: * terraform init * terraform plan * terraform validate * terraform apply

terraform init scans your code to figure which providers are you using and download them.
terraform plan will let you see what terraform is about to do before actually doing it.
terraform apply will provision the resources specified in the .tf files.
                    

Question
How to write down a variable which changes by an external source or during terraform apply?
You use it this way: variable “my_var” {}
                    

Question
Give an example of several Terraform best practices
                    

Question
Explain how implicit and explicit dependencies work in Terraform
                    

Question
What is local-exec and remote-exec in the context of provisioners?
                    

Question
What is a "tainted resource"?
It's a resource which was successfully created but failed during provisioning. Terraform will fail and mark this resource as "tainted".
                    

Question
What terraform taint does?
                    

Question
What types of variables are supported in Terraform?
String
Integer
Map
List
                    

Question
What is a data source? In what scenarios for example would need to use it?
                    

Question
What are output variables and what terraform output does?
                    

Question
Explain Modules
                    

Question
What is the Terraform Registry?
                    

Question
Explain remote-exec and local-exec
                    
Advanced

Question
Explain "Remote State". When would you use it and how?
                    

Question
Explain "State Locking"