Install Terrafom with Quick start tutorial
- DevOps/DevOps Beginner’s Guide
- DevOps/Terraform Beginner’s Guide
- DevOps/The comparison and introduction between Terraform and Ansible
Ensure that your system is up to date, and you have the gnupg, software-properties-common, and curl packages installed. You will use these packages to verify HashiCorp’s GPG signature, and install HashiCorp’s Debian package repository.
Add the HashiCorp GPG key.
Add the official HashiCorp Linux repository.
Update to add the repository, and install the Terraform CLI.
TIP: Now that you have added the HashiCorp repository, you can install Vault, Consul, Nomad and Packer with the same command.
Verify the installation
Verify that the installation worked by opening a new terminal session and listing Terraform’s available subcommands.
Add any subcommand to terraform -help to learn more about what it does and available options.
If you get an error that terraform could not be found, your PATH environment variable was not set up properly. Please go back and ensure that your PATH variable contains the directory where Terraform was installed.
Enable tab completion for ZSH
You can enable tab completion for Terraform commands.
To enable autocomplete, first ensure that a config file exists for your ZSH shell
Then install the autocomplete package.
Once the autocomplete support is installed, you will need to restart your shell.
Importance NOTE: If you want to use the same configuration on your different computers and VMs, please read Linux/Managing Your Dotfiles With Git and Make .
Quick start tutorial
Now that you’ve installed Terraform, you can provision an NGINX server in less than a minute using Docker on Mac, Windows, or Linux.
To follow this tutorial on Linux, first install Docker Engine for your distribution.
Create a directory named learn-terraform-docker-container.
Then, navigate into it.
Paste the following Terraform configuration into a file and name it main.tf.
Initialize the project, which downloads a plugin that allows Terraform to interact with Docker.
Provision the NGINX server container with apply. When Terraform asks you to confirm type yes and press ENTER.
Verify the existence of the NGINX container by visiting localhost:8000 in your web browser or running docker ps to see the container.
To stop the container, run terraform destroy.
You’ve now provisioned and destroyed an NGINX webserver with Terraform.