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

The "Configuring a GitHub Workspace" 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 a Terraform automation for the GitHub workspace. Once the workspace is configured, it is committed and pushed to the TFE repo, and Terraform plans the automation. Once the plan is completed, the changes can be applied in Terraform Cloud.

Preview
Close

Transcript from the "Configuring a GitHub Workspace" Lesson

[00:00:00]
>> So here's what we wanna do, right? Now that we've got our repository created we can actually go back to our terraform automation now because half of the work is actually already done, right? So the first part of the work that we did before was like setting up terraform and all that stuff but that's done right, and we just created the repository.

[00:00:20]
So all we really need to do now, right, is add the workspace with its configuration, right? So I'm gonna go to locals, and then I'm going to add a new workspace, let me copy and paste it from over here. I'm gonna add a new workspace. For GitHub, and I'm gonna call it femeci github, right?

[00:00:46]
Now note my little comment there which is I'm setting it to local first. Can anyone tell me or suggest think why am I be doing this?
>> Debugging? Close. Close.
>> There's no state first time.
>> There's no state first time. Exactly, because there's no state or anything like that.

[00:01:04]
Like there's no automation in the repository hasn't been set up yet. There's no environment variables in the cloud, so we know it's gonna fail. So we have to at least start where a scenario where we're not just gonna immediately fail in front. So to do that we're gonna go to now this is where the organization name can actually be super helpful.

[00:01:24]
So you'll see in my first one I have my main name right but in this one I actually am using the organization name. That's because I'm making an opinionation here where I'm saying you know what let's just make it so that every time I wanna use my main organization, I'll just use, the GitHub organization name.

[00:01:46]
So that's why we added it previously. Was this because going forward, I don't wanna like anything that's due. You'll notice that almost nothing here is duplicate. Right, unless we're trying to make it be that. So in this case because we're not, right, we can do that so go ahead and get that in there for me.

[00:02:06]
>> Can you do the curly bracket because that's just string concatenation?
>> Yeah, yeah.
>> Literal?
>> Yeah, it's called string interpolation. But yeah, I'm basically taking the variable and interpolating it into the stream. All right. So the cool part is once the tfe side gets set up, [LAUGH] it's really that.

[00:02:28]
That's it. So now what we can do is what, what would I do here? Would I validate or would I.
>> We've made a new works. We made the new repos. That probably has to be initiated.
>> Sure, but we have to do something in Terraform Cloud first, right?

[00:02:45]
We don't have a workspace yet. I have the code in my repository but would I run a plan here? Would I plan here?
>> Nope. Just commit it.
>> Just commit it. Yeah, exactly. I just commit it, and this is the cycle, right? This is now how it works right commit.

[00:03:06]
Let's validate just to be safe, and then commit, right. So now we're gonna say set up GitHub workspace. All right. Now what's cool is, is again, at this point, Terraform Cloud's completely automated. We don't have to go into Terraform Cloud and make changes manually anymore. So now once I push that up, I should just be able to go back to my projects.

[00:03:46]
And see a new plan. And there it is. There's my new plan. That's the lifecycle. Commit, push, go to Terraform Cloud and check your plan.
>> But what's the local on this new workspace? You mean like what is the definition?
>> No, why did why do we want to be local?

[00:04:04]
I guess I didn't.
>> Because it's a workspace we're creating a TerraForm cloud. Right? So, let's go back to our diagram and maybe this will help it make sense again, right? So there's two components to every workspace that we must have. We must have a workspace and then a repository that it tracks, right.

[00:04:21]
But we're in a situation with both and it's only Terraform and GitHub. Why is it only Terraform in GitHub? Because they're the two things that maintain state, [LAUGH] right? Terraform cloud is the thing that holds the state in the cloud. But then GitHub is the repository that it tracks, right?

[00:04:39]
These are manual processes. Going forward, we'll only gonna create a telephone network and a telephone cluster. We are actually gonna create those at the same exact time. Because we have automation already set up to create multiple work spaces at the same time and now we also have automation to create repositories at the same time, right.

[00:04:56]
So every time we take a step forward and automation, we're making our required work less and less and less right. And so what we're doing is we're first going to terraform cloud to create that because again, what is dependent of what. The workspace is dependent of the repository, so we create the repository first so that it exists, even though it's empty, right?

[00:05:22]
But then we create the workspace so that it can find the repository, even though it's empty, but it can connect and start synchronizing, right? So then I can just start pushing to the GitHub repo. And I don't have to plan like that removed the need for me to go, okay, let's in it, let's plan, let's migrate the state.

[00:05:40]
That doesn't need to be done anymore, right? But we still have to create the main GitHub repo so that everything else can be tracked and managed, right? Yeah, now, as Whisper said, now we're just gonna be flying, and so in this scenario, because I've done that. There it is.

[00:05:56]
There's my workspace, right example workspace for GitHub work resources. There is my repo we know it's created, so we know it shouldn't fail, right? And then we hit Confirm and apply. Now, you'll notice that once it's applied, we have two workspaces now. Terra or fem eci GitHub and fem eci tfp.

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