Azure App Service path mappings for_each

Hi, I’m trying to add a (currently) unsupported property, ‘path_mappings’, to an App Service (see status [here]( ## azurerm_app_service will not configure Path mappings · Issue #3752 · hashicorp/terraform-provider-azurerm · GitHub). In light of that, I’m trying to use a provisioner as a work around

resource "azurerm_app_service" "as" {
  name = "as-${local.app_name}"
  resource_group_name = local.rg_name
  location = local.rg_location
  app_service_plan_id = azurerm_app_service_plan.asp.id
  ...

  ## https://github.com/hashicorp/terraform-provider-azurerm/issues/3752
  provisioner "local-exec" {
    when = create
    for_each = {for index, value in local.path_mappings : index => value}
    command = "az webapp config storage-account add --resource-group ${self.resource_group_name} --name ${self.name} --custom-id ${each.value.volume} --storage-type AzureFiles --share-name ${azurerm_storage_share.stfs.name} --account-name ${azurerm_storage_account.st.name} --access-key ${azurerm_storage_account.st.primary_access_key} --mount-path ${each.value.path}"
  }
}

However I get the following error:

A reference to “each.value” has been used in a context in which it unavailable, such as when the configuration no longer contains the value in its “for_each”
│ expression. Remove this reference to each.value in your configuration to work around this error.

Is using a for_each in provisioner even possible or do I need to list out each item individually?

Actually, for_each should be used within the resource context instead of the provisioner context. Have you tried that?

Or do you want to create a single resource but multiple provisioners ?

@tbugfinder the second one, a single resource should be made but I need to run the command once for each path_mapping. Would just running a shell script be better here?

I seem to get validation success by instead just creating multiple commands in a single string, like so:

join("; ", [for key, value in local.path_mappings : "az webapp config storage-account add --resource-group ${self.resource_group_name} --name ${self.name} --custom-id '${value.volume}' --storage-type AzureFiles --share-name ${azurerm_storage_share.stfs.name} --account-name ${azurerm_storage_account.st.name} --access-key ${azurerm_storage_account.st.primary_access_key} --mount-path '${value.path}'"])