How to recursively create nested resources in Terraform?

I am trying to create nested management groups recursively in Terraform and I can’t seem to be able to achieve it using count / for / for_each.

Any idea on how something like this can be achieved but without hardcoding values in config?

    locals {
      managementGroups = [
        {
          id            = "MainGroupOne"
          displayName   = "Main Group One"
          subscriptions = []
          children = [
            {
              id          = "GroupOne"
              displayName = "Group One"
              subscriptions = [
                "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", "YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY"
              ]
              children = [
                {
                  id          = "ChildOne"
                  displayName = "Child One"
                  subscriptions = [
                    "ZZZZZZZZ-ZZZZ-ZZZZ-ZZZZ-ZZZZZZZZZZZZ"
                  ]
                  children = []
                },
              ]
            },
            {
              id            = "GroupTwo"
              displayName   = "Group Two"
              subscriptions = []
              children      = []
            }
          ]
        },
        {
          id            = "MainGroupTwo"
          displayName   = "Main Group Two"
          subscriptions = []
          children = [
            {
              id            = "GroupThree"
              displayName   = "Group Three"
              subscriptions = []
              children      = []
            }
          ]
        }
      ]
    }

Terraform isn’t really designed to be used this way. The Terraform way to do this would be to write a separate resource block for each group.