Enterprise DevOps & Cloud Infrastructure

Creating AWS Automation Repos

Erik Reinert

Erik Reinert

TheAltF4Stream
Enterprise DevOps & Cloud Infrastructure

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

The "Creating AWS Automation Repos" 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 uses the GitHub automation repo to create AWS automation repos for networks and clusters. With branch protection enabled, the changes are added to a branch, and a PR is created. Merging the PR will apply the changes in Terraform Cloud.

Preview
Close

Transcript from the "Creating AWS Automation Repos" Lesson

[00:00:00]
>> So we've set up Terraform cloud automation, fantastic, we've also made it so that we have dynamic configuration so that we can add or remove workspaces pretty easily, cool. Then we've set up using VCS tracking so that every workspace we create Knows that it must track a repository so that we have our GitOps paradigm completely standardized.

[00:00:20]
Then we set up our source control automation so that when we wanna create additional automation repositories going forward, we can easily do that. So what do we do next? Well, now we're finally at the fun part, which is we need to create cloud resources, right? Now, with this going forward, this is really going to be the standard process you're going to take to creating resources within this system.

[00:00:46]
It is now set up, right? We've created all the repos, we've done all the importing, we've done all the keying pretty much and everything else. Now there might be additional keys in the future, all right? If it's Amazon or Google or whatever, but the process is pretty much gonna be the same.

[00:01:02]
So the first thing we wanna do is we actually want to go to our GitHub automation because we want to create our repos first, okay? So I'm gonna go to the locals file, here. Now before I do this actually, I wanna create a branch, right, because I can't push the master anymore unless I override it and I just reran my plan.

[00:01:26]
So it's really not gonna let me do that. So you have two options, you can either create a branch if you'd like, which is what I'm gonna go ahead and do. So I'm gonna say git checkout -b, and we'll just call this feature/add-repos, just something simple, right? Now, I'm in a brand new branch, so I do get status.

[00:01:45]
We can see that I'm now in feature/add-repos, right and we wanna add some new repos. I'm gonna say locals. And we're gonna add two new repos. We're actually gonna do all of our automation repos at once for Amazon. Sorry, copied a little too much there. Boy, let me just try that copy one more time.

[00:02:11]
How's that sound? Okay, so let's go here, copy. And again, this is in the same GitHub repo. In the GitHub repo, if you go to the next branch in the GitHub repo automation, this should be there. And so I believe it's five or six, one of the two.

[00:02:33]
>> Set up AWS infrastructure?
>> Yes, yeah. Set up AWS infrastructure. Let me, AWS or GitHub. Yep, so here you go. This is for this, cool. Cool, so again, you can use the second branch set up or the five branch to use this as a reference. And you might want to, for the Amazon part, this one's a little bit easier.

[00:03:08]
But I'll do it as well. So I'll just go to locals, I'm gonna copy both terraform network AWS and cluster. And don't forget we're gonna wanna set these to public. Do not forget to set those to public otherwise you might run into problems. And that's it. Validate, git add locals, git commit, or git status, git commit.

[00:03:40]
Right? Added aws repos, git push, origin, and then we're not gonna push main, we're actually gonna push to our branch. Now, what's really cool about this approach, especially if you use GitHub CLI, you can be really quick with this. So you can be like, all right, I've made my changes, I made my branch, okay, gh pr create.

[00:04:06]
And it will actually help you go through the GitHub Creation PR process, right? This is how I create PRs. And this is why I think if you're using GitHub at least, this is a good approach. Because if not, then your other alternative is to go to the actual repository itself, right?

[00:04:25]
See, I've got a new branch here, compare and pull request, and then open up a pull request for your changes. This is the developer flow now. I'm gonna go here, I'm gonna create one for me, and then I'm just gonna make it so I can do it via CLI, and then I get a nice little URL that it gives me.

[00:04:43]
Now, what's cool, look at that Terraform Cloud is also directly integrated into GitHub. So we have status checks and pipelines built in. So now what I can do is I can click on this little status check right here and then I can actually go to terraform cloud and look at the run for that change.

[00:05:04]
And look at that, my new repos are getting created. And as I said before, you might see bugs like this. It's fine, that's fine, don't worry about that. We know that that's what we wanna set it to, so it's okay. That's a bug in the GitHub repository resource.

[00:05:20]
But these are all brand new, okay? So what does that mean? It's really easy to create repos now. Really easy. I did it in five minutes if not less, right? So what I'm gonna do is, is I'm gonna go back to my pr, just review my changes really quickly, right?

[00:05:40]
And then I'm going to squash and merge. Now, if I go to my main branch, just like the other branches, I should get a status check, right? So if I go to Details for this, This is the actual real apply, right? So it gave us a plan in our branch, but this is where it'll actually give us the ability to confirm and apply.

[00:06:11]
So we're gonna hit Confirm and Apply.
>> Is that because it was on a branch that it didn't do?
>> Yes, exactly.
>> So it recognized that it's not main.
>> Exactly, yeah. That's why it helps with the developer flow, yeah.
>> Yeah. Did we tell it that main is the main branch somewhere?

[00:06:36]
>> In the GitHub organization defaults, it's main. Yeah, they moved from master to main.
>> Now, is this also creating the repo in GitHub?
>> Yeah, it is.
>> Or do we need
>> It is, yeah. So, cuz we just updated the GitHub repo, GitHub automation repo. So now, if I go to my profile, I have six repos now, look at that.

[00:07:09]
I told you we're gonna start cooking. All right, so now we got to fem-eci-terraform-aws-cluster and eci-terrafrom-aws-network. And again, we also know that our source of truth is updated, so we know that it's tracked and it's maintained. Now, I'm just deleting the local branch. That's all I just did, was just to clean up my TFE, GitHub repo, you don't have to do that but it's just something I like to do in the off chance that I create a new branch in the future.

[00:07:36]
You can also do get branch -d feature/add-repos, and then it'll delete it if it's there but I'm gonna go ahead and also pull in main because remember I was on a branch, I wasn't on main. So I got to make sure I come back to main and pull in my changes so that I can continue to automate with the right state.

[00:08:00]
Any questions about that?
>> What if it didn't run when the change was committed?
>> What if it didn't run when the change was committed? You can go into Terraform cloud and manually do a run. Yeah, so if it didn't run for any reason, you can always go into Terraform cloud.

[00:08:20]
Go up in the top right-hand corner and press Start Run. There are some times where GitHub webhooks get weird and that might happen, but I would also make sure that your VCs control is in fact set up.

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