2 hours 48 minutes
all right. So everything ran smooth here. We could see there's some outputs produced at the very end
of certain public eye peas. And this is the girl that corresponds to each of the three containers that were deployed. And we can see central, US, West, US and East Asia us because we wanted to have a container deployed in each one of those regions for one of three different customers.
Let's take a look at the outputs file That was the result of this. This is a good example of a four loop, very comparable to the four each loop, the syntax and structures a little bit different
in this situation. We have the container group, right, And that's a map of the map that has three elements in it. The keys being customer, one customer to customer three. And you can see what I've done here is I'm saying four c c being container. Just a single acronym.
Ah, single letter variable here in that container group. So for each one of those those items that reside in this container group map, I wanted to make the value of this output public at these very well be the fully qualified domain name of that container. So this is another good example here
of using a four loop in your outputs if you wantto
return. An array of outputs are in this circumstance and returning on array of strings. And I'm determining the values in that array by looping through the materials a map or looping through a list or a set of some other things. Right? Because when we're going in this dynamic Ralph, I'm getting a little more procedural. Now we're
dealing a lot more with
multi dimensional elements, collections that have many different items that belong to them.
Last but not least, I want to talk about conditional Sze, specifically the if statement
and I want to talk about the count attributes. So we talked about the four each attributes for a resource.
But what I didn't review in the file that that existed there and you might have noticed if you were exploring herself was the count resource and some of these other used the use of conditional Sze.
So the accountant in condition als go hand in hand very common. You can use count really that the value of that you set for count is going to reflect in that terra form is going to create that many instances of whatever
particular resource item you defined,
but in a very common to see using count to conditionally create a resource or notch. So if the count to zero
that resource isn't gonna be created. If the count is one than the resource, one instance of that resource will be created. And so, in this circumstance, what I've put together, as I have said, if the length of the customers map
is greater than zero,
there goes question mark. If that's true, then the count for this particular resource group, which I've called the No Customers Resource group,
is going to be zero.
Otherwise, the count is gonna be one. So that little Colin is saying, you know, it's gonna goes condition, question, mark, value of true colon
value if false. So we were going to If if it's not greater than zero, then we will be creating this customer's resource group. So in this theoretical example, we're saying we always want to deploy something, even if we don't have customers right. Anytime we run this terra form script,
I did the same thing below for another container group.
it's gonna created under the same circumstances if there are no customers.
And just like before, when we were dealing with the container group and dealing with the four each that were coming from a resource group up here, we wanted to make a reference to that resource group to determine what's the name in the location that this container group should reside and we used brackets. And then we had to reference it by keys,
because when we're using for each and we're making reference to a resource item
that has the four each construct, that resource item is a map
in the count perspective. It's a little bit different in that that resource item is not a map. Rather, it's it's a defined list of things. So in this circumstance I'm putting a number zero because I know the count is either gonna be zero or one, and the first element
in the no customers
list is going to be element zero. So I'm referencing the resource group created here because it's account. It's now a collection or a list or a set, Um,
and I'm gonna use the first element there and then the same strategy for location. So I wanted to bring that full circle for you so you could see the use of count the use of for each as well as how you have to reference resource is
that are created. If they have counter, they have for each.
When you're making cross references to him, you have to reference them either by new Miracle Index or buy a key. This is a This is a little little unique and now we're really pushing the edge of terra form. But let's let's take a moment and and make a little change here and actually get rid of all the customers,
I'm gonna delete all the customers,
and I'm gonna ask Terra Form to let me know. Okay, As a result of doing this, what is your plan of action here? It's going through refreshing state, and what we would expect is there's no customers. So we were expected. It's gonna get rid of all those customer resource groups,
all the containers that pertain to the customer resource groups. Right?
So there's the six items that's going to destroy customer three customer to customer, one right, and then
because now this
This criteria for count the Vare customers is not greater than zero. So we're expecting the count to be one. So it is going to create the resource group called No customers. And again here you see, it's referencing of by a zero.
If I had count equals two, then then there would be a one and there would be a zero and there would be a one.
But we're not going to do that.
And then similar. The No Customers Containers group will also be created. And it's going to be destroying the other groups that we previously defined with our with our map. I actually don't want to do that right now. I encourage you to go ahead and run a terra formed, destroy
um t clean up your your azar instance and get rid of all those containers and resource groups that we just created. But in summary, I hope you cease. Um, several big things that we've learned. We learned about the four each, which is a brand new construct to the language. We learned about the count construct, which has been there quite a while.
We learned about leveraging condition ALS to conditionally
um, create something by sending a count to zero or one. That's a very common and powerful strategy. And then we talked about the four loop here in the in the outputs when we were looking at that and how that's all put together. So hopefully this provides you with some value
when you're getting into creating and solving more advanced problems and creating those
Kali Linux Fundamentals
If you’re interested in penetration testing and ethical hacking, then this Kali Linux course is ...
1 CEU/CPE Hours Available
Certificate of Completion Offered