Updated: Aug 9, 2020

1. What is Terraform?

Terraform is an open-sourceInfrastructure as Code” tool, created by HashiCorp. It is a declarative coding tool, Terraform enables developers to use a high-level configuration language called HCL (HashiCorp Configuration Language) to describe the desired “end-state” cloud or on-premises infrastructure for running an application. It then generates a plan for reaching that end-state and executes the plan to provision the infrastructure.

2. What is use of Terraform CLI?

CLI in terraform is a well-mannered command-line application. In erroneous cases, a non-zero exit status will be returned. CLI also responds to -h and — help as you’d most likely expect. To get help for any particular command, pass the -h flag to the relevant sub-command.

3. Tell some features of Terraform?

Some key features of Terraform:-

1. Infrastructure as Code:- This feature used to infrastructure is described using a high-level configuration syntax. This allows a blueprint of your datacenter to be versioned and treated as you would any other code. Additionally, infrastructure can be shared and re-used. 2. Execution Plans:- The execution plan shows Terraform will do when you call apply. This lets you avoid any surprises when Terraform manipulates infrastructure. 3. Graphing:- Terraform builds a graph of all your resources, and parallelizes the creation and modification of any non-dependent resources. Because of this, Terraform builds infrastructure as efficiently as possible, and operators get insight into dependencies in their infrastructure. 4. Change Automation:- Complex changesets can be applied to your infrastructure with minimal human interaction. With the previously mentioned execution plan and resource graph

5. What are Modules in Terraform?

Terraform modules provide an easy way to abstract common blocks of configuration into reusable infrastructure elements. if you want to write a module, you have to apply the same concepts that you would for any configuration. Modules are collections of .tf files containing resources, input variables, and outputs, which exist outside the root folder of your configuration.

6. Explain the Terraform cloud.

Terraform Cloud is a SaaS that we support — that instead when you run Terraform you still could run it on your local machine, but now it saves and retrieves the state file from Terraform Cloud — which is running over here. We can see who is accessing your state file, control who accesses the state file, and more.

7. How we can check the installed version of Terraform?

To verify your installation and check the version, launch Windows PowerShell and enter: terraform -version.

8. What are terraform Provisioners?

Provisioners are used for executing scripts or shell commands on a local or remote machine as part of resource creation/deletion. They are similar to “EC2 instance user data” scripts that only run once on the creation and if it fails terraform marks it tainted.

9. How can we upgrade plugins on Terraform?

We can modify terraform init ‘s plugin behavior with the following options: -upgrade — Update all previously installed plugins to the newest version that complies with the configuration’s version constraints.

10. Which of the notable applications of Terraform?

Some of the notable applications of Terraform:-

1. Development of multi-tier applications. 2. Heroku App setup. 3. Self-service clusters. 4. Developing software demos. 5. Resource schedulers. 6. Multi-cloud deployment. 7. Creation of disposable environments.

11. Explain the components of Terraform?

Terraform can manage includes low-level components such as compute instances, storage, and networking, as well as high-level components such as DNS entries, SaaS features, etc.

12. What is the use of Terraform CLI? Enlist few major commands?

Terraform is controlled very easily with the command-line interface (CLI). The CLI is a well-mannered command-line application that takes subcommands such as "apply" or "plan". If there is an error, in any case, the CLI returns the non-zero exit status. If you want to view a list of commands supported by Terraform, run terraform with no arguments.

Common Terraform Commands are:

  • Apply: builds or changes infrastructure.

  • Console: Interactive console for Terraform interpolations.

  • destroy: Destroy Terraform-managed infrastructure.

  • env: Workspace management

  • fmt: Rewrites config files to canonical format

  • get: Download and install modules for the configuration

  • graph: Build a visible graph of Terraform resources Import: existing infrastructure into Terraform

  • Init: Initialize a Terraform working directory

  • output: Read output from a state file plan: Generate and show an execution

  • plan validate: Validates the Terraform files

  • version: Prints the Terraform version

  • Workspace: Workspace management

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

A provider is basically liable for exposing resources and understanding of API interactions.

Some Terraform providers are:

· IaaS services: Examples are Alibaba Cloud, AWS, GCP, Microsoft Azure, OpenStack.

· PaaS services: Examples are Heroku.

· SaaS services: examples are Terraform Cloud, Cloudflare, DNSimple.

14. For what provisioners are used in Terraform?

Provisioners can be used to prepare servers or other infrastructure objects for service. It models specific actions on the local machine as well as on remote machines.

15. Enlist some Built-in Provisioners available in Terraform?

Below is the list of some Built-in provisioners in Terraform:

· chef Provisioner

· file Provisioner

· habitat Provisioner

· local-exec Provisioner

· puppet Provisioner

· remote-exec Provisioner

· salt-masterless Provisioner

16. What are Modules in Terraform?

A module in Terraform is a container for several resources that are used together. The root module is compulsory for every terraform that includes resources mentioned in the .tf files.

17. What is the Terraform cloud? Enlist few features provided by it?

Terraform Cloud is an application that let the teams use the Terraform together. It runs in a reliable environment and includes easy access to shared state and secret data. It provides access controls for adopting changes to infrastructure and a private registry for sharing terraform modules.

Features of the Terraform cloud are:

· Audit logging

· SAML single sign-on.

18. How to check the installed version of Terraform?

To check the installed version of Terraform, use the below command:


terraform [-version] [-help] [args]

19. What is a remote backend in Terraform?

A "backend" in Terraform determines how the state is loaded and how an operation such as apply is executed. This abstraction enables non-local file state storage, remote execution, etc.

By default, Terraform uses the "local" backend, which is the normal behavior of Terraform you're used to.

Here are some of the benefits of backends:

Working in a team: Backends can store their state remotely and protect that state with locks to prevent corruption. Some backends such as Terraform Cloud even automatically store a history of all state revisions.

Keeping sensitive information off disk: State is retrieved from backends on demand and only stored in memory. If you're using a backend such as Amazon S3, the only location the state ever is persisted is in S3.

Remote operations: For larger infrastructures or certain changes, terraform apply can take a long, long time. Some backends support remote operations which enable the operation to execute remotely. You can then turn off your computer and your operation will still complete. Paired with remote state storage and locking above, this also helps in team environments.

Backends are completely optional. You can successfully use Terraform without ever having to learn or use backends. However, they do solve pain points that afflict teams at a certain scale. If you're an individual, you can likely get away with never using backends.

Even if you only intend to use the "local" backend, it may be useful to learn about backends since you can also change the behavior of the local backend.

An S3 bucket is one of the most common backends that can be configured.

20. What is a state file locking?

Terraform provides locking to prevent concurrent runs against the same state. Locking helps make sure that only one team member runs the terraform configuration. Locking helps us prevent conflicts, data loss, and state file corruption due to multiple runs on the same state file.

DynamoDB can be used as a locking mechanism to remote storage backend S3 to store state files. The DynamoDB table is keyed on “LockID” which is set as a bucketName/path, so as long as we have a unique combination of this we don’t have any problem in acquiring locks and running everything in a safe way.

To use DynamoDB as a locking mechanism, we first need to create a DynamoDB table, let’s call it “terraform-lock”.

resource "aws_dynamodb_table" "terraform_state_lock" {
  name = "terraform-lock"
  read_capacity = 5
  write_capacity = 5
  hash_key = "LockID"attribute {
  name = "LockID"
  type = "S"


1,210 views0 comments

Subscribe Form

©2020 by Linux Advise