
40+ [REAL-TIME] Terraform Interview Questions and Answers
Last updated on 18th Nov 2021, Blog, Interview Questions
Terraform Professionals and expert trainers from ACTE systems are providing you with the important questions and answers that might be asked when you face an Terraform Interview. These questions and answers will help you in the preparation of the interview. Questions are relevant to Terraform and its applications. The following list includes the best important Terraform questions for freshers as well as Terraform questions and answers for experienced candidates to help them prepare for the interview. This complete guide of Terraform interview questions will encourage you to crack your Job interview easily.
1. Are callbacks possible with Terraform on Azure?
Ans:
By using the Azure Event Hubs, callbacks are probable on Azure. Terraform’s Azure supplier provides effortless functionality to users. Microsoft Azure Cloud Shell provides an already installed Terraform occurrence.
2. What is Terraform init?
Ans:
Terraform init is a control to initialize an operational index that contains Terraform pattern files. This control can be looped multiple times. It is the first command that should be run after writing the new Terraform design.
3. What is Terraform D?
Ans:
Terraform D is a plugin used on most in-service systems and Windows. Terraform init by default searches next directories for plugins.
4. What do you understand about Terraform in AWS?
Ans:
Terraform is an infrastructure as code tool that permits us to store our Amazon Web Services infrastructure and produce an update. It is comparable to AWS Cloud Formation.
5. Is history the same as it is on the web while using TFS API to provide resources?
Ans:
Yes, the narration is similar to on the web because UI keeps API as the base. The whole thing that is on the UI is availed during other methods and the API
6. Why is Terraform used for DevOps?
Ans:
This is because Terraform manages infrastructure as code. Infrastructure as code is the foundation for DevOps practices such as continuous integration, version control, continuous deployment, and code review.
7. Define null resource in Terraform.
Ans:
null_resource implements standard resource library, but no further action is taken. The triggers argument allows an arbitrary set of values that will cause the replacement of resources when changed.
8. Explain Oracle Cloud Infrastructure.
Ans:
Oracle cloud offered by Oracle Corporation is a cloud computing service providing storage, servers, applications, services, and network through a global network of managed data centers by Oracle Corporation. These services are provisioned on-demand over the Internet by the company.
9. What do you understand about Terraform backend?
Ans:
backend in Terraform is used to determine how an operation is executed and how the state is loaded. Terraform uses the ‘local’ backend by default. The abstraction enables remote execution, non-local file state storage, etc.
10. What is Terraform architecture?
Ans:

11. What are the version controls supported by Terraform besides GitHub?
Ans:
The version controls supported GitLab EE, GitLab CE, and Bucket cloud.
12. What are modules in Terraform?
Ans:
A jug for numerous resources that are used jointly is known as a module in Terraform. The root module includes resources mentioned in the .tf files and is required for every Terraform.
13. Is Terraform usable for an on-prem infrastructure
Ans:
Yes, Terraform can be used for on-prem infrastructure. As there are a lot of obtainable providers, we can decide which suits us the best. All that we need is an API.
14. Does Terraform support multi-provider deployments?
Ans:
Yes, multi-provider deployments are supported by Terraform, which includes on-prem like Openstack, VMware, and we can manage SDN even using Terram too.
15. How is duplicate resource error ignored during Terraform apply?
Ans:
- Delete those resources from the cloud provider(API) and recreate them using Terraform
- Delete those resources from Terraform code to stop its management with it
- Carry out a Terraform import of the resource and remove the code that is trying to recreate them
We can try the following options:
16. Name all version controls supported by Terraform
Ans:
- Azure DevOps Services
- Azure DevOps Server
- Bitbucket Server
- Bitbucket Cloud
- Gitlab EE and CE
- Gitlab.com
- GitHub Enterprise
- GitHub.com (OAuth)
- GitHub.com
The supported version controls are:
17. What are some of the built-in provisioners available in Terraform?
Ans:
- Salt-masterless Provisioner
- Remote-exec Provisioner
- Puppet Provisioner
- Local-exec Provisioner
- Habitat Provisioner
- File Provisioner
- Chef Provisioner
Here is the list of built-in provisioners in Terraform:
18. Which command destroys Terraform managed infrastructure?
Ans:
The given command is used for this purpose:
- Terraform destroy [options] [dir]
19. Tell us about some notable Terraform applications
Ans:
- Software demos development
- Resource schedulers
- Multi-cloud deployment
- Disposable environment creations
- Multi-tier applications development
- Self-service clusters
- Setup of Heroku App
The applications of Terraform are pretty broad due to its facility of extending its abilities for resource manipulation. Some of the unique applications are:
20. What are the components in Terraform?
Ans:

