DEV Community

Cover image for Top 10 Popular Terraform Interview Questions
Archit Sharma
Archit Sharma

Posted on

Top 10 Popular Terraform Interview Questions

Terraform, developed by HashiCorp, has rapidly become a go-to tool for infrastructure as code (IaC) in the world of cloud computing and DevOps.
In this blog post, we'll explore some of the top Terraform questions you might encounter in an interview.

Questions List

What are the key features of Terraform?

  • It can do complete orchestration and not just configuration management (like Ansible and Puppet).
  • Works on HCL (HashiCorp configuration language), which is very easy to learn and understand.
  • Has amazing support of almost all the popular cloud providers like AWS, Azure, GCP etc.
  • Easily manages the configuration of an immutable (dynamic) infrastructure.
  • Provide immutable infrastructure where configuration changes smoothly.
  • Easily portable from one provider to another.

What are the most useful Terraform commands?

  • terraform init - initializes the current directory
  • terraform refresh - refreshes the state file
  • terraform output - views Terraform outputs
  • terraform apply - applies the Terraform code and builds stuff
  • terraform destroy - destroys what has been built by Terraform
  • terraform graph - creates a DOT-formatted graph
  • terraform plan - a dry run to see what Terraform will do

What is Terraform init?

Terraform initialises the code with the command terraform init. This command is used to set up the working directory for Terraform configuration files.

You can use the init command for:

  • Installing Plugins
  • Installation of a Child Module
  • Initialization of the backend

What do you understand by terraform backend?

Terraform Backend is a configuration option in Terraform that allows you to store and manage the state of your infrastructure in a remote or local location. The backend is responsible for storing the state file and providing an interface for reading and writing state data. When you run Terraform, it checks the backend to see if there are any changes to the state file, and if there are, it applies those changes to your infrastructure.

What are modules in Terraform?

Modules are repeatable blocks of Terraform code that we can test, version and reuse to reduce duplication. In a more traditional programming language like Java, for example, Terraform modules would equate to classes or methods

What is a Private Module Registry?

It's a feature from Terraform Cloud that allows you to share Terraform modules across the organization. You can enforce rules or “sentinel policies” on the registry that specify how members of your organization can use the modules.

How to Store Sensitive Data in Terraform?

  • Using Environment Variables
  • Utilizing Terraform Variables
  • Employing Secret Management Tools like HashiCorp Vault, Azure Key Vault, or AWS Secrets Manager.
  • Using Encryption and Secure Storage

Explain State File Locking?

State file locking is a Terraform mechanism in which operations on a specific state file are blocked to avoid conflicts between multiple users performing the same process. When one user releases the lock, then only the other one can operate on that state. This helps in preventing state file corruption. This is a backend operation.

Top comments (0)