Looping over object collections
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 key-value objects.
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
To get started, we 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 ...