Check out a free preview of the full Enterprise DevOps & Cloud Infrastructure course

The "Configuring an AWS Cluster" Lesson is part of the full, Enterprise DevOps & Cloud Infrastructure course featured in this preview video. Here's what you'd learn in this lesson:

Erik configures the AWS cluster automation and discusses features including domain, environment, instance type, market type, and VPC name. Templates offer structured naming conventions and add ease to automating what would be a complex process using the AWS UI.

Preview
Close

Transcript from the "Configuring an AWS Cluster" Lesson

[00:00:00]
>> So we're gonna go to our cluster repository, right? And again, I would recommend in the browser going to the cluster repository for the course. So that's gonna be aws-cluster. And do the exact same thing before. We're gonna to our branch, setup AWS automation, okay? So again, the branches match so that you know you're on the right thing.

[00:00:38]
So eci-terraform-aws-cluster, right? And then, I'm gonna do the exact same thing I did before, data, lb, main, user_data, and variables. We're gonna create all these. It's a new file, data.tf. And I'm just gonna create them all right now. So I have lb.tf, main.tf, and Variables.tf. Now, I'm using something called nnn, which is a very nice file viewer in the CLI.

[00:01:16]
But you can also just do touch, and then the name to create those. So it's either of the two, whichever you want. So data, Copy, paste, right? Lb, Copy, paste, main, Copy, paste. And I forgot the user data. I think, new file user_data.tpl. Now this is the unique one file that is different than all the other files, because this is an actual template that's gonna get injected into our EC2 instances.

[00:02:01]
So just note that this is actually a template. You don't need to change anything in this file. [LAUGH] Just copy and paste it directly, it knows how to take care of the terraform that it passes. So we do that, and then we go to variables. Let me copy variables.

[00:02:19]
Now I'm gonna stop here because I wanna show you the variables for the cluster, right? We looked at the variables for the service and we said, okay, well, we've got AZs, we've got cider block, we've got other things, right, but what about our cluster? What is our cluster care about, right?

[00:02:38]
Well, for starters, a cluster is actually gonna care about the domain we're on. Why is it gonna care about that? Because our cluster manages all of our load balancing, all of our ingress rules for our load balancers. And so it won't know what domain you're trying to route to unless it is a part of the actual automation, right?

[00:02:56]
So that's gonna be the first thing we're gonna add is our domain. Now again, don't worry about actually making defaults or anything like that, right, just keep it as it is. The next one is environment. This one is probably pretty straightforward, right? This is a cluster for a specific environment.

[00:03:12]
Now you might be like, hey, Eric, why? [LAUGH] You don't have to. If you don't want to, you don't have to. The nice thing about ECS clusters is they're free, because they're not actually anything, right? You pay for the EC2 instances, not the ECS clusters. So in this scenario, you could have a cluster, they're kind of like folders in a bit of a way, where you could have a cluster for dev, a cluster for staging, a cluster for whatever.

[00:03:37]
And that's the paradigm that we're essentially doing here, right? Then we have instance type. You'll notice this has a default. Can anyone guess why I might set a sane default for the instance type?
>> Cost.
>> Cost, yeah, [LAUGH] exactly, yeah, cost. And you might also notice right underneath it, the second thing we're trying to do to save money, which is, we're gonna use spot instances here, right?

[00:04:01]
So just note that this cluster has a domain for it. It has an environment that it's for, it has an instance type that is predefined, it has a market type that is predefined, then then it has a name. So we actually name the cluster, right, and then what's called a vpc_name.

[00:04:18]
Now you might be like, well, what's a VPC? The VPC is created in the network module that we just made. So if we go back to our diagram, technically, it's not just that we're creating a provider network module, but in the same way, and this is something that it was too hard to convey [LAUGH] in a flow chart.

[00:04:41]
But in the same way, it's also a dependency of the cluster workspace, right? So what we're doing is, again, we're using to connect these things together, right? We have a variable in TFE, we have a variable in GitHub, and now we're at the point where we wanna create a bunch of networks and a bunch of clusters, right?

[00:05:05]
So we need to have a sane way of essentially wiring all that together, right? So the network is first, that will create the VPC, everything we need on the lower level, and then the cluster will sit on top of that. So if the cluster sits on top of that, what do you think the services sit on top of?

[00:05:24]
>> The cluster.
>> On top of the cluster, exactly. Layered automation, right? So we're gonna go back here, I'm gonna do a Terraform in it. And then I'm gonna do a validate. Beautiful, okay, cool. So we have an automation setup. Sorry, we have automation setup for our cluster now as well.

[00:05:54]
So I'm gonna get it checked out. I'm gonna create a branch again, call it add resources. Git status, git add data. If you wanna make it a little bit easier, you can just do this, star.tf. That'll add all your TF files for you.
>> No back end yet?

[00:06:13]
No back end?
>> No back end yet. We're never gonna use a back end in these repos, you'll see why in a second. And then add the user TPL. Cool, so we're gonna get commit, this is the flow. Those back ends, you should never have to touch going forward, is what I mean.

[00:06:33]
So those back ends are only there for the bootstrapping. Once we have those, everything is configurable via TerraForm cloud and the automation we've made. So now what we're gonna do is, is we're gonna say, feature added resources. Push, And then gh pr create. Or go to the repo, open up a PR.

[00:06:59]
What's interesting about this? One of the things that's interesting about this is that for starters, we don't see a status check on either of these repos, right? Does anyone know why we don't see status checks on these repos? [INAUDIBLE] Connected.
>> There's no workspace, there's no back. Yeah, there's nothing, yeah, it's just repos right now.

[00:07:21]
But these are automation repos that we know we wanna keep using, right? So that's okay, that's okay. So we're gonna hit squash and merge. Squash, there we go. And then [LAUGH] we will squash and merge our changes, right? So we know we validated them, right? We did a TerraForm validate, oops, that's not what I meant to do.

[00:07:38]
Validate, right, cool. So then I'm going to git checkout main, git pull origin main, and then git branch -d, sorry, added-resources. There we go. Wait, what? Feature. I see. Yeah, it's fine. If you run into that error, it's because we have a terraform.lock file sitting here and it's like, well, I don't wanna delete something that's still there.

[00:08:20]
It's like, [SOUND]. it's okay, just dash d, capital D, and it'll delete it for you. Okay, cool, so I'm gonna pull in really quickly, awesome.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now