Terraform Install for Beginners
Stefana Muller
Global Leader of Cloud Infrastructure & Operations | Scaling Applications and Infrastructure | DevOps, Production Engineering & SRE
My new team is all about Terraform from HashiCorp. We often train customers on how to write Infrastructure as Code and the tool seems to do it well for most scenarios.
As I build out new service offerings in this area, I thought I'd learn a bit about this tool so I can speak intelligently about it. I spend a ton of time on the business side of tech and can sometimes go months before touching Terminal or Bash commands. So when I do, I'm usually searching for answers to very basic questions like what are the basic "vi commands" or "how to set a PATH in bash".
After spending 2 hours on Friday night trying to figure out how to set my PATH correctly and follow the supposed "5 minute" instructions from HashiCorp, I realized I was editing the wrong file. For Mac, you want to edit ~/.bash_profile and not ~/.profile.
For those of you dabbling in this area and hitting the same issue, here's a quick video to show you how to set your PATH and move Terraform to the correct directory so that it runs via Terminal.
Basic stuff my friends... but stuff I forget all the time since I don't sit in Bash each day.
Basically, change directories to where your Terraform zip file is located. For me it was in Downloads on my local user (stefana).
$ cd Downloads
Downloads$ unzip terraform_0.11.11_darwin_amd64.zip
Archive: terraform_0.11.11_darwin_amd64.zip
inflating: terraform
Now change directories back to your home directory and check the contents of the existing /bash_profile file using the cat command.
Downloads$ cd
$ cat ~/.bash_profile
export PATH=/usr/local/bin:$PATH
In the video, I already had edited that file so the export line was there. If you don't have it there, here's how to quickly edit the file using vi.
$ vi ~/.bash_profile
Use O to insert a line and type in the export line below:
export PATH=/usr/local/bin:$PATH
Hit ESC, then :wq to save the file.
Now type pwd to remember where you are in Bash :)
$ pwd
/Users/user1
Then type the move command to move the terraform file from the Downloads directory to the /usr/bin/ directory. NOTE: make sure you sub out "/Users/user1" with what returned from above. In the video, mine stated "/Users/stefana/".
$ mv /Users/user1/Downloads/terraform /usr/local/bin/terraform
Now confirm that Terraform will run from Bash by typing in terraform and hitting enter.
$ terraform
You should see this... if you do, you're good to go!
Usage: terraform [-version] [-help] <command> [args]
The available commands for execution are listed below.
The most common, useful commands are shown first, followed by
less common or more advanced commands. If you're just getting
started with Terraform, stick with the common commands. For the
other commands, please read the help and docs before usage.
Common commands:
apply Builds or changes infrastructure
console Interactive console for Terraform interpolations
destroy Destroy Terraform-managed infrastructure
env Workspace management
fmt Rewrites config files to canonical format
get Download and install modules for the configuration
graph Create a visual graph of Terraform resources
import Import existing infrastructure into Terraform
init Initialize a Terraform working directory
output Read an output from a state file
plan Generate and show an execution plan
providers Prints a tree of the providers used in the configuration
push Upload this Terraform module to Atlas to run
refresh Update local state file against real resources
show Inspect Terraform state or plan
taint Manually mark a resource for recreation
untaint Manually unmark a resource as tainted
validate Validates the Terraform files
version Prints the Terraform version
workspace Workspace management
All other commands:
debug Debug output management (experimental)
force-unlock Manually unlock the terraform state
state Advanced state management