Time
2 hours 48 minutes
Difficulty
Intermediate
CEU/CPE
3

Video Transcription

00:01
take a quick look at the, um at the different that the shell script itself set up. That s H. This isn't a course on bash. It is a bash script. If you understand Bash, you can digest it as much as you want. But the shortened the skinny of this is its installing an engine ex web server on the machine. Um,
00:21
and it's configuring that Web server to listen on a specified port
00:25
and for a specified D. N s name on DSO here we can see I have, ah, function on and I'm parsing the input arguments in this particular circumstance. And then the meat of the script is first is going to use app get to update the various
00:43
packages. In this case, the virtual machine that we're deploying
00:46
isn't a boon to Lennox. So first, I want to update all of packages and get the latest in Greece that are on there immediately after the server's been provisioned that I'm gonna go ahead and I'm gonna install the Engine IX package. I'm goingto create a configuration file,
01:00
which is essentially saying, engine X, you're gonna be a very simple Web server. You're gonna listen on the specified port.
01:07
Um, here's your root directory for the Web pages that you're gonna be serving up. I spit that configuration file to a specific location that I know based on the the apt Engine IX package. This is where it's gonna be looking for configuration files
01:23
and then I restart the engine Ex server. So this is a pretty simplistic set up script Maur. Though the focus of this exercise being on using provisions, orders remotely executing scripts on servers after Terra Form has provisioned them.
01:41
Now that we have a basic feel for what the shell script is going to be going when the virtual machine gets created, um, I want youto go ahead and we're gonna kick off from the terminal here. We're gonna kick off the terra form process to deploy these scripts
02:00
in the whole, used the terra form file and build out the infrastructure.
02:02
And let's have that running in the background while we're exploring one other aspect of terra form provisions. Er's is the local execs,
02:13
so I'm gonna say yes. Okay, so that's off and running.
02:17
Um, well, that's doing its thing. Let's navigate back to the main terra form file and spend a moment talking aboutthe local execs. So the remote executives used to remotely execute commands on the server that was just provisioned.
02:35
And by the way, these provisions er things that I'm talking about him or recovering
02:39
these air capabilities that regardless, if you're using as er you're using AWS all the cloud providers if the virtual machines being deployed to any of those cloud providers, this technique in this approach will work. It's a terra form technique. The cloud provider specifics.
02:57
They themselves also have other techniques that you can accomplish this kind of stuff.
03:01
But this is a common technique that you can use across the different cloud providers. So that's why we're focusing on that.
03:07
Local execs is, ah, specific method to run a command locally on the machine that is performing the Terra form in executing the terra form script. So in this situation, we just kicked off the terra form, apply my own work station is that machine.
03:25
And so in this situation, it's gonna
03:28
echo just a just a simple string to the consul. But I could be calling other commands. Maybe I have other things that I want to take place Maybe it's running a curl command and kicking off in an A P I to an interval eternal inventory system
03:46
so that it's tracking and knowing what I'm
03:49
what servers I'm being created in which environments,
03:53
really, it is a very open ended kind of situation, but you want to keep this all in your back pocket to understand if you end up with these kind of funny situations where there needs to be a little more than just terra form itself involved in the deployment and tracking and your internal operations, these air good handy utilities
04:13
tohave on and leverage these provisions right again. It is really a last
04:17
last resort situation, but you will encounter situations where it's last resorts, I think more often than than you may like. The other point of this particular local, exactly the way I've set this one up is so by default the provisions they're gonna run when the um,
04:38
the resource the servers created
04:40
in this circumstance, I've specified the wen attributes, and I said, I want you to run this local execution when the
04:47
when the server is destroyed,
04:49
so we're going to destroy all this infrastructure after it gets created, and we make sure everything's up and running. And when that destroy process happens, we wanna watch. And we should see this echo command very simple being called here. So the wind attributes is not a required attribute.
05:08
And if it's not specified, your default is gonna be thio
05:14
tohave the to have it run when the machine has been closed so you can play around with this. It's something specific to the local execs, and if we were to flip over to the the module descriptions here from terra form,
05:30
we can see at the bottom. It gives it some example of when
05:34
Onda protect Henschel values that you can put in the wind to have that local command be executed based on different events and circumstances in the life cycle of the virtual machine that you're defining in terra form.

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