Terragrunt - make dynamic group optional
You can make the block optional as follows:
  dynamic "group" {
    for_each = length(var.app_groups) > 0 : var.app_groups : []
    content {
      id       = group.value["id"]
      priority = group.value["priority"]
    }
  }

also your default value for app_groups should be:
variable "app_groups" {
  description = "Groups assigned to app"
  type        = list(map(any))
  default     = []
}


I'm using Okta provider to create okta_app_oauth and okta_app_group_assignments. My module looks like:
resource "okta_app_oauth" "app" {

  label                      = var.label
  type                       = var.type
  grant_types                = var.grant_types
  redirect_uris              = var.type != "service" ? var.redirect_uris : null
  response_types             = var.response_types
  login_mode                 = var.login_mode
  login_uri                  = var.login_uri
  post_logout_redirect_uris  = var.post_logout_redirect_uris
  consent_method             = var.consent_method
  token_endpoint_auth_method = var.token_endpoint_auth_method
  pkce_required              = var.token_endpoint_auth_method == "none" ? true : var.pkce_required
  lifecycle {
    ignore_changes = [
      client_basic_secret, groups
    ]
  }
}

resource "okta_app_group_assignments" "app" {
  app_id = okta_app_oauth.app.id
  dynamic "group" {
    for_each = var.app_groups
    content {
      id       = group.value["id"]
      priority = group.value["priority"]
    }
  }
}

And it works when I assign groups to application, but when I don't want to assign groups, I get error:
│ Error: Invalid index
│ 
│   on main.tf line 26, in resource "okta_app_group_assignments" "app":
│   26:       id       = group.value["id"]
│     ├────────────────
│     │ group.value is empty map of dynamic
│ 
│ The given key does not identify an element in this collection value.


in addition, my app_groups variable looks like:
variable "app_groups" {
  description = "Groups assigned to app"
  type        = list(map(any))
  default     = [{}]
}

I was trying to use lookup(group, "priority", null), but it wasn't resolving my problem. Can somebody help me with solving this?
