7.3 local-exec and Example

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *

Already have an account? Sign In »

2 hours 48 minutes
Video Transcription
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,
and it's configuring that Web server to listen on a specified port
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
packages. In this case, the virtual machine that we're deploying
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,
which is essentially saying, engine X, you're gonna be a very simple Web server. You're gonna listen on the specified port.
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
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.
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
in the whole, used the terra form file and build out the infrastructure.
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,
so I'm gonna say yes. Okay, so that's off and running.
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.
And by the way, these provisions er things that I'm talking about him or recovering
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.
They themselves also have other techniques that you can accomplish this kind of stuff.
But this is a common technique that you can use across the different cloud providers. So that's why we're focusing on that.
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.
And so in this situation, it's gonna
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
so that it's tracking and knowing what I'm
what servers I'm being created in which environments,
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
tohave on and leverage these provisions right again. It is really a last
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,
the resource the servers created
in this circumstance, I've specified the wen attributes, and I said, I want you to run this local execution when the
when the server is destroyed,
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.
And if it's not specified, your default is gonna be thio
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,
we can see at the bottom. It gives it some example of when
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