Table of Contents
ToggleTerraform helps to define cloud and on-prem resources using configuration file that are readable by humans.It provides version control, consistent workflow to provision and manage all of your infrastructure. So if you are appearing for dev ops role interview, there are high chances interviewer can asked these Terraform Interview Questions.
Let’s look at some of the most Frequently asked Terraform Interview Questions.
Terraform Interview Questions.
1. What are the most useful Terraform commands?
Some of the important terraform commands are:
Command | Function it performs |
terraform init | Prepare your working directory for other commands |
terraform plan | Show changes required by the current configuration |
terraform apply | Create or update infrastructure |
terraform destroy | Destroy previously-created infrastructure |
2. What do you mean by term null resource in Terraform?
Null Resource: It allows to configure provisioners not directly associated with a single existing resource. It follows standard lifecycle and can configure provisioners, connection details, and other meta-parameters like other resources but it doesn’t take additional actions. The null resource’s primary application is as a do-nothing container for arbitrary actions performed by a provisioner.
3. What does the command terraform validate do?
Terraform validate command examines configuration file and inspects whether it is syntactically correct and internally consistent, regardless of variables or current state. It can be executed automatically, such as a post-save check in a text editor or a test step in a continuous integration system for a reusable module.
4. Explain State File Locking?
To prevent multiple concurrent operations from different users on same file and to prevent file from being corrupt, terraform uses state file locking mechanism.Unless the lock has not been released, other users cannot perform operations on it.
5. What are the components that makeup Terraform’s architecture?
The following components are included in the Terraform architecture:
Sub-graphs |
Evaluation of Expression |
Evaluation of the Vertex |
Configuration Loader |
CLI (Common Line Interface) |
Backend |
Walk the Graph |
Builder of Graphs |
State Manager |
6. What are the different degrees of Sentinel policing?
Various degrees of Sentinel policing are
Policy | Roles |
Advisory | When a user initiates a plan that violates the rules, an advisory is sent. |
Soft Mandatory | Unless an override is stated, the policy must pass. Overrides are only available to administrators. |
Hard Mandatory | The policy must pass regardless of the circumstances. Unless it is abolished, this policy cannot be overridden |
7. What is the use case of Terraform State?
Terraform State maps resources to the configuration thus helping in performance improvement when planning changes for complex infrastructures.
8. Define Provisioners in Terraform?
Provisioners are Terraform resources used to execute scripts as a part of the resource creation or destruction. There are two types of Provisioners in Terraform:
local-exec | It invokes a script on the machine running Terraform. |
remote- exec | Invokes a script on a remote resource after it is created. |
9. What happens when multiple engineers start deploying infrastructure using the same state file?
Terraform have mechanism called state file locking to prevent such scenarios and prevents the state file from getting corrupt.
10. Which command can be used to preview the terraform execution plan?
The terraform plan
command generates the execution plan of the changes Terraform will do to the infrastructure.
11. Differentiate between Terraform and Ansible.
Feature | Terraform | Ansible |
---|---|---|
Purpose | Provisioning and orchestration | Configuration and adding software |
Approach | It follows a declarative Infrastructure as a Code approach. | It follows a procedural approach. |
Network | Best for building services from the ground up | Works best on an existing network |
Mutable | No | Yes |
Packaging and Templating | It does not provide better support in terms of packaging and templating. | It provides full support for packaging and templating. |
Lifecycle Management | Depends on lifecycle or state management. | Does not have lifecycle management at all. |
12. How does Terraform control and handle rollbacks ?
To control and handle rollbacks:
- Recommit the previous code version to make it the new and current one
- Because Terraform is more declarative, make sure that everything in the code reverts to its previous state.
- If the state file becomes corrupted, we would use Terraform Enterprise’s State Rollback feature to restore the previous state
Conclusion
In this article we most Frequently asked Terraform Interview Questions.
Checkout Other commonly asked questions here
Got a question or just want to chat? Comment below or drop by our forums, where a bunch of the friendliest people you’ll ever run into will be happy to help you out!