DEV Community

Cover image for What is terraform?
Rakesh Suryawanshi
Rakesh Suryawanshi

Posted on • Edited on

What is terraform?

In this blog post series we will learn about terraform right from the beginning, this series contains multiple blog post which you can navigate to specific section if you need.

Let's first of all understand

1. What is Infrastructure as Code

Infrastructure as code (IaC) tools allow you to manage infrastructure with configuration files rather than through a graphical user interface. IaC allows you to build, change, and manage your infrastructure in a safe, consistent, and repeatable way by defining resource configurations that you can version, reuse, and share.

2. What is Terraform?
Terraform allows you to manage your infrastructure with code and configuration called HashiCorp's.
It lets you define resources and infrastructure in human-readable, declarative configuration files, and manages your infrastructure's lifecycle. Using Terraform has several advantages over manually managing your infrastructure:

  • Terraform can manage infrastructure on multiple cloud platforms.
  • The human-readable configuration language helps you write infrastructure code quickly.
  • Terraform's state allows you to track resource changes throughout your deployments.
  • You can commit your configurations to version control to safely collaborate on infrastructure.

3. Install Terraform

Terraform is widely used tool to automate your infrastructure with any cloud provider and its available for Free, you just need to install terraform exe and store in your workstation its really simple.
Terraform installer is version controlled managed by HashiCorp, to download the appropriate version you have to check the terraform documentation.
How to install it ?
There any many ways to install terraform across different operating system (such as Windows, Mac, Linux)

https://learn.hashicorp.com/tutorials/terraform/install-cli

4. Write your first terraform command

Following command can be used to know all the basic commands of terraform

terraform

Main commands:
  init          Prepare your working directory for other commands
  validate      Check whether the configuration is valid
  plan          Show changes required by the current configuration
  apply         Create or update infrastructure
  destroy       Destroy previously-created infrastructure

All other commands:
  console       Try Terraform expressions at an interactive command prompt
  fmt           Reformat your configuration in the standard style
  force-unlock  Release a stuck lock on the current workspace
  get           Install or upgrade remote Terraform modules
  graph         Generate a Graphviz graph of the steps in an operation
  import        Associate existing infrastructure with a Terraform resource
  login         Obtain and save credentials for a remote host
  logout        Remove locally-stored credentials for a remote host
  output        Show output values from your root module
  providers     Show the providers required for this configuration
  refresh       Update the state to match remote systems
  show          Show the current state or a saved plan
  state         Advanced state management
  taint         Mark a resource instance as not fully functional
  test          Experimental support for module integration testing
  untaint       Remove the 'tainted' state from a resource instance
  version       Show the current Terraform version
  workspace     Workspace management

Global options (use these before the subcommand, if any):
  -chdir=DIR    Switch to a different working directory before executing the
                given subcommand.
  -help         Show this help output, or the help for a specified subcommand.
  -version      An alias for the "version" subcommand.
Enter fullscreen mode Exit fullscreen mode

To verify the version of terraform you have installed you can run

terraform version
------------- This should display the output like this -------
Terraform v1.1.2
on windows_amd64
Your version of Terraform is out of date! The latest version
is 1.2.1. You can update by downloading from https://www.terraform.io/downloads.html
Enter fullscreen mode Exit fullscreen mode


`

5. Integrated Development tool

There are many IDE tools which you have use to start development using terraform, even notepad is okay, the most widely used IDE right now is Visual Studio Code, which you can download for free.
With VSCode there are many extensions you can install which can ease you terraform development experience.
following of them I have installed in my VSCode

Image description

Top comments (0)