Now that we've copied our policy, let's jump over it's see visual studio code and set this up to start.
Let's create a new folder.
And I'm going to call this.
I am.
Let's right click and creates a new file.
We're going to call this main dot t f first, let's set up our provider.
In this case, it's going to be eight of us in this region equal to.
The dash w dash to No one here, what we're going to do is create a user and it's gonna be a generic
user.
This would normally be like setting up someone's accounts.
So to are going to create a resource.
Eight of us underscore I am under school user and we need to give it a name.
Now don't confuse us.
This isn't the name for the user.
It's the name for when we access this inside.
Terrible.
I'm going to call it my user.
Next, we give it a name up on a name.
This one off to meet someone, we call it T.J..
And the reason we're creating this user is so that we can attach the policy to the user.
So now let's go ahead and use our policy to do so.
We're going to create a resource which is eight of us underscore I am on the school policy.
How critical this custom policy.
No one needs to give it a name.
So when to call it my custom policy, you may choose to do something else.
We'll give it a unique name.
Maybe something more specific.
So call it closure if it's easy to get something really unique.
Now comes the clever bit.
We're going to type in policy equal to then left angle bracket, left angle brackets e o f and when
it's open, another E F.
Let's break this down.
So this is going to take the policy we've created in A.W. s where they're going to paste it inside a
on code.
And when this is going to add the policy to A.W. US, she may be wondering why do we do it in the console?
Now we're all business requirements where you need to keep your policies in code.
And it could also be on the flip side, you may have multiple feet of U.S. accounts or maybe you're
an MSP and you have a client.
We have a generic set up.
So rather than doing it every single time on the console, you can keep it inside your code with a W.S..
It also looks good for security reasons.
So you have it tracked and audited so you can see if there's any changes made to it.
You might need a pull request and you'll see a version control.
So there are lots of reasons for keeping this inside the code.
And once it's in there, it's very easy to make changes to it.
And with a hack, Robert, to do this all in code from scratch.
We simply copied and pasted what we've set up in eight of us to give us a rough idea what we want.
And then as time progresses, it's very easy to make changes.
So now let's go ahead and paste in our code.
Now, bear in mind, this is going to be huge.
Let's bring this EAF here.
So it starts at the beginning of a line.
And let's scroll all the way up to the top.
Now, sometimes if this doesn't work.
And I've seen it before, when I first film this lesson, it was because this curly brace was like this.
It has to be at the beginning of the line.
But let's also break down what was your efforts to make sure you really understand it, because you
will see stuff like this quite commonly used in Linux.
So AOL stands for End of File.
So you may be wondering why we put two in.
This is using a principle called Haydock sort of allows us to do is put in multiple lines of text and
also maintain all the formatting of it.
As far as it's concerned, it's a single line.
So it's a very clever trick.
So we have the E with which is unique because it's not going to be anywhere else inside the code apart
from at the end.
So it can read all of this as a single line until it reaches the bottom and sees the EAW.
So now that we've got all this set up, let's scroll to the bottom and now let's attach it to a resource.
And this is quite a long one.
It's a W.S. underscore.
I am underscore policy.
Underscore attachment.
I'm gonna call this policy binde.
Because this is how we linked this policy and add it to the user so the user gets the permissions old
for policy.
So we have to give it a name.
I'm going to call this attachment.
We have to pass in which users we want to attach the policy to.
And that's a list.
So we saw it's a W.S. underscore.
I am on the school user dot my user dot name.
Next, we need to attach the policy.
So it's policy MRN or Amazon resource name.
So that means we're going to use the attribute dot a red.
So we've set that equal to a W.S. underscore.
I am underscore.
Policy dropped and we call it custom policy dot a are in.
So as you can see here, we cannot touch one policy to multiple uses.
Now, when I look up, just make sure we spell everything correctly so that my user and custom policy.
So to recap, we've created a custom policy in a W.S. we're not going to create a user.
Again, to attach that policy to that user.
So if we're happy with that, let's go up to.
Go to Terminal C into I and run Terfel in its.
Excellent.
So now let's go ahead and run.
Now let's run terraformed reply.
And so, yes.
Okay, look, something made made the policy a bit too big.
It's the first time I've seen an error like that.
We have such a big policy, an industry.
What you'd probably do is split this up.
You wouldn't have such a big policy.
It's good, for an example, so proficient.
It takes so many things in ACTC.
Again, it's all about learning.
So we'll keep a bottom line here.
Let's go up to about halfway and strip out.
Some of his policy being very careful of Jason formatting.
There we go.
So it's a bit smaller now.
Let's go ahead and now run.
Terrible reply.
And so, yes.
Excellent.
So now we go to the UAW, this console, go to Iowa, see uses.
And he could see we go user code, T.J., We can see we've got my policy glacier ESFS and you could
also see we've got adjacent policy.
So, again, if we need to delete something, we could delete easy to create routes.
We could do that inside the code on terraform apply and make that change.
So now we go from set up.
Let's tear it down.
Let's run.
Terrible.
Destroy.
And so, yes.
Excellent.
That wraps up this lesson.
I look forward to seeing you in the next well.