Variable from for loop can not be seen in service configuration

hello,
I wrote this for loop to go through a dictionary, tested first with 1 key in the dict. However the icinga validation complains that it could not find the variable defined in the for loop. Could you please point out my mistake? Thanks!

const http_services = {
  "server1" = [{"service_name" = "app_http-Geoserver",uri = "/geoserver/rest/about/status",port = 9100,authorization = authorization_value},{"service_name" = "app_http-Geoserver-Security",uri = "/actuator/health",port = 9150}]
}
for (server => services in http_services) {
  for (service in services) {
    apply Service service["service_name"] {
      import "http-service-ssh"
      vars.uri = service["uri"]
      if (service["port"]) {
        vars.port = service["port"]
      }
      if (service["authorization"]) {
        vars.port = service["authorization"]
      }
      assign where host.name == server
    }
  }
}

Error: Error while evaluating expression: Tried to access undefined script variable ‘server’
Error: Error while evaluating expression: Tried to access undefined script variable ‘service’

Hello,

i edited your post for better readabillity.
If you do for loops you need to tell the dsl to use this variables, See this topic for details.

Regards,
Carsten