To create multiple identical resources, perform the following steps:
- In the variables.tf file, we add the following variable:
variable "nb_webapp" {
description = "Number of App Service to create"
}
- In the terraform.tfvars file, we give a value for this new variable as follows:
nb_webapp = 2
- In the main.tf file, we modify the resource code of azurerm_app_service in the following way:
resource "azurerm_app_service" "app" {
count = var.nb_webapp
name = "${var.app_name}-${var.environement}-${count.index+1}"
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
}
- (Optional:) In a new outputs.tf file, we add the output values with the following code:
output "app_service_names"{
value = azurerm_app_service.app[*].name
}