|
| 1 | +# How to install Terraform |
| 2 | + |
| 3 | +### Installation environment |
| 4 | +- OS: Ubuntu 20.04.6 LTS (on WSL2) |
| 5 | +- Terraform: v1.5.5 (I'm going to install Terrfarom v1.5.5 due to license issue.) |
| 6 | + - See [HashiCorp adopts Business Source License](https://www.hashicorp.com/blog/hashicorp-adopts-business-source-license) |
| 7 | + - See [7. What products will be covered by BSL 1.1 in their next release?](https://www.hashicorp.com/license-faq#products-covered-by-bsl) |
| 8 | + |
| 9 | +### Install Terraform |
| 10 | +```bash |
| 11 | +# Ensure that your system is up to date |
| 12 | +sudo apt-get update |
| 13 | +# Ensure that you have installed the dependencies, such as `gnupg`, `software-properties-common`, `curl`, and unzip packages. |
| 14 | +sudo apt-get install -y software-properties-common gnupg2 curl unzip |
| 15 | + |
| 16 | +### Install Terraform on Linux from tarball |
| 17 | +# Set Terraform version |
| 18 | +TERRAFORM_VERSION="1.5.5" |
| 19 | + |
| 20 | +# Get tarball |
| 21 | +wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip |
| 22 | + |
| 23 | +# Unzip the tarball |
| 24 | +unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip |
| 25 | + |
| 26 | +# Move the terraform binary to `/usr/local/bin` |
| 27 | +sudo mv terraform /usr/local/bin/ |
| 28 | + |
| 29 | +# Make the toll acccessible to all user accounts |
| 30 | +which terraform |
| 31 | + |
| 32 | +# Check the version of Terraform installed |
| 33 | +terraform --version |
| 34 | +``` |
| 35 | + |
| 36 | +#### Verify the installation |
| 37 | +```bash |
| 38 | +terraform -help |
| 39 | +``` |
| 40 | +#### Enable tab completion |
| 41 | +If you use either Bash or Zsh, you can enable tab completion for Terraform commands. |
| 42 | +To enable autocomplete, first ensure that a config file exists for your chosen shell. |
| 43 | + |
| 44 | +```bash |
| 45 | +touch ~/.bashrc |
| 46 | +``` |
| 47 | + |
| 48 | +Then install the autocomplete package. |
| 49 | +```bash |
| 50 | +terraform -install-autocomplete |
| 51 | +``` |
| 52 | + |
| 53 | + |
| 54 | +### Appendix |
| 55 | + |
| 56 | +Ref: [Install Terraform](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli)(official guide to install the latest version of Terraform) |
| 57 | +```bash |
| 58 | +# Ensure that your system is up to date and you have installed 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. |
| 59 | +sudo apt-get update && sudo apt-get install -y gnupg software-properties-common |
| 60 | + |
| 61 | +# Install the HashiCorp [GPG key](https://apt.releases.hashicorp.com/gpg "HashiCorp GPG key"). |
| 62 | +wget -O- https://apt.releases.hashicorp.com/gpg | \ |
| 63 | +gpg --dearmor | \ |
| 64 | +sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg |
| 65 | + |
| 66 | +# Verify the key's fingerprint. |
| 67 | +gpg --no-default-keyring \ |
| 68 | +--keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg \ |
| 69 | +--fingerprint |
| 70 | + |
| 71 | +# Add the official HashiCorp repository to your system. The `lsb_release -cs` command finds the distribution release codename for your current system, such as `buster`, `groovy`, or `sid`. |
| 72 | +echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \ |
| 73 | +https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \ |
| 74 | +sudo tee /etc/apt/sources.list.d/hashicorp.list |
| 75 | + |
| 76 | +# Download the package information from HashiCorp. |
| 77 | +sudo apt update |
| 78 | + |
| 79 | +# Install Terraform from the new repository. |
| 80 | +sudo apt-get install terraform |
| 81 | +``` |
| 82 | + |
| 83 | +#### Verify the installation |
| 84 | +```bash |
| 85 | +terraform -help |
| 86 | +``` |
| 87 | + |
| 88 | +#### Enable tab completion |
| 89 | +If you use either Bash or Zsh, you can enable tab completion for Terraform commands. |
| 90 | + |
| 91 | +To enable autocomplete, first ensure that a config file exists for your chosen shell. |
| 92 | +```bash |
| 93 | +touch ~/.bashrc |
| 94 | +``` |
| 95 | + |
| 96 | +Then install the autocomplete package. |
| 97 | +```bash |
| 98 | +terraform -install-autocomplete |
| 99 | +``` |
0 commit comments