Were you able to complete the challenge?
How did you find it?
Did you struggle on that last step?
A major well done.
If you did, complete it.
And now let's have a look at how you would do it.
So I'm going to start by creating a new folder and I'm going to call this challenge to.
Now, you will already have access to the file, which is going to be called server dash scripts.
Dot S.H..
Now, quick recap of what is going to do is to update the system installed Apache, make sure it started
this next step here.
Enable insurers if the instance were to restart.
That's the Web server would come back up.
The last line here is Echo.
Hello.
From TerraForm.
And it's going to put it inside a file which is indexed H2, UML.
The goal of this is when we finally spin up the instance and we get the public IP, we'll be able to
do is in our browser.
Go to the page and see this message.
Hello from Terrible.
So now let's get off its inside challenge to create a new file, which is gonna be main dot f.
Now, what I am going to do is copy from any one of our files with an EU instance and copy the easy
to instance.
The reason why is the EMI.
The rest of this is very good practice to type it out again.
That way it becomes muscle memory.
So we're going to do now, is that a tax?
We said name equal to and we'll call this DBI, sir.
Speed things up.
We can copy this again and we'll go the second one Web server.
So let's start with the easy bit.
How do we give it a persistent public IP?
Now, do you remember the difference between a public IP on an AC two instance and any IP with a public
IP?
For instance, what's get restarted?
That would change.
And if we had a domain pointing to an IP address, that's not ideal because it's going to break our
Web site.
Instead, we would use an IP or an elastic IP, which is a persistent IP address.
And it's also an external IP address.
So let's go ahead and create that.
Now we'll do resource.
Eight of us on the school, V.I.P.
Give it a name.
Someone goes web on the school IP.
And next we need to say what instance to attach it to in this case is going to be the Web server.
In this case, it's going to be a Web server.
So the A.W. is on the school instance, DOT.
And it's a grouping.
We spotted this now.
So the top one, DBI, and we'll call the bottom one web.
So the eight of us on the school instance web dot and we need to pass in the I.D. so easily, I.D. attribute.
Excellent.
So we've got our two Web servers.
We've got the VIP.
Next, we need to create the secure security.
Now, didn't mention here, but you had two options of going about doing this.
Bonus points if you did it with dynamic block.
But if you didn't.
That's fine, because at the end of the day, it's about guessing results.
I'm going to use the dynamic block approach.
So now I need to create two variables.
So the variable one will call this ingress.
It can be type.
List.
And of type number.
Next, set default and the two ports.
We need open are 80 and forceful.
Three.
What we can do is copy this and set it to egress.
Now let's go ahead and set up a security group.
So it's going to be resource.
A.W. is on the School Security Unschool Group.
Give it a name, some Nikko's Web under school traffic.
And let's put that inside curly braces.
We need to give it a name.
So Unical allow Web traffic.
Now let's do a dynamic blocks.
So start with the Inger's.
So the dynamic.
We'll say it's in Greece.
It's the right to.
I like to use ports because it makes the most sense when you say for each and when you'd say the beach,
what is going to be vare dot in?
Next, we need to add the content block.
So what do we actually want to create?
And here we can set off from port.
EHU to Port Dot Vally to underscore port people to equal to Port Dot Valley.
Pacheco.
So it's see TGP and then Seida blocks.
Equal to.
And we get to allow everything is zero zero zero slash zero.
Now let's copy this block.
And exactly the same, but with vigorous.
Quick word, a warning here.
I made the mistake a few times.
What I've swapped out where it says ingress and put an E.
And it's now called ingress.
So make sure it says egress.
Excellent.
So looks like we've got pretty much everything set up right now.
So now what we can do is get back to our Web instance and attach a security group.
So security groups.
Equal to its list.
In this case is going to be the one we just set up.
Eight of us under the school security and the school group DOT.
And the name said it's web on the school traffic, so web on the school traffic dot name.
Next up, we've got a couple of outputs.
That's correct.
First one, which is private IP.
And the value is going to be who to O.W. us underscore instance, dot, D.V., dot privates and the
school IP.
If you ever get confused, which actually you need to use, always check the documentation.
Now, what we can do is copy this and we'll get sort this out soon.
But public IP.
Now, we could just sort this line out here and said it's a Web server.
What we're going to use instead is the E IP eight abuse on the school, IP dot web unschool, IP dot
public on the school IP.
Excellent.
We're almost there.
We've got one last thing to do, which is to get a script to run.
Now, did you work out how to do this?
Let me break this down.
With easy two instances.
You have an option to run a bootstrap script that is not ideal because sometimes it can fail and he
run into issues and should probably use a novel solution to configure things on the easy to instance.
However, this is an option if you need to do it.
And sometimes it's referred to as a bootstrap script because what it does is once the easy two instances
started, it's the next thing to run.
And the option is called user data.
And then to get a filing, we need to use some sort of built in function and the function we want to
use is called File Next and pass in the Volney, which is server dash script dot S.H..
To recap what the file option is going to do is read the contents of our scripts and then read it.
It's very good to pass in to the field of user data.
Now normally in industry you might use another tool free, so you'll configure the instances with terraform
and you'd vent Pulse O2 enough to be be chef, puppet or Ansible to then go ahead and configure it.
Again, there is a chance if something fails here, there's no sort of recovery process as in it's not
going to try again.
It will just fail.
Instance will stay up, scripts won't have run.
Let's have one last quick glance at our code.
Everything looks good.
So now one more thing to add is to make sure we add our provider.
We'll that's the eight of us.
I'll set a region equal to.
EU dash w dash two, if you're using a different region, make sure to put it in here.
Now let's go up to a terminal.
So gets a view.
Gates terminal now seedings to folder.
So c.D, challenge to this from terraformed in.
It's excellent.
Now let's from terrible flight.
Okay, I made a slight mistake there.
And again, alights include these things because it does show that sometimes even US instructors can
make mistakes.
And it also shows you how to fix it.
So here are put tags and or forgotten vehicles on.
So let's quickly fix up the tags equal to.
There we go.
That looks better.
So let's go back to our terminal.
The terminal.
Notes from terrible apply.
Excellent.
This is looking good.
So solid from the top A it's to create the VIP.
A D.V. instance.
A Web server.
The security group and we'll check the ports, fulfill FRIE 80.
And same again, Fullfil Frie, an 80.
Excellent.
I'm happy with that.
So I'm going to go ahead and it's a yes.
Now, with this challenge, when it comes to seeing VIP and checking the Web server, it can sometimes
take five or so minutes for it's actually boot up the easy to instance and then go ahead and roll the
script.
Unfortunately, one of these things, you're going to have to wait it out and wait for the instance
to start.
Excellent.
Let's grab the IP and wait a couple of minutes.
Let's go ahead and check it out.
So I want to copy this.
I've got a pulse recording for a couple of minutes and we'll test it and see if it works.
OK, because I'm a little bit impatient.
I want to go ahead and check it out anyway.
I can always keep hitting refresh to make sure it's wrong.
So once you copy VIP go, it's your browser Pastern VIP and hit enter.
Also now we can see hello from Terrible.
Well done.
If you can, please give this challenge.
It's a really challenging one and it's one that's going to really tested your terrible knowledge.
But you're going to have learned so much from this.
And it's quite similar to a real life project you probably face in the workplace where you're going
to get some very sparse details told to set something up.
And that's it.
So very good.
Pat yourself on the back.
Well done.
And congratulations.
Take a quick break from now.
Grab a quick tea or coffee and I'll join you in the next lesson.
But first, let's go ahead and set it down.
Let's go to our terminal and run.
Tearful Destroy.
And so, yes.
And there we go.
We'll leave that to run.
And we'll look forward to seeing you in the next lesson.