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

The "Creating a Managed Repository" 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 a private GitHub repository for managing Terraform automations. The repository can be cloned to your computer using Git or the GitHub CLI. Instructions for installing and setting up the GitHub CLI are also included in this lesson.

Preview
Close

Transcript from the "Creating a Managed Repository" Lesson

[00:00:00]
>> So let's go ahead and keep moving forward. So we just finished, finally, setting up all of our access keys and everything. So that's great. We're ready now to fully get started. And the first thing we're gonna do is we're gonna start by creating our Terraform Cloud Automation.

[00:00:16]
When we look back at our chart, nope, this one, right? The first workspace that we talk about working with is Terraform, right? Because we wanna automate Terraform first. So this is the first repository that we're going to create. Now, you might be like, hey Eric, why are we creating a repository if we want to create Terraform automation?

[00:00:37]
Welcome to my world of the chicken before the egg scenario. So, a lot of the times with infrastructure, you'll find yourself having to create something before you can manage it, right? And that might seem like, duh. But what I actually mean by that is, is sometimes you might have to manually create something and then import it into state so that you can set it up properly.

[00:00:59]
Because, again, something has to create the thing to create the thing, right? And so in this case, we create the thing so the thing can create the things, right? And so we want to create a new repository. So we're actually gonna go to GitHub. Alright, so we're gonna go to GitHub.

[00:01:20]
And we're gonna go to our account. So in the top right hand corner, just click on your profile And then, click on repositories, and then here, click new repository, New, bam right there. So we're gonna create a new manage Terraform Cloud repository. So we're gonna call it fem-eci-terraform-tfe.

[00:01:50]
Let me zoom in a little bit for you guys. Come on now. So that's the name we want to make. You can give it a description if you want or not. It's totally up to you. The main point is, is that this must be done first, again, chicken before the egg scenario.

[00:02:01]
Another reason why we're doing this is we're doing it to create state in Terraform Cloud as well. Right, Terraform Cloud is our remote provider. So we have to actually create automation and run it against Terraform Cloud. So there's two reasons why we have to create this repo first, right?

[00:02:19]
We're gonna work on the main branch for now, but in the future, as I mentioned, we will have PRs and things like that. The next thing you wanna do is you wanna click private. So I would make this private for now. If you want to make it public, you can, but I would just say private for now.

[00:02:35]
I would also say Add README. If you notice when I click Add README, do you see what happens at the bottom there? So this is kind of nice. Which is if you add a readme or a gitignore template or anything like that, it will also initialize your default branch for you.

[00:02:50]
So you don't wanna have to worry about cloning something and then first commits, essentially. This is a nice way of getting around it. And what we're gonna do is we are actually going to add a gitignore. We're gonna add one for Terraform, right? Cuz there's probably a bunch of things that it generates.

[00:03:06]
We don't wanna have to worry about stuff like that. And then we're gonna click Create Repository. Okay, bam. Now you should have your name, then fem-eci-terraform-tfe. Now, one of the things you can do is you can go to wherever you clone your code, right? So go to your terminal and then find a place to put your code, right?

[00:03:34]
For me, I have a really strict way of doing things because I work with so many repositories, and I'll show you my structure now. So I have a development folder in the main route of my home directory. This is where all of my dev code goes. No other part of my system besides things like these dot files and whatnot go.

[00:03:54]
So all my code goes into the home development directory. And it took me a long time to kind of figure out how I wanted to organize things from there, because I'm a kind of person who likes to work in different languages. I'm the kind of person who likes to work with a lot of repositories and I'm also the kind of person that just likes to write really random scripts every now and then.

[00:04:12]
So this is the next layer for me is, do I wanna work in a language and mess around? Do I wanna write a script or do I wanna actually work with a repository? For me, it's a repository, so I'm gonna go to the next thing. Now, I also have in the past, worked with other systems, so like azure.devops.com would be another one in here if your repositories were say, in Azure.

[00:04:36]
So if you were to say, hey Eric, how do you separate repos from provider to provider and know where they are and know which provider it was before? This is how I do it. So that, for example, if we go in GitHub then you'll see another layer, right?

[00:04:51]
This layer, can anyone guess what this layer is?
>> User.
>> User, yeah, user exactly, yeah. Organization or user. And so in this case, we've got ALT-F4, and then we've got my personal one. So for me, my clone path is this. You don't have to do this. Like I said, I'm a bit of an overachiever so it's up to you.

[00:05:12]
You don't really need to but this really has helped me a lot with managing my repositories across many different places. So what I'm going to do and there's two things you can do. You can do git clone and then actually, we'll do git clone. And then we'll go here, click this, and then click this little button right here to copy your code.

[00:05:33]
That's the first thing you can do. Do that should get your code, okay? However, and this is something that I've been messing with more. You can also use GitHub CLI. Now, this was something that I did include in the install, but it's up to you if you wanna use it or not.

[00:05:51]
It's totally up to you. If you do use GitHub CLI, you might have to authenticate. So you would do gh auth, and then you would do login, right? And it's gonna ask you, well, where do you wanna log in, right? You tell Github.com. I'm already logged in. So it just says you're good.

[00:06:10]
I'll hit yes. Now, which do you prefer your protocol for your Git operations. I actually don't prefer HTTPS. I'd much rather use SSH because I'd rather use the key that's on my system. And so I hit SSH and then bam, that's where it actually asks me, okay, cool, what key do you want to use, right?

[00:06:30]
So I hit enter and then get a title for your SSH key. Now, it's actually asking me if I want to upload my key, right? So I've already done that. So I don't have to go through this process. But if I wanted to, I could then upload my key and do it.

[00:06:44]
So if you want you can use GitHub host through this, GitHub CLI through this sign in and use this or you can use the clone action. We're really not gonna be using any of the CLI except for like creating PRs and stuff like that. So let me let me cancel out of this really quickly.

[00:07:05]
Let me go one more time. So get GH off login here. Yes, I wanna re authenticate SSH, skip, right? And then I wanna log in with browser. So here's my one time code. I should then be, Where did sorry, have to answer [LAUGH] There we go. So I paste in my code.

[00:07:32]
I hit Continue, and then asks me, what do I want access to. I click Authorize github. Congratulations, you're all set. Now, I'm logged in as myself, and what's nice is now I can just do repo clone. A little easier, right? A little nicer. So it's up to you.

[00:07:58]
You're welcome to use the normal Git operations, or you can use the GitHub CLI. I personally like to use the GitHub,CLI, so I'm gonna be using that but I can do it in either way.

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