Terraform is an open-source infrastructure-as-code software tool created by HashiCorp. It provides users with the ability to spin up, Modify, and version infrastructure as per their requirements. It uses declarative configuration language known as HashiCorp Configuration Language, or optionally JSON to code, which is easy to read and write.
Terraform supports many clouds on which it can build infrastructures. Check out this link for the supported providers.
Terraform consists of two chief components:
- Terraform Core
- Terraform Plugins
Terraform Core: It is written in go language and its main task includes monitoring the reading and interpolating config files, state management, and graphs.
Terraform Plugin: These are executable binaries written in Go that communicate with Terraform. Each plugin is an implementation for a specific service, such as the Azure provider or the cloud-init provider. Terraform currently supports only one type of Plugin called providers.
Installing Terraform:
Ubuntu/Debian
- Install GnuPG and software-properties-common
$ sudo apt-get update && sudo apt-get install -y gnupg software-properties-common
- Install GPG Key
$ wget -O- https://apt.releases.hashicorp.com/gpg | \
gpg --dearmor | \
sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg - Verify Key
$ gpg --no-default-keyring \
--keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg \
--fingerprintThe gpg command output's the key fingerprint
- Install the Hashicrop repository
$ echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \
https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/hashicorp.list - Update the system
$ sudo apt update
- Install Terraform
$ sudo apt-get install terraform
CentOS/RHEL
- Install yum-utils
# sudo yum install -y yum-utils
- Add Hashi Crop Repository
# sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
- Install Terraform
# sudo yum -y install terraform
Fedora
- Install dnf-plugins-core to manage repos
# sudo dnf install -y dnf-plugins-core
-
Add Hasi Crop repo
# sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/fedora/hashicorp.repo
-
Install Terraform
# sudo dnf -y install terraform
Verifying Terraform Installation
You can verify the successful completion of the terraform by checking the installed version or terraform help
$ terraform -version
or
$ terraform -help
Troubleshooting
If you get an error that terraform could not be found Checkout PATH env Variable contents. Make sure the PATH variable contains the directory where Terraform was installed.
Enable tab completion:
Bash:
$ touch ~/.bashrc
$ terraform -install-autocomplete
Zsh: -> I think there is no such shell.. It should be zsh
$ touch ~/.zshrc
$ terraform -install-autocomplete