Hello, I am trying to create 2 resources by using “for-each” Terraform 0.12 version to create more than one application service plan. So, have declared variables.tf with AppServicePlanName
as variable type = list(string)
.
variables.tf :
variable "AppsServicePlanName" {
type = list(string)
description = "app service plan name"
default = [ "testappsvcp1", "testappsvcp2" ]
}
main.tf :
resource "azurerm_resource_group" "appssvc" {
name = var.AppsResourceGroupName
location = var.AppsResourceGroupLocation
}
resource "azurerm_app_service_plan" "asp" {
for_each = toset(var.AppServicePlanName)
name = each.value
resource_group_name = "${azurerm_resource_group.appssvc.name}"
location = var.AppsServicePlanLocation
asp_name = each.value
asp_kind = var.AppsServicePlanAspKind
asp_tier = var.AppsServicePlanAspTier
asp_size = var.AppsServicePlanAspSize
asp_capacity = var.AppsServicePlanCapacity
is_xenon = var.AppsServicePlanisXenon
tags = {
env = "Test"
layer = "app"
}
}
Get this error:
in resource "azurerm_app_service_plan" "asp":
for_each = toset("[ "testappsvcp1", "testappsvcp2" ]")
A comma is required to separate each function argument from the next.
Can I not declare it within an array like how I have declared in the variable?
Also, if I need to create apps services based on these 2 app service plans. So, if I use for_each for app service plan, how will I susbstitute the asp_id for them?
Can I use the each.key
/value
from app service plan into app service? I am confused there. Could somebody please help me understand this?
Thanks in Advance.