Top Terraform Interview Questions (2021) | CodeUsingJava
















Most frequently asked Terraform Interview Questions


  1. What is Terraform?
  2. What are the features of Terraform?
  3. What are the two components of terraform?
  4. How are data sources used in Terraform?
  5. Why is Terraform Used for DevOps?
  6. Name some competitors of Terraform?
  7. Explain the architecture of terraform?
  8. What are the Built-in Provisioners available in Terraform?
  9. What are the commands used by Terraform init?
  10. What are the primary responsibilities of Terraform Core?
  11. What is a provider in Terraform? Enlist some Terraform Providers.
  12. What is the Meaning of Terragrunt?
  13. What do you mean by IaC?
  14. What is use of Terraform CLI?
  15. What are Modules in Terraform?
  16. Why should Terraform be preferred for DevOps?
  17. What is Terraform cloud?
  18. How can we check installed version of Terraform?
  19. What are the major competitors of Terraform?
  20. What is State File Locking?
  21. How to Lock Terraform State with S3 bucket in DynamoDB?
  22. What is a Tainted Resource?
  23. What are the Noteworthy Applications that make Terraform Useful?
  24. How do we create a SSH key in Terraform?
  25. How are data sources used in Terraform?
  26. How to create a folder in an amazon S3 bucket using terraform?


What is Terraform?

Terraform is used managing the service providers by creating, modifying and versioning infrastructure securely and efficiently.It can generating and executing plans for reaching the desired state and then executing for building the desired infrastructure.Terraform is used for building an infrastructure safe and efficient.It can manage the leading and popular services providers as well as custom in house solutions.
Features of Terraform are:
Infrastructure as Code
Execution Plans
Resource Graph
Change Automation

What are the features of Terraform?

Main features of Terraform are as follows:
  • Graphing - used for visualizing the infrastructure
  • Custom Syntax - helps in aiding enhancing efficiency
  • Resource Relationships - helps in understanding resource relationships
  • Updates - helps in adding updates and features by the Open Source Project
  • Improved Maintenance - used for configurating parts and chunks for improving the organization and the maintenance

What are the two components of terraform?


terraform

How are data sources used in Terraform?

Data sources helps us by providing information about entities which are not managed by the current Terraform configuration.Once we figure out a data source we can use it elsewhere in our terraform configuration.

Why is Terraform Used for DevOps?

Terraform is used for developing the infrastructure with a suitable coding structure.It works efficiently and supports all cloud providers such as GCP, Azure, etc.
Terraform is like a puppet and ansible that helps to have control over complete orchestration.
It can be easily managed as it has a dynamic infrastructure as the configuration can be changed smoothly.

Name some competitors of Terraform?

Kubernetes.
Packer.
Cloud Foundry.
Pulumi.
Chef.
Jenkins.
Serverless.

Explain the architecture of terraform?


terraform


What are the Built-in Provisioners available in Terraform?

There are many provisioners available:
chef Provisioner
file Provisioner
habitat Provisioner
local-exec Provisioner
puppet Provisioner

What are the commands used by Terraform init?

Plugin Installation
Child Module Installation
Backend Initialization

What are provisioners in Terraform?

Provisioners are used for executing scripts commands to model specific actions on local machine.Provisioners add complexity to the terraform.

What are the primary responsibilities of Terraform Core?

The primary responsibilities of the Terraform Core are as follows:
  • Resource state management
  • Communication with plugins over RPC
  • Plan execution
  • Infrastructure as code

What is a provider in Terraform? Enlist some Terraform Providers.

Provider is liable for exposing resources and understanding of API interactions. Terraform providers are:
IaaS services : Examples are DigitalOcean, Linode, Rackspace, AWS.
PaaS services : Examples are Google App Engine, Apache Stratos, OpenShift.
SaaS services : Examples are Cisco WebEx, Concur, GoToMeeting.

What is the Meaning of Terragrunt?

Terragrunt is used as a covering layer and is thin in nature, is used to cover terraform.It helps in implementing all the practicies which are advocated and vetted under terraform.
Terragrunt is a one time thing that helps to write codes on terraform and it also deletes the duplicate code.

What do you mean by IaC?

Iac is a system by which all the developers can maintain the computer data centers automatically by not getting into the manual process.
Infrastructure as Code(Iac) is critical for:
Cloud computing
IaaS
DevOps

