Is there a way to create for_each loops for created resource IDs?

Hi,

I’ve got some issues with broken icons for AVD remote applications that I’m trying to fix, one suggested fix is using AzAPI, I’ve got 28 applications that I need a for_each loop to run on to update the app description based on another article I’ve seen.

I want to run a for_each article like the below but I’m getting an error which is also noted below

Code:


resource "azapi_update_resource" "update_app_description" {
  for_each = azurerm_virtual_desktop_application.*.id

  type        = "Microsoft.DesktopVirtualization/applicationGroups/applications@2023-09-05"
  resource_id = each.value

  body = {
    properties = {
      description = "Remote App"
    }
  }
}

Error:
│ on app.tf line 374, in resource “azapi_update_resource” “update_app_description”:
│ 374: resource_id = azurerm_virtual_desktop_application.*.id

│ A reference to a resource type must be followed by at least one attribute
│ access, specifying the resource name.

What’s the correct way of doing this or is there a better way around it?

The syntax error is because the reference azurerm_virtual_desktop_application.*.id is missing the resource name in the identifier.

The result of a splat expression is also always a list or tuple, so it’s not applicable in a for_each context. If the azurerm_virtual_desktop_application resource also uses for_each, it’s common to simply reference the resource address directly, otherwise you will need to construct a map from the list of instances.