In this final video of Section 3 you're gonna put together all the
AWS and terraform knowledge of learned thus far to create your
lab. This setup will serve you for the remainder of this course.
Okay, there are a few things we need to discuss in
do before you can create your infrastructure AWS. The
first thing I assume you've already installed terraform in
the AWS CLI. You would need both applications to
proceed. If you have not done so already, please
pause the video and go do that. Now the two
download links are in the course prerequisites.
We will use terraform to create our lab so you
can focus on building a solid foundation without having to worry
about knowing everything right from the beginning.
The AWS CLI is a command line application that allows
us to communicate with AWS. We will use
this to configure our axis keys that we're going to do later on and
we're going to use AWS CLI and later videos.
Next I assume you have cloned the git repository that is
in the course prerequisites this repository contains all
the terraform files needed to create your lab.
To be able to run terraform and the AWS CLI
you need to have access to aws's apis
AWS users can create access keys that
give them permission to do so, you will create access keys
to populate a local credential file, which is
read by terraform and AWS CLI.
You will need an SSH key pair so you
can connect with your Linux hose for brevity. I
provided a simple script in the git repository that you can
use to set these up after all that setup is
complete. You will finally get to run a few terraform commands.
They are in it plan and apply these
commands when successful should create
your lab.
Lastly we will verify your ec2 instance was
created and that you can access it over SSH. Let's
get started.
Okay. So here we are back in the AWS console
and instead of going to the normal places. We've
been going to we're gonna go up here to the top right corner, which is
your username and here are mine's obviously the Linux for
cloud devops course.
Click on that and then in this drop down here, you're gonna have a security credentials
link go ahead and click on security credentials.
Okay. So here we are in the root user security credentials page
as you can see the first thing you see is this big
red exclamation point like no MFA for
root user and this is great
advice. There should be MFA activated through user. If
this was not a lab course, I
would tell you this exactly what you should do. So if
you're gonna keep this account after this course is done,
please add MFA to so you
can secure your account the best best way possible, but we
can proceed now with the warning out of the way.
So I want you to scroll down until you see access keys.
And so this is we're going to create it creates two keys
now access key and a secret axis key and we're
going to use both of those later on in the terminal.
But for now, let's go ahead and create click create
access key. Well, we have another warning that
says root users access keys are not best practices or
recommended and while again this is good advice,
but because of the course the nature
of this course and this being a lab it is
okay that we're gonna do this now I after
this is over with the courses over with feel free
to delete the access keys.
Or just deactivate them or just close this
AWS account as well. That way you can keep yourself
as secure as possible. The reason why it's not
the greatest idea is because your root user
has full access to billing and to be able to create your
account. I mean to close your account or change your account so you
don't want those keys falling into someone else's hands because they could do
some damage. But like I said, we're okay doing that
here for our use case if you wanted to do it
the correct way or best practice way if you if you
will is you would create a group you would assign that
group permissions for whatever task that needs to
be done in this case would be to create the infrastructure that terrible needed.
And you would then create a user inside that group
and let's call that user terraform us or whatever and
then for that terraform user you would then create the access
keys and that would be a little bit safer way. That
way you're limiting the destruction that those access keys can do.
There's only there the scoped much closer, but all right
with all that out of the way go ahead and click I understand.
And then click create access key.
Okay, so it brings us to this page showing us. Hey your access
keys are done. Here you two keys.
so
There's two ways you get the keys. You can view them right now in the
page and you'd have to copy and paste or you can download CSV
down here download the CSV. It's
much easier. You can delete the file off your computer later on
but you've only got one shot here to see your secret access key. So
if you show it, you copy it somehow your copy paste buffer
gets messed up. You can't see that key ever again. You'd have to delete this
key and create new ones. So, all right download them.
All right. So we're done in here. So we're
gonna use everything that we're gonna use going forward we're gonna
do is in the terminal. So let's head over to the terminal now.
All right. So here we are on the terminal. So the
first thing we're gonna do is we're gonna use those
access Keys. We just created to set up our credential file and
our access for terraform.
So if you recall.
The file in my case was called root c a root
key dot CSV should be the same in yours if
you did it on the root user.
So as you can see here, it's just a normal CSV file. We have
the you know the key here and then the secret
access key here.
So to write this configuration file
out we could just do it by hand or there's a wizard
way that you can use with the AWS CLI. And
since we're gonna be using this tool later on I thought this would be good introduction for
you.
So AWS command always starts with AWS.
And there's a subcommand called configure and this
is what we're going to use. So go ahead and type those two and then
hit in.
So here the first thing it asks us for is this
axis key. So we're gonna go ahead I'm just gonna cut
and paste.
and do that
The next thing is asking is for is the secret access key and
I'll cut and paste that as well.
Okay, the next question asks is the default region here
since we've done everything in US West 2 you
might as you should keep it as you as let us West 2 unless
you have a reason and our understand why changing this compares to
what where the infrastructure is going to be created.
So I'll hit enter for the default.
And then you have this default output format none. It
could either be Json or text but for our purpose just to
enter for the default.
Okay, so our axis key has been set
up locally. The next thing we want to do is we need to create our SSH
key pair. So once our ec2 instances up
we can connect to it. So I'm going to clear the screen.
And if you remember I said that I've created I've
added a file here for you call create SSH keys.sh.
And we're gonna run that so it's gonna prompt us for a passphrase
and you should always add you should always enter a passphrase
on your your key pair to keep
it secure.
So I'll go ahead and go ahead and run the script now.
Asking me for my passphrase. I will enter one.
Confirm it.
Okay, so
you can see here in this line it your identification
has been saved in lab key pair which is
just local. That's the private key. And then
it says your public key has been saved.
And this dot pub file and so those are
local and then if you remember from the terraform ec2 file
it was looking in that exact spot just a local
for for the public key file and we've
created that. Okay. So with the axis Keys
done, and now the SSH key done, the
next thing to do is actually run terraform. So I
am going to clear the screen once more you can
see a pattern there with clear on the screen.
And the first thing we need to do is we need to initialize this directory for
terraform terraform needs to download the libraries. It
needs to access and communicate with AWS
and so for that to happen, you need
to run the terraform in it command. So we're going to go ahead and run terraform
in it here.
Okay and successful, the biggest thing to take away here is
that it installed the AWS version 4.5.2 and
it's signed by hashicorp hashicorp
is the company that is the Creator and supporter
of terraform. Okay. So the
next thing it doesn't even tell you here in the green try running
plan to see what changes are required for your infrastructure.
And so that's exactly what to do. So the plan command is
great because it gives you a dry run of what possibly could
change if you actually if you
actually go through with it and so for our case, we expect
to see a whole bunch of Creations, right? We're creating this
lab. It's the first time we've ever done this and so
we'll run plan here.
All right. So there's a lot of output here. Don't be
taken back by all these lines and known after Plies. What
I'll do is we'll go over just one of these there's no reason to go
over all of them. You've kind of seen this code before the biggest thing
is it's gonna create eight things. So it's gonna go add
eight things to AWS for us not are gonna
change and it's not gonna destroy any so let's just scroll
up a little bit here. And as you can see the green plus signs
mean creation if it was a destroy you
would see red negative.
So here you can see the resource what you
saw in the terraform files during those other videos.
And here this is just creating our lab VPC and
as if you look at this right column, you can
see like stuff that's filled in this is the stuff that
we provided that was in the file. So it knows
those values before it actually runs them the known
after apply. For example, like an
Arn or the ID down here.
Terraform doesn't know these because Amazon AWS will
create these once the resources created and
so terraform has to wait for this to happen to then
retrieve the IDS to store that state locally for
us.
And as you can see, like all this same values you
saw in the terraform file are here the tags the enable
DNS support Etc. So let's come
down here also to you can see the output here.
This is the IP address the public IP address
the ec2 instance when it's created. This is
that output resour the output directive that
I put in there that will spit this out. So it's easy for
us when it's done we can just ssh in and we get
the IP address right there. Okay. So now it's telling you
hey, if everything looks good in the plan now, you
should run apply. So I am going to clear the
screen once again.
And I'm gonna run apply.
So what we should see here is the exact same output that
we got with the plan. But this time around
we get a pause that says
Only enter s yes, if you accept these and
this is basically making sure that we've double checked
everything and we're not going to do anything harmful to
our environment.
We are pretty sure what we're doing here says
is a new lab and it's all creation. So
we're gonna hit yes and terraform is gonna go create all this
stuff.
As you can see as each line is going
by you can see the resources being created.
And where you see the 10 seconds elapsed still
creating that is because when you spinning up an ec2
instance in AWS, it takes some time for it to come up
and be active and as you can see here, it finished about
22 seconds out after creating it. So we're
completed eight resources were created. And as
you can see here, we have this output down here. This is the public
IP address of our new Linux instance
that we just created so
Let's not wait. Let's try to SSH into that.
And if you recall we have our keep here here.
So what we're gonna do is we're gonna use the SSH command. And
so we're going to use a flag called Dash. I
But the dash I does it instructs SSH
today. Hey, when you connect to this host use this key
and so we are gonna use the
private key because the public key if you recall is
up on our ec2 instance and this is gonna
authenticate us and since we chose Amazon Linux as
our Linux version, the default user is ec2
user.
And we will type that now and then I'm gonna
paste the IP address here. And so this is what your
SSH command's gonna look like to get into our newly
created Linux host. So hit enter.
Here's this asking us. This is the new host. We've never seen it before.
Are you sure you want to continue connecting? Yes, it's okay. So
type in yes.
And so it's asking me for my passphrase that I set on my key pair.
I'll type my passphrase.
And there we go. We are now inside our
brand new created ec2 Linux
instance.
Now I'm not gonna poke around that much in here. And the
reason being is that we're gonna
do a lot more of that in the next section, but I wanted
to have validate that this was up and running. We also I
want to take you back over to the browser so you can see what
it looks like now inside the browser in not
just in the SSH terminal. So let's do that really quick right now.
Okay. So back in the browser in AWS console.
I want to go ahead and just click on ec2. We're just
gonna go look at the ec2 overview.
Here now, you can see that instances running says one. So
let's go ahead and click on instances running.
And it brings us to we have one instance running. We're in
the US West 2 region, which is important.
If let's go ahead and click the checkbox here for our lab one,
which is if you recall what we named it and here's the details page really
quick. What's probably worth mentioning is
you already know the IP address because that well we SSH into you
can see the instance type which we set which is the TCP
micro here. You can see that this is this instance
is running inside the new VPC we created called
lab VPC.
And you can see it's in the subnet lab subnet public one. So everything
that we
Set up in those terraform files all the
end state that we defined is all here
now.
And not much else to go you obviously there's your key
pair that we used.
We'll dive into this Linux more as we
go through later in this course, but I just wanted to show
you both ways. We SSH into it.
And we checked the AWS console. So let's
jump back over and let's let's do a recap and
everything that we did in this video.
We did a lot in this video. So let's go over a few
key aspects that I think are worth talking about. So one
of the first things you did is you created an SSH key pair
that you used to connect to your ec2 instance. You also
created access keys that AWS CLI
and terraform used
to create all our infrastructure. You got
to run the in it plan and apply commands for
terraform that created your infrastructure.
Finally you verified that your lab one ec2
instance was created and usshed into
it.
Alright, congratulations, you have completed
creating the lab portion of this course.
I know the section was on the long side, but I wanted to make sure you
had a good look at both the infrastructure's code and how they map to
the AWS console. I find this is very important for you
going forward.
You now have the necessary tools to continue in the next section.
Speaking of the next section you'll be learning Linux Administration
operations in the cloud by leveraging your newly created
lab environment. We'll see you there.