How to Install Terraform on Debian 12

In this guide, we will show you how to install Terraform on Debian 12 system step-by-step.

Terraform is an open-source powerful tool for automating the deployment and management of infrastructure on public and private cloud. It is also Known as infrastructure as code (IaC) tool. If you are running Debian 12 and eager to harness the capabilities of Terraform, then you are in the right place.


  • Pre-Install Debian 12
  • Sudo User with admin rights
  • Internet Connectivity

Installing Terraform on Debian 12

Terraform Debian package is not available in the default package repositories of Debian 12. So, for its installation, we will add official hashicorp apt repository.

1) Add Hashicorp APT Repository

Open the terminal and run following wget and echo command to download gpg key and add apt repository respectively.

$ wget -O- | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
$ echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list


2) Install Terraform on Debian 12 with Apt Command

After adding the Terraform apt repository, we are good to install. Run following apt commands.

$ sudo apt update
$ sudo apt install terraform -y

This command will install latest version of terraform along with all the required dependencies.


Post terraform installation, check its version, run following terraform command.

$ terraform version
Terraform v1.6.4
on linux_amd64

3) Validate Terraform Installation

In order to verify your terraform installation, we will create a demo terraform project and main configuration files under this project. Before jumping into validation, let understand the terraform project files.

  • Main Configuration File ( In this file, we define the resources and settings for our infrastructure.
  • Variable Declaration Files ( : In this file, you can declare input variables and set their default values. Input variables allow you to parameterize your Terraform configuration, making it more flexible.
  • Output Declaration Files ( This file is used to declare output values that can be useful for other Terraform configurations or scripts.
  • Terraform Provider Configuration Files ( In larger projects or environments with multiple providers, you might use a separate file to configure your providers.
  • Terraform State Configuration Files ( This file is used to configure the backend where terraform stores its state. State files keep track of the current state of your infrastructure. Common backends include Amazon S3, Azure Storage, or HashiCorp Terraform Cloud.

Create a demo project with name “terraform_demo” using mkdir command.

$ mkdir terraform_demo
$ cd terraform_demo/

Next, create file with following content.

$ vi
resource "local_file" "linux-distros" {
  filename = "/tmp/distros.txt"
  content = "There are multiple Linux distros like Ubuntu. Debian, RHEL, Rocky Linux & Kali Linux etc"

Save and exit the file.

In the same directory where your file is located, initialize the Terraform project, run below command.

$ terraform init


This command initializes the working directory and downloads the provider plugin (in this case, the local_file provider).

Next run ‘terraform plan’ command to see what exactly resources will be created. It is more of a dry run.


If you are satisfied with the plan and then go ahead and apply the configuration to create resources. Execute “terraform apply” command as shown below:

$ terraform apply

This will prompt you to confirm the action, type “yes” and hit enter.


Once you have verified that terraform is working as expected, you can destroy the resources to clean up:

$ terraform destroy

Terraform will again prompt you to confirm the destruction of resources. Type yes and press Enter.


That’s all from this guide, we believe you have found it informative and useful. Feel free to post your queries and feedback in below comments section.

Also Read: How to Install VirtualBox on Debian 12 Step-by-Step

Share on:

I am a Cloud Consultant with over 15 years of experience in Linux, Kubernetes, cloud technologies (AWS, Azure, OpenStack), automation (Ansible, Terraform), and DevOps. I hold certifications like RHCA, CKA, CKAD, CKS, AWS, and Azure.

Leave a Comment