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

The "Creating the Product Service Repo" 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 creates the automation repository for the service infrastructure. This repository deploys the service repos created by developers.

Preview
Close

Transcript from the "Creating the Product Service Repo" Lesson

[00:00:00]
>> So the repo that we want to create is really the product service repo. So here let's sorry, really quick, Locals, cool. So I created an ECI service repository, right? This is for my actual service, but I have no resources to automate it with, right? I created the service repository first because I wanted to show you guys some of the things that we need.

[00:00:29]
We need a registry, right? We need an image we know that we're building with Docker and we know that we have configuration variables and things like that, right. So the next thing we wanna do is we want to make automation that makes that service deployable. So we're gonna go back to here one more time.

[00:00:44]
And this time we're gonna say fem-eci-terraform-product-, Service, right? And as I was saying before, all of the automation for the service repository that we created will go in here, okay? So I'm gonna quickly delete all of this, and I'm gonna replace it with the stuff that I need.

[00:01:10]
All right, let's get rid of this, get rid of this. And there we go, now I have my Frontend Masters ECI Terraform product service repository as well. And let's make sure that this is public too. Cool, so we added both of them. Now realistically, we could have added both of these simultaneously, but I wanted to show you guys the process of a developer going in and then being like hey, I need to create a service repository, how can I do it?

[00:01:38]
What I just did, was essentially the process to do that. So now that the developers created the service repository, we need to make it so that we can actually create the automation for it. Because it's a little bit like we need them to do their job first before we can do ours, right?

[00:01:52]
So we're gonna say git checkout, nope, sorry, cool. And then let's check our locals really quickly just to make sure that it's in here. Okay, cool. And then git checkout -b added or add-service-automation. Git locals, see feature, added automation repo push, cool. Okay, so we've added our automation repo, I'm gonna do gh pr create.

[00:02:35]
Go like this. And then, of course, because it's connected to Terraform Cloud, it's gonna do a run. So, we've gotta give it a second to do its run. And there we go, beautiful. That looks great. Okay, so let's go ahead and keep moving, squash and merge. And as you can see, my pattern is make some changes, review it in a pr, merge it, and apply it, right?

[00:03:14]
So while that's going, I'm gonna go ahead and just clean this up. So I'm gonna say git checkout main, right, pull. And then get branch -a git branch -d feature/add-service-automation. And let's do a capital D just so that it's all good. Playing finished, fantastic, Confirm & Apply. So we're gonna create our product service repository that will maintain all of our service level automation.

[00:03:47]
So this is the last repo we need. So we're gonna say, eci-terraform-product-service. And you can see it's actually being created underneath my screen, so I can't hit Enter just yet. Cool, now I'm gonna hit Enter. Bam, cuz you can see here it got created. Okay, cool. So let's go ahead and create our product service automation.

[00:04:13]
To do this, you're gonna go back to the example repo, eci-terraform-product-service. So terraform, -product-service. And then we're gonna copy all the stuff in here. And I'm gonna go to the branch 06 setup. Remember, we wanna make sure we follow these branches. So I'm gonna go to module-service. And you'll see here I have a module actually inside of my repository.

[00:04:48]
Now we've been saying module, module, module over, and over, and over again, but this is actually a time where I decided to say, well, I want this repository to not just deploy services to ECS. Maybe in the future I also want this repository to deploy to Google or other things like that.

[00:05:05]
And so you can create these modules for that. So you have a module for ECS, you have a module for Kubernetes, you have a module for other things, and then this can go out and connect to all those things and deploy all of your services to all of its relative providers, right?

[00:05:21]
So what we're gonna do is we're going to create a new directory, we're gonna create a module, just like we have here, all right? And we're gonna create another new directory, ECS service, okay? Now, in this, we have three files, a data file, data.tf, right? Now again, feel free to look at this file if you want, it's got some cool stuff in it, but it's mostly just to make it so that this works the way that we want.

[00:05:47]
Okay, cool. So we're gonna get rid of that. We're gonna close that out, I mean. Then we're gonna do the main. So you'll notice that even in this module, I am still following the conventions of data, main, right, stuff like that. New file, variables, right? Now this is important to note because these are the variables for the service.

[00:06:13]
So we wanna tell it which cluster it's supposed to go into which environment? What's the default image? What's the log retention? What's the name? What's the parameters? What's the secure parameters? And what's the port, right? These are very common, things that you might expect with a service. And so these are things that we want to add as optional parameters, right?

[00:06:35]
So we're gonna go to file variables .tf, and we're gonna paste this in, right?, cool. Okay, so now we have a module folder with all of our ECS relevant deployment infrastructure code, right? So once we have that, then we can go to the root and use it, right.

[00:06:58]
So I'm gonna create a new file main.tf. I'm gonna copy everything that's in here, and I'm gonna paste this. And you'll notice that it's very simple, but look at the source here. This is the important part, the source, right? The source is saying, hey, you gotta go local.

[00:07:15]
You're not gonna go out to any remote connection or anything like that, this is a local module, right? The cluster name, environment, image name these are all, right, parameters to that module that we just made. And look at this, we just saw this in our service repository. So when I told you that you can configure, your service, right, let's go back to the service repository really quick.

[00:07:39]
If we go back to that service repository and we go to configs, look at the values of the configs fem-instructor-Erik, okay? Well, we need an parameter that's an fem-instructor. We need a location, okay? Well, that's got to be another parameter, right, version? Okay, we're literally looking at the code and saying what is this application expecting so that we can create the resources needed for it, right?

