Hi, welcome back.
How did you do with a challenge?
We were able to complete it.
How many modules did you create?
Did it all work?
What I'm going to show you now is how to complete the challenge.
What I'm going to do is I'm going to make a copy of Challenge to somebody's control C, Control V,
and I'm going to rename this to Challenge Free also.
Now let's have a look at our terraform code.
There's a lot in here.
So let's stop.
What we'll do is we'll create two new folders.
We'll have Web.
We'll create another one.
And we'll call it DBI.
DBS is gonna be the easiest.
So what we'll do is we'll create a new file.
I call this DV dot t.f..
And what we can do is literally start stripping stuff out.
So we'll cut this pasted in here.
And we also need an output's.
I'm going to make a copy of this.
Pasted in here.
I've copied and pasted the output because, Lisa, what we're going to do is change this to the module.
You now pretty much everything else.
Can go inside the web folder.
So let's do that inside here.
Let's create a new file.
We'll call this Web dot t.f..
Go back to main dot T.F..
Well, cuttle, cuttle and pasted in here.
Now, while I'm here, I'm clean this up and I'm also going to set 12 modules.
So the module will call it DBI and source is can be dot slash DBI module.
Call it web and it's gonna be dot slash web.
Now, that means you can also set the outputs.
So let's copy this public IP.
And we'll piece it down here.
I'm almost here with a private IP.
We can change that to multiple DBI and it's got the same name, so we'll call it private IP.
As far as we're concerned, the DBI is done.
There's not much else to change on that.
No Web one's going to be interesting because we could split this up even more.
So why don't we have a go at doing it?
From organs I need to do is copy the script inside the web folder.
Because what it's looking for is inside here.
And we put it inside challenge free.
It's not gonna be fun file.
No, what we can do is split this up a little bit more.
So you could do VIP dot, see if we could create another file, which is going to be S.G. Dot T.F..
So navigates Web T.F. Apology's is a lot of T.F. files in here.
We can cut the IP pasted in.
And next, we got the security group.
Go ahead and paste that in there and we will Scott Republik IP.
Let's cut it and put it inside VIP.
We've got a lot of stuff set up in here.
Do you think we can modularize it anymore?
Let's have a go.
So create two new folders called S.G. and we'll create another folder and we'll call it E IP.
So being couples respective falls into their respective folders.
Now we have a quick look at what top T.F. Let's have a quick look at what we're going to need.
So we're gonna need the name of a security group and the VIP is going to need the instance I.D. So we
have Whittlesey F.
We have to set up an output so in call instance on the school I.D..
In the valley, it's going to be equal to NWS on the school instance, dot web, dot idee.
If we minimize all this, we got means, see if we could create individual modules for all the other
items or we could add them as child modules or modules inside with instance.
So inside the module, we'll declare another module.
That, to me, would make the most sense.
Let's go ahead and do it.
So do Modu.
We'll call it VIP.
And the source is going to be equal to.
And you might find you have to go back up to levels that we dot, dot, slash VIP.
And what we could do is pass in the instance I.D. as a variable with the variable instance on the school
I.D. type and we'll do of type string.
Vincent said before Dott instance on the school I.D..
And then we could pass an instance, underscore I.D. equal to and we can copy that line here.
That it means we can delete this output here.
The original plan was to have the module set up differently.
But if that were going to cool in factory as a child module, this is no longer relevant.
Next, we got the security group.
So do module.
I'm Nicole, S.G..
Same as before, dot, dot, slash SDD.
Now, what is going to mean is we can need to pass in the name here so we can have to declare an output
in security group's output.
Security Group nine optionally what we could do is pass in variables for we ingress and egress rules.
What I want to focus on instead is setting up a security group and being able to access it inside the
easy to over web modu.
I was going to say, let's set myself at the bottom of the list of the top instead.
Was it the outputs and we call it S-T on the school name?
And was it not value equal to eight of us on the school security group DOT Web, on the school traffic
dot name?
Now we go back to Web dot t.f..
We'll do module we type in module DOT, S.G. Dots, and we said it's called S.G. on the school name.
And we can confirm that absolutely.
Now and here, we want to output the public IP.
So we send over output and call it pub on the school IP value equal to modu dots, IP dots.
And let's quickly recap what the name is.
And it's public IP.
But if he gets a mindless yeth.
It's going to be Molcho Dot Web dot pub IP.
So let's quickly check the pub, underscore IP again, spelling is very important, and I do often catch
myself misspellings.
Always check your coat.
Now let's quickly recap what we've done, because I realize we can watch arises even more from the original
filming when a deviously zero point eleven syntax.
I played it a little bit safe and I've gone all us in this case to turn everything into a module.
So let's have a quick look at our structure.
We have four modules.
Two of them are initiated and accessible inside Main T.F..
And we created two other modules that have access inside by modules.
So a lot of tongue twisters here.
But bear with me.
So we have may not yet.
It's going to create our instance.
It's going to create two additional modules.
One is going to be the IP and the second is going to be the security group.
With an axis security group name using and outputs and V.I.P.
We've been passing the instance I.D. so that it can attach itself to the IP.
We've been creates an output to ventilate the output from multiple IP.
Again, lots of tongue twisters here.
So we create VIP.
We create an output.
We then pass it in here script over output.
It passes it to CFF.
It used to be in zero point eleven for any output inside a module would show.
But in zero point twelve, we changed it.
So now we have to actually declare inside Main Delta F or the parent file up here.
And we have a quick recap that secures your group.
Let's see if we have our ingress egress.
We have an output which is going to then pass it over to the Web.
T.F. We set up our security group and we're all there.
So now what we can do is go to view, go to terminal.
And at this point we hope everything is going to work.
So we'll see these two challenge Guri.
Now, do you remember that?
Come on.
I said you need to run.
Any time you're working with lots of modules or making any changes with modules that command these,
terraform in it.
And if anything's wrong here, Pops, it's gonna go ahead and can play 60.
His initialize the modules, but it's also complaining about block definition.
Appears to be an equal son was missing.
Excellent, let's go ahead and run again.
Also now let's run.
Terrible plan.
I want to include this as well, because I know some instructors want to give you this really polished
image, and I do want to give you the impression it's a sloppy thing, that it's me troubleshooting
on the fly.
I've junji with this and I've done it as live as I can.
This is me.
Good.
OK.
We can create some more modules, but it's things like this.
We can see how I'm going to try and troubleshoot stuff.
But I want you to also learn from this as well because you may encounter the same error or a slightly
different one.
And you think, how do we go about solving this?
This is one of these things I remember from memory last time when our first film, this.
And if I run into these issues well, in real life situations and I forgot set this time file is movies,
really weird things and terrible.
And you can have a look on stack overflow.
Was really hard things to find.
I moved the file inside this web folder expecting that when we use file it would set the context or
in other words, where it's looking to inside this web folder.
I believe what it's done and it's happened before is it instead is looking side challenge for.
But we need to tell TerraForm the file is actually inside the Web folder.
So when I'll go to Web dot t.f. and we'll do dot slash web slash service dot S.H..
Now clever.
And now let's run a terrible plan.
Now, let's go ahead and run.
Terrible reply.
Well, it's a yes.
Awesome.
Would you look at that?
You even got the public and the private eyepiece.
What do we give this a little test?
Sarafa go over to my browser.
Let's paste in the public IP.
Hello.
From Terrible.
Wow.
This has been a really cool challenge.
Originally, my plan and the hints I gave you was to split into two module folders.
I realized we could do even more.
We even had a bit of life troubleshooting as well.
So this has been quite a fun challenge.
I could go back and re film it to make it a lot needs.
But I quite like the edginess and the grittiness in this.
I want to know how many different modules did you create?
Did you do something similar to what I did right now?
Did you try modularized everything?
And what sort of issues did you run into?
I can imagine the file.
One would have probably been the biggest.
So it made it easier just to let that folder outside.
But now, you know, for next time, that is very aware of the context.
It's looking inside the challenge for refolded, not the module folder.
It was it even if you only did the Web and the DBI folders, still you can completive a challenge.
That's what we were looking for.
What could you modularize in this example here?
It's a lot more extreme and we modularized a lot more.
We want a lot more in depth.
Either way, congratulations.
A well done with completing the challenge.
You'll guys have used up a lot of brainpower doing this.
I feel free to go grab a tea and coffee and I'll join you back here very shortly.
And I look forward to seeing you in the next lesson.