21. What are the components of Terraform architecture?
Ans:
- Sub-graphs
- Expression Evaluation
- Vertex Evaluation
- Graph Walk
- Graph Builder
- State Manager
- Configuration Loader
- CLI (Command Line interface)
- Backend
The Terraform architecture includes the following features:
22. Define Resource Graph in Terraform.
Ans:
resource graph is a visual representation of the resources. It helps modify and create independent resources simultaneously. Terraform establishes a plan for the configuration of the graph to generate plans and refresh the state. It creates structure most efficiently and effectively to help us understand the drawbacks.
23. What is Terragrunt, and what are its uses?
Ans:
- Working with multiple AWS accounts
- Executing Terraform commands on multiple modules
- Keeping our CLI flags DRY
- Keeping our remote state configuration DRY
- Keeping our Terraform code DRY
Terragrunt is a thin wrapper that provides extra tools to keep configurations DRY, manage remote state and work with multiple Terraform modules. It is used for:
24. Explain State File Locking?
Ans:
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.
25. What is Terraform LaC?
Ans:
- LaC is a short form of the term “Infrastructure as Code”. IaC refers to a scheme whereby developers can run and provision the computer data centre’s mechanically instead of getting into a physical process. Terraform, for example, is a case tool of IaC.
26. What do you understand by a Tainted Resource?
Ans:
A tainted resource is a resource that is forced to be destroyed and recreated on the next apply command. When a resource is marked as tainted, the state files are updated, but nothing changes on infrastructure. The Terraform plan shows that help will get destroyed and recreated. The changes get implemented when the next application happens.
27. How to lock Terraform module versions?
Ans:
A proven way of locking Terraform module versions is using the Terraform module registry as a source. We can use the ‘version’ attribute in the module of the Terraform configuration file. As the Github repository is being used as a source, we need to specify versions, branch, and query string with ‘?ref’.
28. What is Terraform Core? Tell us some primary responsibilities of it.
Ans:
- Reading and interpolation of modules and configuration files by Infrastructure as code functionalities
- Resource Graph Construction
- Plugin communication through RPC
- Plan execution
- Management of resource state
Terraform Core is a binary written statically compiled by using the Go programming language. The compiled binary offers an entry point for the users of Terraform. The primary responsibilities include:
29. Give the Terraform configuration for creating a single EC2 instance on AWS.
Ans:
- provider “aws” {
- region = “”}
- resource “aws_instance”
- “example” {
- ami = “”
- instance_type = “”
- tags {
- Name = “example”}
This is the Terraform configuration for creating a single EC2 instance on AWS:
30. Define Terraform enterprise?
Ans:

31. How will you upgrade plugins on Terraform?
Ans:
Run ‘Terraform init’ with ‘-upgrade’ option. This command rechecks the releases.hashicorp.com to find new acceptable provider versions. It also downloads available provider versions. “.Terraform/plugins/<'OS>_<'ARCH>” is the automatic downloads directory.
32. How will you make an object of one module available for the other module at a high level?
Ans:
- Ab output variable is defined in resource configuration.
- Declare the output variable of module_A.
- Create a file variable.tf for module B.
- Establish the input variable inside this file having the same name as the key defined in module_B.
- Replicate the process for making variable available to other modules
33. What are some of the latest Terraform Azure Provider factors?
Ans:
The latest versions involve new data resources and Azurem_batch_certificate, which helps in managing the certificate. This resource is used for controlling the prefix in networking. There is fixing of bugs, and azurerm_app_service has also been enhanced.
34. How will you control and handle rollbacks when something goes wrong?
Ans:
need to recommit the previous code version to be the new and current version in my VCS. This would trigger a Terraform run, which would be responsible for running the old code. As Terraform is more declarative, I will make sure all things in the code roll back to the old code. I would use the State Rollback Feature of Terraform Enterprise to roll back to the latest state if the state file got corrupted.
35. Explain the command Terraform validate in the context of Terraform.
Ans:
- Syntax: Terraform validate [options]
- The following options are available with this command:
- -Json
- -no-color
The Terraform validate command verifies the configuration files in a directory, focusing solely on the configuration and excluding any outside services such as remote state, provider APIs, and so on. Validate performs checks to see if a configuration is syntactically correct and internally consistent, regardless of any variables or current state. As a result, it’s best used for general verification of reusable modules, such as ensuring that attribute names and value types are correct. This command can be executed automatically, for example as a post-save check in a text editor or as a test step for a reusable module in a continuous integration system.
Create output in the machine-readable JSON format, appropriate for integration with text editors and other automated systems. Color is always turned off. If supplied, the output will be colourless.
36. How can you prevent Duplicate Resource Error in Terraform?
Ans:
- By destroying the resource, the Terraform code will no longer manage it.
- By removing resources from APIs
- Importing action will also aid in resource elimination.
Depending on the situation and the necessity, it can be accomplished in one of three ways.
37. What do you understand about remote backend in the context of Terraform?
Ans:
Terraform’s remote backend stores Terraform state and can also conduct operations in the Terraform cloud. Terraform commands such as init, plan, apply, destroy , get, output, providers, state (sub-commands: list, mv, pull, push, rm, show), taint, untaint, validate, and many others can be run from a remote backend. It can be used with a single or several remote Terraform cloud workspaces. You can utilise Terraform cloud’s run environment to conduct remote operations like Terraform plan or Terraform apply.
38. What procedures should be taken to make a high-level object from one module available to the other module?
Ans:
- The first step is to define an output variable in a resource configuration. The scope of local and to a module will not be declared until you define resource configuration details.
- Now you must specify the output variable of module A so that it can be utilised in the setup of other modules. You should establish a fresh new and up-to-date key name, with a value that is equal to the output variable of module A.
- You must now create a file named variable.tf for module B. Create an input variable with the exact same name as the key you defined in module B inside this file. This variable permits the resource’s dynamic setting in a module. Replicate the process to make this variable available to other modules as well. This is because the scope of the variable established here is limited to module B.
The steps to make an object from one module available to the other module at a high level are as follows:
39. When something goes wrong, how will you control and handle rollbacks in Terraform?
Ans:
In our Version Control System, we need to recommit the previous code version to make it the new and current one. This would start the Terraform run command, which would execute the old code. Because Terraform is more declarative, we will 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.
40. What is a Terraform cheat sheet?
Ans:

41. What do you know about Terraform core? What are the primary responsibilities of Terraform core?
Ans:
- Reading and interpolating configuration files and modules using infrastructure as code
- Management of the state of resources
- Resource Graph Construction
- Execution of the plan
- Communication with plugins through RPC
Terraform Core is a binary created in the Go programming language that is statically compiled. The compiled binary is the Terraform command line tool (CLI), which is the starting point for anyone who wants to use Terraform. The source code can be found at github.com/hashicorp/Terraform.
The primary responsibilities of Terraform core includes:
42. Explain State File Locking in the context of Terraform.
Ans:
Terraform’s state file locking method prevents conflicts between numerous users doing the same task by blocking activities on a given state file. When one user unlocks the lock, only the other user has access to that state. Terraform will lock your state for any operations that potentially write state if your backend supports it. This prevents outsiders from gaining access to the lock and corrupting your state. All operations that have the potential to write state are automatically locked. There will be no indication that this is happening. Terraform will not continue if state locking fails. The -lock flag can be used to deactivate state locking for most tasks, although it is not advised. Terraform will send a status message if gaining the lock takes longer than planned. If your backend enables state locking, even if Terraform doesn’t send a message, it still happens.
43. What do you know about Terragrunt? What are its uses?
Ans:
To Keep Our Background Configuration DRY (Don’t Repeat Yourself): By setting your backend configuration once in a root location and inheriting that information in all child modules, Terragrunt helps you to keep it DRY (“Don’t Repeat Yourself”).
To Keep Our Provider Configuration DRY: It might be difficult to unify provider configurations across all of your modules, especially if you wish to alter authentication credentials. You may use Terragrunt to refactor common Terraform code and keep your Terraform modules DRY by using it. The provider configurations can be defined once at a root location, just like the backend configuration.
44. Explain the command Terraform fmt in the context of Terraform?
Ans:
Syntax:
- Terraform fmt [options] DIR
By default, fmt looks for configuration files in the current directory. If the dir option is provided, it will instead scan the specified directory.
The following are the flags that are available:
-list=false – This option doesn’t show files with discrepancies in formatting.
-write=false – This option prevents the input files from being overwritten. (When the input is STDIN or -check, this is implied.)
-diff – Shows the differences in formatting modifications.
-check – Verifies that the input is properly formatted. If all input is properly formatted, the exit status will be 0, else it will be non-zero.
-recursive – Process files from subdirectories as well.
45. What do you mean by a Virtual Private Cloud (VPC)? Which command do you use in Terraform to use a VPC service?
Ans:
Virtual Private Cloud (VPC) is a private virtual network within AWS where you can store all of your AWS services. It will have gateways, route tables, network access control lists (ACL), subnets, and security groups, and will be a logical data centre in AWS. When you create a service on a public cloud, it is effectively open to the rest of the world and can be vulnerable to internet attacks. You lock your instances down and secure them from outside threats by putting them inside a VPC. The VPC limits the types of traffic, IP addresses, and individuals who have access to your instances.
46. Explain the command Terraform taint in the context of Terraform.
Ans:
Syntax:
- Terraform taint [options] address
The address option specifies the location of the infected resource. The following options are available with this command:
-allow-missing – Even if the resource is absent, the command will succeed (exit code 0) if it is supplied. Other scenarios, such as a problem reading or writing the state, may cause the command to return an error.
-lock=false – Turns off Terraform’s default behaviour of attempting to lock the state for the duration of the operation.
-lock-timeout=DURATION – Instructs Terraform to reattempt procuring a lock for a period of time before issuing an error, unless locking is disabled with -lock=false. A number followed by a time unit letter, such as “3s” for three seconds, is the duration syntax.
47. Explain the architecture of Terraform request flow.
Ans:
CLI (Common Language Interface) (command package)
Aside from some early bootstrapping in the root package (not shown in the diagram), when a user starts the Terraform application, execution jumps right into one of the command package’s “command” implementations. The commands.go file in the repository’s root directory contains the mapping between user-facing command names and their respective command package types.
48. Explain the workflow of the core Terraform.
Ans:
Write – Create infrastructure in the form of code.
Plan – Plan ahead of time to see how the changes will look before they are implemented.
Apply – Create a repeatable infrastructure.
49. What do you understand about providers in the context of Terraform?
Ans:
To interface with cloud providers, SaaS providers, and other APIs, Terraform uses plugins called “providers.” Terraform configurations must specify the providers they need in order for Terraform to install and use them. Some providers also require setup (such as endpoint URLs or cloud regions) before they may be used. Terraform may manage a set of resource types and/or data sources that each provider contributes. A provider implements each resource type; Terraform would be unable to manage any infrastructure without them. The majority of service providers set up a specific infrastructure platform (either cloud or self-hosted). Local utilities, such as generating random numbers for unique resource names, can be offered by providers.
50. What is Network Infrastructure Automation with Consul-Terraform-Sync Intro?
Ans:

51. What do you mean by Terraform?
Ans:
Terraform is open-source communication as a system software tool created by HashiCorp. It is an instrument for building, altering, and versioning transportation safely and professionally. Terraform can direct existing and accepted service providers as well as convention in-house solutions.
52. What are the reasons for choosing Terraform for DevOps?
Ans:
- It can do complete orchestration and not just configuration management (like Ansible and Puppet).
- Has amazing support of almost all the popular cloud providers like AWS, Azure, GCP, DigitalOcean etc.
- Easily manages the configuration of an immutable (dynamic) infrastructure.
- Provide immutable infrastructure where configuration changes smoothly.
- Works on HCL (HashiCorp configuration language), which is very easy to learn and understand.
- Easily portable from one provider to another.
- Easy Installation.
Below are the reasons for choosing Terraform for DevOps:
53. How to check the installed version of Terraform?
Ans:
We can use Terraform -version of the command to identify the version which we are running.
54. Describe the working of Terraform core?
Ans:
- Terraform Configuration – It keeps track of the infrastructure detail
- Terraform state – It keeps track of the infrastructure status.
The Terraform core looks at the configuration monitoring and creates analysis and evaluation based on the configuration. It keeps track and compare the versions (current and previous) and then display the output through the terminal.
Terraform core mainly takes two input:
55. Explain the uses of Terraform CLI and list some basic CLI commands?
Ans:
The command-line interface to Terraform is via the Terraform command, which accepts a variety of subcommands such as Terraform init or Terraform plan.
56. How does Terraform help in discovering plugins?
Ans:
The authority “Terraform init” helps Terraform interpret configuration files in the operational directory. Then, Terraform finds out the essential plugins and searches for installed plugins in diverse locations. In addition, Terraform also downloads extra plugins at times. Then, it decides the plugin versions to use and writes a security device file for ensuring that Terraform will employ the identical plugin versions.
57. Can I add policies to the open-source or pro version of Terraform enterprise?
Ans:
You cannot insert policies to the open-source description of Terraform Enterprise. The same also goes for the Enterprise Pro version. The finest version of Terraform Enterprise only could contact the lookout policies.
58. Can Terraform be used for on-prem infrastructure?
Ans:
Yes, Terraform can be utilized for on-prem infrastructure. There are a lot of obtainable providers. You can decide any one of them which suits you most excellent. Many also build client Terraform providers for themselves; all wanted is just an API.
59. What does the following command do?
Ans:
Terraform -version – to check the installed version of Terraform.
Terraform destroys – to destroy the managed infrastructure of Terraform.
Terraform fmt– it is used to rewrite configuration files in a canonical styles and format.
Terraform providers – it gives information of providers working in the current configuration.
60. Define Terraform CI/CD on AWS workshop?
Ans:

61. How would you recover from a failed application in Terraform?
Ans:
You can put your configuration in version control and commit before each change, and then you can use your version control system’s features to revert to an older configuration if needed. You always need to make sure that you recommit the previous version code for it to be the new version in the version control system.
62. What do you mean by Terragrunt, list some of its use cases?
Ans:
- Keep your Terraform code DRY
- Keep your remote state configuration DRY
- Keep your CLI flags DRY
- Execute Terraform commands on multiple modules at once
- Work with multiple AWS accounts
Terragrunt is a thin wrapper that provides extra tools for keeping your configurations DRY, working with multiple Terraform modules, and managing remote state.
Use cases:
63. What is State File Locking?
Ans:
State file locking is a mechanism in Terraform where operation on a specific state file is blocked to avoid conflicts between multiple users performing the same operation. Once the lock from one user is released, then only any other user can operate on that state file after taking a lock on it. This helps in preventing any corruption of the state file. It is a backend operation, so the acquiring of locks on a state file in the 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.
64. What is a Remote Backend in Terraform?
Ans:
The remote backend in Terraform is used to store the state of Terraform and can also run operations in Terraform cloud. Remote backend multiple Terraform commands such as init, plan, apply, destroy (Terraform version >= v0.11.12), get, output, providers, state (sub-commands: list, mv, pull, push, rm, show) , taint, untaint, validate and many more. It can work with a single remote Terraform cloud workspace or even multiple workspaces. For running remote operations like Terraform plan or Terraform apply, you can use Terraform cloud’s run environment.
65. How to prevent Error Duplicate Resource
Ans:
- By deleting the resource so that Terraform code stops managing them.
- By discarding resource from the APIs
- Importing action will also help to eliminate resource
It can be done in three ways depending on the situation and the requirement:
66. What is Terraform and how does it work?
Ans:
Terraform is our tool of choice to manage the entire lifecycle of infrastructure using infrastructure as code. That means declaring infrastructure components in configuration files that are then used by Terraform to provision, adjust and tear down infrastructure in various cloud providers.
67. How does AWS Terraform work?
Ans:
By creating a custom AWS CloudFormation resource for Terraform, you can control your on-premises and public cloud resources programmatically. You can access that resource directly through the CloudFormation console, or through the AWS Service Catalog, which gives you an extra layer of governance and control
68. What is Terraform main TF?
Ans:
Terraform does not use this file, but services like the Terraform Registry and GitHub will display the contents of this file to people who visit your module’s Terraform Registry or GitHub page. main.tf will contain the main set of configuration for your module.
69. What steps should be followed for making an object of one module to be available for the other module at a high level?
Ans:
Following are the steps that should be followed for making an object of one module to be available for the other module at a high level:
First, an output variable to be defined in a resource configuration. Till you do not declare resource configuration details, the scope of local and to a module. Now, you have to declare the output variable of module_A to be used in another module’s configuration. A brand new and latest key name should be created by you and the value should be kept equivalent to the module_A’s output variable.
Now, for module_B you have to create a file variable.tf. Establish an input variable inside this file having exactly the same name as was in the key defined by you in module_B. In a module, this particular variable enables the resource’s dynamic configuration. For making this variable available to some other module also, replicate the process. This is because the particular variable established here have its scope restricted to module_B.
70. What is module Terraform?
Ans:

71. Define null resource in Terraform?
Ans:
The null resource implements the average resource lifecycle but takes no extra action. The trigger argument permits specifying a subjective set of values that, when misrepresented, will cause the reserve to be replaced.
The primary use-case for the null resource is as a do-nothing container for arbitrary actions taken by a provisioner.
72. What do you mean by Terraform cloud?
Ans:
Terraform Cloud is an application that helps teams use Terraform together. It manages Terraform runs in a consistent and reliable environment, and includes easy access to shared state and secret data, access controls for approving changes to infrastructure, a private registry for sharing Terraform modules, detailed policy controls for governing the contents of Terraform configurations, and more.
73. What are the ways to lock Terraform module versions?
Ans:
You can use the Terraform module registry as a source and provide the attribute as ‘version’ in the module in a Terraform configuration file. If you are using the GitHub repository as a source, then you need to specify the branch, version and query string with ‘? ref’.
74. Define Modules in Terraform?
Ans:
A module in Terraform is a jug for numerous resources that are used jointly. The root module is required for every Terraform that includes resources mentioned in the .tf files.
75. Differentiate between Terraform and Ansible.
Ans:
Terraform is a tool for provisioning. | Ansible is a tool for managing configurations. |
It uses a declarative Infrastructure as Code methodology. | It takes a procedural method. |
It’s ideal for orchestrating cloud services and building cloud infrastructure from the ground up. | It is mostly used to configure servers with the appropriate software and to update resources that have previously been configured. |
76. Define IAC?
Ans:
IaC is a short form of the term “Infrastructure as Code”. IaC refers to a scheme whereby developers can run and provision the computer data center’s mechanically instead of getting into a physical process. Terraform, for example, is a case tool of IaC.
77. Name some major features of Terraform?
Ans:
- Execution Plan
- Change Automation
- Resource Graph
- Infrastructure as code
Some of them are:
78. How does Terraform work?
Ans:
Terraform creates an implementation plan, defines what it will do to attain the preferred state, and then executes it to construct the described infrastructure. As the configuration changes, Terraform is talented to decide what changed and generate incremental execution plans which can be practical.
79. Define Terraform provider?
Ans:
Terraform is used to manage and inform infrastructure resources such as bodily machines, VMs, network switches, containers, and more. A provider is accountable for thoughtful API interactions and revealing resources. Terraform supports a large number of cloud providers.
80. What is Terraform best practices?
Ans:

81. Name some major competitors of Terraform?
Ans:
- Packer
- Cloud Foundry
- Ansible
- Kubernetes
Some of them are:
82. Define Terraform init?
Ans:
- Plugin Installation
- Child Module Installation
- Backend Initialization
Terraform initializes the code using the command Terraform init. This command is used to initialize the working directory containing Terraform configuration files. It is safe to run this command multiple times.
You can use the init command for:
83. What are the key features of Terraform?
Ans:
Infrastructure as Code: Terraform’s high-level configuration language is used to describe your infrastructure in declarative configuration files that are human-readable. You may now generate a blueprint that you can edit, share, and reuse.
Execution Strategies: Before making any infrastructure modifications, Terraform develops an execution plan that describes what it will do and asks for your agreement. Before Terraform produces, upgrades, or destroys infrastructure, you can evaluate the changes.
Graph of Resources: Terraform develops or alters non-dependent resources while simultaneously building a resource graph. This allows Terraform to construct resources as quickly as possible while also providing you with more information about your infrastructure.
84. What are the use cases of Terraform?
Ans:
Setting Up a Heroku App:
Heroku is a prominent platform as a service (PaaS) for hosting web applications. Developers build an app first, then add add-ons like a database or an email service. The ability to elastically scale the number of dynos or workers is one of the nicest features. Most non-trivial applications, on the other hand, quickly require a large number of add-ons and external services.
Terraform may be used to codify the setup required for a Heroku application, ensuring that all essential add-ons are present, but it can also go beyond, such as configuring DNSimple to set a CNAME or configuring Cloudflare as the app’s CDN. Best of all, Terraform can achieve all of this without using a web interface in about 30 seconds
85. Is it feasible to use Terraform on Azure with callbacks? Sending a callback to a logging system, a trigger, or other events, for example?
Ans:
Yes. Azure Event Hubs can be used to accomplish this. This capability is now accessible in the Terraform AzureRM provider. Terraform’s Azure supplier provides users with simple functionality. Microsoft Azure Cloud Shell includes a Terraform occurrence that has already been setup.
86. What do you mean by Terraform init in the context of Terraform?
Ans:
- Terraform init [options]
- The following options can be used in conjunction with the init command
- -input=true: This option is set to true if the user input is mandatory. If no user input is provided, an error will be thrown.
- -lock=false: This option is used to disable the locking of state files during state-related actions.
- -lock-timeout=
: This option is used to override the time it takes Terraform to get a state lock. If the lock is already held by another process, the default is 0s (zero seconds), which results in an immediate failure. - -no-color: This option disables the color codes in the command output.
- -upgrade: This option can be chosen to upgrade modules and plugins throughout the installation process.
The Terraform init command creates a working directory in which Terraform configuration files can be found. After creating a new Terraform configuration or cloning an old one from version control, run this command first. It is safe to use this command more than once. Despite the fact that successive runs may result in errors, this command will never overwrite your current settings or state.
Syntax:
Ans:
87. Why is Terraform preferred as one of the DevOps tools?
Ans:
Terraform allows you to specify infrastructure in config/code, making it simple to rebuild, alter, and track infrastructure changes. Terraform is a high-level infrastructure description.
While there are a few alternatives, they are all centred on a single cloud provider. Terraform is the only powerful solution that is totally platform-neutral and supports different services.
Terraform allows you to implement a variety of coding concepts, such as putting your code under version control, writing automated tests, and so on.
88. Differentiate between Terraform and Cloudformation.
Ans:
Terraform encompasses numerous Cloud Service Providers such as AWS, Azure, Google Cloud Platform. | While CloudFormation is limited to AWS services. Terraform covers the majority of AWS resources. |
Terraform, on the other hand, saves the state of the infrastructure on the provisioning machine, which can be either a virtual machine or a remote computer. The state is saved as a JSON file, which Terraform uses as a map to describe the resources it manages. | Because CloudFormation is an AWS managed service, it examines the infrastructure on a regular basis to see if the provisioned infrastructure is still in good shape. If anything changes, CloudFormation receives a thorough response. |
89. Mention some of the major competitors of Terraform.
Ans:
- Azure Management Tools.
- Morpheus.
- CloudHealth.
- Turbonomic.
- CloudBolt.
- Apptio Cloudability
- Ansible
- Kubernetes
- Platform9 Managed Kubernetes
90. Explain 3-Tier architecture Terraform?
Ans:

91. What do you understand about Terraform Cloud?
Ans:
Terraform Cloud is a collaboration tool for teams using Terraform. It offers easy access to shared state and secret data, access controls for approving infrastructure modifications, a private registry for sharing Terraform modules, full policy controls for managing the contents of Terraform configurations, and more. Terraform Cloud is a hosted service that can be found at https://app.Terraform.io. Terraform allows small teams to connect to version control, share variables, run Terraform in a reliable remote environment, and securely save remote state for free. Paid tiers provide you with the ability to add more than five people, establish teams with varying levels of access, enforce policies before building infrastructure, and work more efficiently.
Large businesses can utilise the Business tier to scale to multiple concurrent runs, establish infrastructure in private environments, manage user access using SSO, and automate infrastructure end-user self-service provisioning.
92. Explain the destroy command in the context of Terraform.
Ans:
The Terraform destroy command is a simple way to eliminate all remote objects maintained by a Terraform setup. While you should avoid destroying long-lived objects in a production environment, Terraform is occasionally used to manage temporary infrastructure for development, in which case you can use Terraform destroy to quickly clean up all of those temporary objects after you’re done.
- Syntax: Terraform destroy [options]
You may also execute the following command to build a speculative destroy plan to see what the effect of destroying might be:
- Terraform -destroy plan
This will launch Terraform Plan in destroy mode, displaying the proposed destroy changes but not allowing you to execute them.
93. What do you understand about Terraform modules?
Ans:
A Terraform module is a single directory containing Terraform configuration files. Even a simple arrangement with a single directory having one or more files can be referred to as a module. The files have the extension .tf. This directory is referred to as the root module when Terraform commands are run directly from it. Terraform commands will only use the configuration files in one location: the current working directory. Your configuration, on the other hand, can employ module blocks to call modules from other directories. When Terraform comes across a module block, it loads and processes the configuration files for that module. A module that is called by another configuration is frequently referred to as that configuration’s “child module.”
94. What are the benefits of using modules in Terraform?
Ans:
Organization of configuration: By grouping relevant portions of your configuration together, modules make it easier to access, understand, and change your configuration. Hundreds or thousands of lines of configuration can be required to establish even moderately complicated infrastructure. You can organise your configuration into logical components by utilising modules.
Encapsulation of configuration: Another advantage of modules is that they allow you to separate configuration into logical components. Encapsulation can help you avoid unforeseen consequences, such as a change to one element of your configuration causing changes to other infrastructure, and it can also help you avoid basic mistakes like naming two resources with the same name.
95. What are some guidelines that should be followed while using Terraform modules?
Ans:
To publish to the Terraform Cloud or Terraform Enterprise module registries, you must use this convention Terraform-<'PROVIDER>–<'NAME>.
Start thinking about modules as you write your setup. The benefits of using modules outweigh the time it takes to utilise them properly, even for somewhat complicated Terraform settings maintained by a single person.
To organise and encapsulate your code, use local modules. Even if you aren’t using or publishing remote modules, structuring your configuration in terms of modules from the start will dramatically minimise the time and effort required to maintain and update your setup as your infrastructure becomes more complicated.