[00:08:04]
So it's very easy to do. The only other thing we're gonna do is, we're gonna set the image. And again, that registry that I told you guys about before should be customizable, right? And the off chance that you change registries or you wanted whatever, that can be a variable, the same thing with the environment.

[00:08:21]
So we're gonna do vvariables.tf. And we're going to, whoops, wrong. I'm right or wrong repo, go here. And we're going to paste this in, right? Now, the registry domain in this case, right would be the one in ECR that I showed you. So we'd go back to ECR, and I can just copy this part here, right, this first part here.

[00:08:53]
If you don't see this, you can go to create repository and it'll show you what's there so that you can copy and paste it there. But basically, we're gonna copy and paste that, that is my registry. And I have officially set up my automation for my service, right?

[00:09:10]
Now, I'm not actually going to connect this or anything like that, I'm gonna let terraform do all that for me. But I still wanna do a Terraform valid or Terraform init, right, just to make sure that the initialization works well. And I wanna do a validate too just to make sure that the code validate is fine, right?

[00:09:35]
Cool, okay. So now what we're gonna do is we're going to push these changes up, Okay, so let me just, [INAUDIBLE] one second, trying to catch up with my notes. Cool, okay. So then we're gonna do git checkout -b feature/add-service-automation, sure. We're gonna go ahead and add all of our specific files.

[00:10:03]
Again, you can also do git add main, right, module, so forth and so on, it's up to you. I use lazygit, and then I'm going to just say git commit added resources. And I'm gonna push that up. Oops, cool, so we're gonna do gh pr create. Again, always gonna be using prs, right?

[00:10:30]
That's your flow now. Cool, now, I'm not gonna have automation attached to this right now, and that's fine, totally fine. Let's just review our code. Looks good, looks good, looks good, cool. Okay? And then let's merge it. So we created the repo just like we have before. What else do we need to create?

[00:11:01]
The workspace, right, so we're gonna go back to our Terraform TFE Pull in, Go to locals. And we've got our network now, we've got our cluster now. All right, time to add our service. So I'm going to actually go to my notes. Copy and paste this, paste this in.

[00:11:34]
Oops, I messed up my syntax a bit there. Let me try that paste one more time. There we go. And now here's our service prod. Now let's take a look at this really quick, cuz we had variables here. So let's take a look at these variables. Now you'll see that I've actually got prod in here, because I'm trying to be specific and say, yes, this workspace is for production,right?

[00:12:03]
We've already got execution mode set up, because we know we want it to just go ahead and start running, right? The repo is already there. And then what we're gonna do is we're going to say my name. And then you'll notice that it's got -prod. Now that wasn't in the cluster name, so why are we using it as -prod here?

[00:12:23]
It's up to you, I decided to make this explicit. You could take the environment and then say the name and then it attached prod for you, right, in the logic. However, it's a little bit too much magic for me, I like to know if I wanted to put prod on a different cluster or something like that I could, right?

[00:12:40]
And so the way to know that I am actually looking at the right cluster, is just to go into console,right? And then ECS, right, and then here it is. So fem-eci-ereinert-prod should match fem-eci-ereinert-prod, okay? So I'm gonna validate. Looks good, great, git checkout -b feature/add-service-automation. Lazygit see feature added service automation.

[00:13:15]
And we're gonna push that up as well. Cool, so we're gonna do gh pr create. And then we'll go to the pr. Now again, everything's already wired up, so I'm just gonna come in here and take a quick look. Product service, looks good, cluster name, looks good, prod, looks good, cool, looks good.

[00:13:55]
We got the check mark, we're good to go, squash and merge. Okay, so we've gone ahead and added our workspace. Now we've run into this a few times already. So after we create this workspace, do you think it's gonna work? Right, we just created a workspace for Amazon.

[00:14:12]
Do you think it's gonna work?
>> It's a credentials?
>> Exactly, so this is a common scenario where maybe you start adding the variable sets to the Terraform automation, right? So that then they can automatically be added to the workspaces, right, that's up to you. I just I chose to do it manually for now just so that you guys could see your options there.

[00:14:36]
But yeah, we're gonna need to make sure that the workspace actually gets the AWS credentials after it's created. But again, we're in a chicken before the egg scenario where we have to wait for the workspace to be created to do so. And you'll notice that in this scenario, it's waiting for the configuration actually be pulled in, so it's cloning our repo, and then it's gonna plan and fail.

[00:14:56]
So we're gonna go to Settings one more time, right? We're gonna go to variable sets. We've already got our variable set, but we need to apply it to another repository. And that is, sorry, service-prod, right? So we'll save that variable set. The pipeline is gonna fail, that's fine, cuz it started running before we gave it the credentials, right?

[00:15:19]
So let's go here, new run, and start. Now again, this service has a bunch of different stuff. So it has like an execution policy, it has other execution policies, it has roles, it has parameters, right? It has all these other things that we know we're gonna need that it's just gonna kinda create a out of the box for us.

[00:15:40]
So I'm gonna hit Confirm & Apply. And now, I wanna note, every service going forward has the ability to do everything that all the other services did. So if you have a service that needs different parameters, just give a different parameters, right? If it needs a different image or a different name, just give it a different name.

[00:16:01]
But just like the repositories, right, the services now follow the same standardization of the other ones, right? So what's cool is, is look at that green across the board, awesome. We just finished setting up our service infrastructure automation

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