Hello, I have a little problem here:
In variables.tf
variable "sp_name" {
  type    = set(string)
  default = ["ASP-CriticalApp-TESTA", "ASP-CriticalApp-TESTB"]
}
variable "af_name" {
  type    = set(string)
  default = ["SFT-FUNCTAPP-TESTA", "SFT-FUNCTAPP-TESTB"]
}
In main.tf
resource "azurerm_service_plan" "sp" {
  for_each            = toset(var.sp_name)
  name                = each.value
  resource_group_name = data.azurerm_resource_group.rg.name
  location            = data.azurerm_resource_group.rg.location
  os_type             = "Windows"
  sku_name            = "Y1"
}
resource "azurerm_windows_function_app" "af" {
  for_each            = toset(var.af_name)
  name                = each.value
  resource_group_name = data.azurerm_resource_group.rg.name
  location            = data.azurerm_resource_group.rg.location
  storage_account_name       = data.azurerm_storage_account.sa.name
  storage_account_access_key = data.azurerm_storage_account.sa.primary_access_key
  service_plan_id            = azurerm_service_plan.sp[each.value].id
...
}
In main.tf in service_plan_id Iβm trying to reference βresource βazurerm_service_planβ βspββ but I get this error:
Error: Invalid index
β
β   on main.tf line 27, in resource "azurerm_windows_function_app" "af":
β   27:   service_plan_id            = azurerm_service_plan.sp[each.value].id
β     βββββββββββββββββ
β     β azurerm_service_plan.sp is object with 2 attributes
β     β each.value is "SFT-FUNCTAPP-TESTA"
β
β The given key does not identify an element in this collection value.
β΅
β·
β Error: Invalid index
β
β   on main.tf line 27, in resource "azurerm_windows_function_app" "af":
β   27:   service_plan_id            = azurerm_service_plan.sp[each.value].id
β     βββββββββββββββββ
β     β azurerm_service_plan.sp is object with 2 attributes
β     β each.value is "SFT-FUNCTAPP-TESTB"
β
β The given key does not identify an element in this collection value.
It should creates 4 resourcers but instead it only creates 2. I want to reference the 2 resources created in βazurerm_service_planβ βspβ and each resource join the βAβ with the βazurerm_windows_function_appβ βafβ β βAβ and so. Thank you.
(Tried with βeach.keyβ too)