Time
2 hours 48 minutes
Difficulty
Intermediate
CEU/CPE
3

Video Transcription

00:00
So coming back to the main terra form file, Let's do a little exercise and get you a little hands on.
00:05
We want to go ahead and update the name attributes for the resource so that in, instead of having a hard coded value here, we're gonna have the value of it be derived from resource group name and whatever that variable value is, and we're gonna go ahead and we're gonna save it.
00:25
And
00:26
and so it was a pretty easy process for you. Hopefully, in the auto complete capabilities of the I d. Really helped you get a full bearing off. What are all these variables in this context of the Terra form file? The resource group name.
00:41
Just playing around with this for a second. So I show you a little bit more about the an object.
00:47
Here's an object, and then you can see I had another dot and I've got port in protocol. So when we were talking about, If you have more structured input variables and and you want to try to create a hierarchy tomb, the object type is very powerful. Of course, you can make lists of objects.
01:03
You can create collections if you if you really want to get exotic as well.
01:07
There are several other types of variables that I didn't cover or providing the examples in the reference guide on the get home page, I included a link so you can see the full terra form documentation regarding variables and the different types of variables
01:27
if you're so interested to explore. But the ones I did cover, I think, or your bread and butter
01:33
that you're gonna be using quite frequently
01:37
final stop before we actually start doing some terra form work. Let's just take a little look at this vey net item this resource that we're defining and specifically let's start breaking down some of the the attributes in the value so we can see the location for the V Ned Resource. The value is not hard coded string.
01:57
In fact, I didn't use Varda location,
01:59
which, you can see we did here is we said I want the location of this virtual network to be in the same location as the resource group that we've defined up here. So this is an example of not an input variable so much as I'm making a cross reference
02:16
using RG as variable and the structure
02:20
between the different resources and entities within my terra form file. Similarly, the resource group name. I want this V Net to be created in this resource room up here. So rather than hard coating it or in this case, even rather than
02:34
daily, they're doing the bar. I'm going ahead and I'm just going to say reference the value of name
02:39
from that entity created up here, the RG entity which is of type resource group. So you can see now we're creating inter relationships between our different resource is and so a big value in doing it like this
02:54
is when we run terra form and it's doing its thing, it'll actually calculate their relationships between the resource is
03:00
so that it creates things in the correct order. And obviously that's going to be very helpful when we have interdependencies within the resource is such as a resource is that belong to an over our king resource group.
03:15
So let's move along
03:16
and give this a shot with what we've created here would open up the consul and I'm gonna make sure I've changed into my working director to be the 02 variables directory
03:30
and I'm going to run good old Terra Form and Nick's because this is a new working directory of no longer in the 01 basics directory. So the contents of this have not been initialized. And when we can see the tzar R M provider plugin has been downloaded as a result of that innit process.
03:51
Next, I am going to run terra form plan just to get a feel for how things were going and immediately you'll notice
04:00
that I'm being prompted to define the value for a variable called resource group name. If we come back up here to the variables, you may recall that that this we didn't define it a default value for this particular variable. We just gave it a description. We didn't even define a type
04:19
to be honest.
04:20
So because it no, wait a minute. This is a variable. This variable is being referenced by the resource is right. It was important. Variable. I don't have a default value. I need a value for this variable. So it's prompting me to enter enter the value. So I'm just gonna call it ah manual
04:41
dash R g
04:42
as a value in this context, it's Go calculate the planet's not actually gonna create anything here, and then it's gonna show me. Okay, what is this gonna be actually doing if I wore to run the apply process? And sure enough, it's creating a resource group with the name manual RG
05:01
um
05:01
located in the West US to region.
05:06
Ah, and it's also creating an azure resource manager. Ah, virtual network. Excuse me. Ah v Net, which a NCO, incidentally, belongs to the resource group manual dash RG and is located in the West us to region. So
05:26
let's talk another second about why we would want to do variables
05:30
like this and input variables. Let's say we had this terra form script and we wanted it to be reusable such that we had had different customers and maybe we wanted the resource group name to be a reflection of who that customer waas.
05:50
So there's a few different ways we can do that
05:53
and to find that with one approach would be to go in here and just define default. Value equals customer one. That's one approach that we could take
06:09
if you think about concepts of continuous integration and continuous deployment and having terra form scripts run, not manually like we're doing in these lessons. But by ah bite by a program such as a Jenkins or get lab C I or the desert pipelines.
06:29
Editing the files in a script, A Matic Ways is really not a good practice. So terra Form provides a few other capabilities around. How you do this, one of them is creating what's called referred to is is a t f ve *** file.
06:45
So I'm gonna create a new file in the Variables directory, and I'd like youto
06:48
to follow on and and we're gonna call a customer one dot t f bars. Okay, that's that's the extension there, and the contents of it is gonna be very simple. We're gonna say resource group name and nice to have that auto complete equals customer. One
07:05
customer one. Okay, so now what we've done is we've defined this, um, this value. And if we come back to terra form
07:15
and we say Okay, you know what? Show me the plan again. Terra form a plan.
07:20
It's gonna prompt me again for the resource group name, right, because we don't have a default value for this particular variable.
07:28
Now I'm gonna cancel out of that, and I'm gonna go terra form plan. But I must say, you know what? Look at this variable file.
07:36
Their file equals customer customer
07:43
bars. Okay.
07:46
And when I do this,
07:49
you'll notice I'm not being prompted for a value of that variable because it's reading in the value from the variables file that I specified on the command line. And sure enough, the name of the resource group is going to be a customer. One. What's also interesting And and I guess of note
08:09
is if I were to go back and edit that the TF bars file
08:13
and say, You know what? We don't want to put this in West us to that. That's the default. But we want to put this in East us,
08:20
and then I would run the plan again. It's actually gonna override the value off
08:24
the variables location file that is West us, too. And it's going to use the value that's in TF bars and so, sure enough, there's East us.
08:39
Okay,

Up Next

Fundamentals of Terraform

In this Terraform training course, students will learn the basics of the tool through hands-on labs, become comfortable with its core language features, learn how Terraform fits into the cloud tooling landscape.

Instructed By

Instructor Profile Image
James Leone
Cloud, IoT & DevSecOps at Abbott
Instructor