Looping over a map of objects
We have seen in the previous recipes of the chapter the use of the count
property, which allows us to provision N identical resources, as well as the use of map variables, which allow values to be of type object
.
In this recipe, we will discuss how to provision N resources of the same type but with different properties, using the loop functionalities included in Terraform since version 0.12.
Getting ready
We’ll start with a basic Terraform configuration that allows you to deploy a single App Service in Azure.
The basic Terraform configuration is as follows:
resource "azurerm_app_service" "app" {
name = "${var.app_name}-${var.environement}"
location = azurerm_resource_group.rg-app.location
resource_group_name = azurerm_resource_group.rg-app.name
app_service_plan_id = azurerm_app_service_plan.plan-app.id
}
The source code for this recipe is available at https://github.com/PacktPublishing...