So you have heard great things about Terraform
and infrastructure as code,
but you just don't know where to start.
Well, the first thing you'll need to do
is install the powerful Terraform CLI.
In this video, I'll show you how to install this IaC tool
on Windows, MacOS, and Linux
so you can start your Terraform journey.
But before we jump into installation,
let me explain what makes Terraform and IaC so great
and why you may want to use it.
Now IaC or infrastructure as code
is the process of provisioning and managing infrastructure
through machine-readable configuration files
rather than your normal physical hardware configuration,
or interactive configuration tools.
Terraform is an IaC tool that allows you to build,
change and version infrastructure using Terraform's
high level, human-readable configuration files.
Some of the key benefits of using an IaC tool like Terraform
are as follows - first portability.
You can use one tool to manage and create infrastructure
across multiple providers.
This makes the hassle of switching providers a non-issue.
Flexibility.
With a large community of developers,
the Terraform module and provider registry is vast
and makes Terraform the Swiss army knife of IaC tools.
Next, repeatability.
Since you use code to define the resources,
you can use the same configuration
to deploy multiple environments across multiple providers.
Then finally collaboration.
Since the configuration files are code,
you can use version control to share and collaborate
on the configuration with your team.
Now the first step to using Terraform is installing the CLI.
The Terraform CLI allows the user
to interact with their Terraform configuration files.
Let's run through how to install the CLI on Windows, MacOS,
and Linux.
Here we are at our Windows machine,
I already have the Terraform website brought up.
First thing we wanna do is download our CLI.
We're gonna click the download CLI button.
If you scroll down,
you'll see Windows 64 bit,
we're gonna click on that.
Our zip file is downloading.
I'm gonna go ahead and minimize our browser.
Now we're gonna go into our downloads folder.
Actually before we go there,
we're gonna go ahead and go to our local C drive
and we are going to create a folder,
and we're just going to call it Terraform.
We'll go into our downloads,
we'll unzip our zip file
to extract all.
We're actually gonna tell it,
to put it in our Terraform folder.
We'll say extract.
And once it's finished,
you can see our Terraform binary
is now in our Terraform directory that we created.
Now we're gonna need to add that to our path.
So if we go to the little magnifying glass here,
we start typing in environment,
we wanna click on the system environment variables.
We'll get a systems property window here,
where I come down here to environment variables.
And here you see path,
I'm gonna click on that and hit edit,
and then we're gonna add a new variable,
we're gonna do C:/terraform.
Click okay, then we're gonna hit okay again.
And then we're going to hit okay a third time.
So I'm gonna go ahead and close these screens right here.
Next, we're gonna go to PowerShell.
If we actually want our changes to our path
to work in our PowerShell,
we're gonna actually close that session
and we're gonna open up PowerShell again.
And now we should be able to type in Terraform.
And as you've seen, Terraform has been added to our path
and is working correctly.
Now, if we use the Terraform command
without any other sub commands,
it just gives us a list of all of its commands
that we can use.
Another good way to check to make sure it works,
let me just clear my screen real quick.
Is you can do a terraform --version,
which will show you the version of Terraform
that we're running.
And just like that Terraform is ready
and raring to go on Windows.
(upbeat music)
Now the first thing we'll need to do
is download our Linux binary.
We're back on our Terraform download page.
So if you scroll down here, you see a Linux.
Also, here is the Mac binary as well.
The install for both Linux and Mac are the exact same,
so I'm just going to demonstrate it here
with my Linux machine.
I'm going to right click on the 64 bit link,
and we're gonna copy link address.
And now I'm going to jump over here to my terminal
and we'll do a wget and then paste our address here
to download the zip file.
Next, we wanna put the Terraform binary in our path,
so we'll find a directory in our path
by doing an echo $PATH all in caps.
And here are some of the directories in our path,
I'm gonna use the user bin path
to put our Terraform binary in.
So I'm gonna go ahead and clear my screen.
Now I want to unzip my binary into my user bin path,
so we're gonna do a sudo unzip terraform zip file,
and then -d /usr/bin, hit enter.
Its asking me for my password.
And now Terraform should be unzipped in our usr/bin folder.
We can do an ls -l
to make sure,
if you scroll up just a bit,
little more than a bit I guess,
and there is our terraform binary right here.
Go ahead and clear my screen.
And if we just run the Terraform command,
you can see we correctly placed it within our path,
and it will give you a list of subcommands
that you can use with it.
One of those subcommands is terraform --version,
which will show the version of Terraform that we're running.
Now with Mac and Linux,
there is a cool tool that we could use
if you're a big Bash user and a fan of Bash auto-complete,
there is a terraform auto-complete.
What we'll need to do is we'll need to touch ~/.bashrc,
which will create our .bashrc file.
And then we'll run terraform -install-auto-complete.
So now that I've installed auto-complete,
to use it, I'm going to have to restart my shell.
So let me do that and I'll be back in just a second.
Clear my screen,
and next, we're gonna need to restart our shell.
So we'll do a source ~/. and then bashrc,
which has restarted our bash shell.
So now to use the auto-complete,
we can start typing our command,
say like terraform, hit tab, we'll fill it in.
Say we wanted to do an apply,
we can just type a and hit tab again,
it fills it in for us.
Same thing if we did a terraform
and we did a ve and see it filled in the version for us.
And there we have it, we've installed Terraform on Linux,
as well as the Terraform auto-complete.
Once again, this is the same process
that you would use on MacOS as well,
there's really no difference.
Terraform CLI is a simple, yet powerful way to plan,
execute and delete infrastructure
and resources from a multitude of providers like AWS,
Azure and GCP to name a few.
So that was Terraform CLI in a nutshell.
We installed Terraform CLI on Windows,
as well as MacOS and Linux.
We set our path and verified that it worked
using the Terraform command.
We even enabled the useful Terraform auto-complete
in MacOS and Linux.
Now that we have the CLI installed,
you're all set to start down your Terraform journey
and take advantage of the power of Terraform.
Once you start using Terraform to create
and manage infrastructure and resources,
you'll never go back.
Now, if you enjoyed this episode,
let me know by liking this episode.
If you want to learn more about Terraform,
check out the resources I've listed for you,
including my Terraform course,
or leave a comment
with your Terraform suggestion, I'd love to hear it.
Well that's it for now,
until next time, keep being awesome Gurus.