Filtering Terraform list
In the previous recipes of this chapter, we learn different use cases of loop over Terraform objects like collections using for and for_each
expression.
In some scenarios we can have the necessity to create resources from existing list, but the requirement is to filtering only some elements from this list.
In this recipe we will learn how to filter a Terraform list to provision resources.
Let's get started!
Getting ready
To complete this recipe, you'll need to know about loop with for_each
expression that will learn in recipe Looping over object collections of this chapter.
The starting element of this recipe is the following Terraform list. This list contains some properties of resources here in our use case is App Services:
web_apps = {
webapp1 = {
"name" = "webapptestbook1"
"os" = "Linux"
},
webapp2 = {
"name" = "webapptestbook2"
"os" = ...