What is use of Terraform CLI?

Terraform can be easily controlled with the CLI(Command Line Interface), it is a weel mannered CL application which takes subcommands like apply or plan.The list of commands are supported by Terraform and can be run with no arguments.
Common Terraform Commands are:
  • Apply used for building or changing infrastructure
  • Console used for consoling Terraform interpolations
  • Destroy used for destroying Terraform-managed infrastructure
  • env used as Workspace management
  • fmt helps in rewriting config files for canonical format
  • get helps in downloading and installing modules for configuration
  • graph used for building visible graph of Terraform resources
  • Init used for initializing a Terraform working directory
  • Output helps in generating and showing an execution plan
  • validate helps in validating the Terraform files
  • version used for printng the Terraform Version
  • Workspace act as Workspace management

What are Modules in Terraform?

Module acts as a container for multiple resources which are used together, terraform configuration has least one module and known as root module that are consists of the resource known as the : tf files in the main working directory.
The modules helps us by allowing to create logical abstraction on the top of some resource set and also sllows us for grouping resources together and reuse this group later, possibly many times.

Why should Terraform be preferred for DevOps?

Terraform is used as a significant tools in DevOps, and helps in bringing efficiency and quality in the software delivery and is required for making the dilevery smoother, faster and efficient.Terraform helps in automating and also helps in aiding with the infrastructure as code.It is helpful with its availability of implementing all the types of coding operations that are performed.

terraform


What is Terraform cloud?

Terraform Cloud helps in running a reliable environment and also in including easy access for shared dtate and secret data.Terraform Clouds helps in providing access controls for adopting changes for infrastructure and private registry for sharing terraform modules.
Features of the Terraform cloud are:
Audit logging
SAML single sign-on.

terraform


How can we check installed version of Terraform?

We can check the installed version of terraform by using the following command:
terraform [-version] [-help]  [args]


What are the major competitors of Terraform?

Major competitors of Terraform are as follows:
Packer
Cloud Foundry
Ansible
Kubernetes

What is State File Locking?

State File Locking is used by terraform that is used for operation on a specific state file which is blocked for avoiding conflicts between multiple users that are performing the same operation and when the user is released, the other user will operate the state file after taking a lock on it by helping in preventing any corruption of the state file.It acts as a backend operation, so the acquiring of lock on a state file in backend. If it takes more time than expected to acquire a lock on the state file, you will get a status message as an output.

How to Lock Terraform State with S3 bucket in DynamoDB?


terraform


What is a Tainted Resource?

Terraform Tainted Resource are resources which are forced to be destroyed and recreated on the next command, it informs terraform which is a particular object that has become degraded or damaged.It represents the marking the object as tainted in the terraform state and can purpose to replace it in the next plan.We can mark the resource as tainted, nothing can change the infrastructure but the state file is updated with the information.

What are the Noteworthy Applications that make Terraform Useful?

Noteworthy Applications are notable and are broad as for the abilities to terraform.The applications are as follows:
Self-service clusters
Development of multi-tier applications
Creation of environments
Resource scheduling
Developing demo for a software
Heroku app setup

How do we create a SSH key in Terraform?

variable "key_name" {}

resource "tls_private_key" "example" {
  algorithm = "RSA"
  rsa_bits  = 4096
}

resource "aws_key_pair" "generated_key" {
  key_name   = var.key_name
  public_key = tls_private_key.example.public_key_openssh
}

data "aws_ami" "ubuntu" {
  most_recent = true

  filter {
    name   = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
  }

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  owners = ["099720109477"] # Canonical
}

resource "aws_instance" "web" {
  ami           = data.aws_ami.ubuntu.id
  instance_type = "t2.micro"
  key_name      = aws_key_pair.generated_key.key_name

  tags {
    Name = "HelloWorld"
  }
}


How are data sources used in Terraform?

We can use the aws_ami data source and can return an object that you can get information from name, owner_id, description and image_id.

# Find the latest available AMI that is tagged with Component = web
data "aws_ami" "web" {
  filter {
    name   = "state"
    values = ["available"]
  }

  filter {
    name   = "tag:Component"
    values = ["web"]
  }

  most_recent = true
}


How to create a folder in an amazon S3 bucket using terraform?


resource "aws_s3_bucket_object" "folder1" {
    bucket = ""
    acl    = "private"
    key    = "Folder1/"
    source = "/dev/null"
}