How to create several resources using for_each and a map?

I would like to define all the resources in tfvars to create resources. I created a map of items that should map to values that the resource would use, but I am getting stuck for blocks that are in the resource. I am not sure how to do this.

resource "cloudflare_page_rule" "some_server_1" {
  actions {
    always_use_https         = "false"
    automatic_https_rewrites = "on"
    disable_apps             = "false"
    disable_performance      = "false"
    disable_railgun          = "false"
    disable_security         = "false"
    disable_zaraz            = "false"
    edge_cache_ttl           = "0"
    ssl                      = "flexible"
  }

  priority = "1"
  status   = "active"
  target   = "some-server.example.com/*"
  zone_id  = "12345678901234567890123456789012"
}

So instead, I would create values like this (using only one item, for brevity):

My tfvars looks like this:

page_rules = {
  some_server_1 = {
    actions = {
      always_use_https         = false
      automatic_https_rewrites = "on"
      disable_apps             = false
      disable_performance      = false
      disable_railgun          = false
      disable_security         = false
      disable_zaraz            = false
      edge_cache_ttl           = 1
      ssl                      = "flexible"
    }

    priority = 1
    status   = "active"
    target   = "some-server.example.com/*"
    zone_id  = "12345678901234567890123456789012"
  }
}

This is where I am getting stuck, I am not sure how to handle the block.

# failed attempt 1 - An argument named "actions" is not expected here. Did you mean to define a block of type "actions"
resource "cloudflare_page_rule" "default" {
  for_each = var.page_rules
  actions  = each.value.actions
  priority = each.value.priority
  status   = each.value.status
  target   = each.value.target
  zone_id  = each.value.zone_id
}

But this didn’t work, so I tried dynamic block, but this didn’t work either:

# failure 2 - This value does not have any indices.
resource "cloudflare_page_rule" "default" {
  for_each = var.page_rules
  dynamic "actions" {
    for_each = each.value.actions

    content {
      always_use_https         = actions.value["always_use_https"]
      automatic_https_rewrites = actions.value["automatic_https_rewrites"]
      disable_apps             = actions.value["disable_apps"]
      disable_performance      = actions.value["disable_performance"]
      disable_railgun          = actions.value["disable_railgun"]
      disable_security         = actions.value["disable_security"]
      disable_zaraz            = actions.value["disable_zaraz"]
      edge_cache_ttl           = actions.value["edge_cache_ttl"]
      ssl                      = actions.value["ssl"]
    }
  }

  priority = each.value.priority
  status   = each.value.status
  target   = each.value.target
  zone_id  = each.value.zone_id
}

I am lost on how to do this. I combed through the docs, google search, but I don’t find anything yet that could answer this.

I noticed that the docs are incomplete (ref).

It may be obvious to some, but really, need to see an example values of the variables for nested blocks. It is not quite clear otherwise.

I found the solution. I had to put the actions map in a one element set. It’s implicitly documented and subtle to newbies, not very clear.