Enterprise DevOps & Cloud Infrastructure

Configuring an AWS Cluster

Erik Reinert

Erik Reinert

Enterprise DevOps & Cloud Infrastructure

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.


Transcript from the "Configuring an AWS Cluster" Lesson

>> 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.

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.

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.

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.

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?

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?

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.

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.

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?

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.

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.

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?

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?

>> 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.

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?

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.

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.

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.

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.

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.

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