Terraform lets you safely and consistently manage your infrastructure as codeacross multiple cloud providers. To provision infrastructure with Terraform, youwill write configuration in Terraform's configuration language, configure yourcloud provider credentials, and apply your configuration with the TerraformCommand Line Interface (CLI).
To use Terraform, you first need to install it. HashiCorp distributes Terraformas a binary package. You can also install Terraform using popular packagemanagers.
Install Terraform
HashiCorp distributes Terraform as an executable CLI that you can install onsupported operating systems, including Microsoft Windows, macOS, and severalLinux distributions. You can also compile the Terraform CLI from source if apre-compiled binary is not available for your system.
If you use a package manager to install software on your macOS, Windows, orLinux system, you can use it to install Terraform.
Homebrew is a free and open-source package management systemfor macOS. If you have Homebrew installed, use it to install Terraform from yourcommand line.
First, install the HashiCorp tap, which is Hashicorp's official repository ofall our Homebrew packages.
Chocolatey is a free and open-source packagemanagement system for Windows. If you have Chocolatey installed, use it toinstall Terraform from your command line.
$ choco install terraform
Note
HashiCorp does not maintain Chocolatey or the Terraform package. The latestversion of Terraform is always available for you to download and installmanually. Refer to theManual installation tab below for instructions.
HashiCorp maintains and signs packages for the following Linux distributions.Use the built-in package management system for your Linux distribution toinstall Terraform.
Ensure that your system is up to date and that you have installed thegnupg andsoftware-properties-common packages. You will use these packagesto verify HashiCorp's GPG signature and install HashiCorp's Debian packagerepository.
Other Linux distributions may have pre-built Terraform packages available. Referto your package manager's documentation, or follow the steps above forManualinstallation.
Install theterraform CLI by installing a pre-compiled executable or compilingit from source.
Next, compile the binary. The following command compiles the binary and storesit in$GOPATH/bin/terraform.
$ go install
Finally, make sure that theterraform binary is available on your system'sPATH. This process will differ depending on your operating system.
Print out a colon-separated list of locations in yourPATH.
$ echo $PATH
Move the Terraform executable to one of the listed locations. This commandassumes that the executable is currently in your downloads folder and that yourPATH includes/usr/local/bin. Customize it if your locations are different.
$ mv~/Downloads/terraform /usr/local/bin/
For more detail about adding Terraform to your path, refer to your operatingsystem's documentation.
Print out a semicolon-separated list of locations in yourPATH.
$ path
Move the Terraform executable to one of the listed locations.
HashiCorp regularly releases new versions of Terraform with new features and bugfixes. HashiCorp maintains compatibility between Terraform versions, so aTerraform configuration written for one version of Terraform should continue towork with any later minor version update. Refer to theTerraform compatibilitypromise for more details.
Verify the Installation
Verify that the installation worked by opening a new terminal session andlisting Terraform's available subcommands.
$ terraform -helpUsage: terraform [global options] <subcommand> [args]The available commands for execution are listed below.The primary workflow commands are given first, followed byless common or more advanced commands.Main commands:##...
Add-help to any Terraform command to learn more about what it does andavailable options.
$ terraform plan -help
Enable tab completion
If you use either Bash or Zsh as your command line shell, you can enable tabcompletion for Terraform commands. To enable autocomplete, first ensure that aconfiguration file exists for your chosen shell.
$ touch~/.bashrc
$ touch~/.zshrc
Then install the autocomplete package.
$ terraform -install-autocomplete
After installing autocomplete support, you will need to restart your shell toenable it.
Next steps
Now that you have installed Terraform, you can use it to create and manageinfrastructure with the cloud provider of your choice. Get started with one ofthe following providers:
Build, change, and destroy a virtual cloud network and subnet on Oracle Cloud Infrastructure (OCI) using Terraform. Step-by-step, command-line tutorials will walk you through the Terraform basics for the first time.
Terraform
7 tutorials
Get Started - Google Cloud
Build, change, and destroy Google Cloud Platform (GCP) infrastructure using Terraform. Step-by-step, command-line tutorials will walk you through the Terraform basics for the first time.
Terraform
7 tutorials
Get Started - Docker
Build, change, and destroy Docker infrastructure using Terraform. Step-by-step, command-line tutorials will walk you through the Terraform basics for the first time.
Terraform
8 tutorials
Get Started - Azure
Build, change, and destroy Azure infrastructure using Terraform. Step-by-step, command-line tutorials will walk you through the Terraform basics for the first time.