name: "world"
description: "Exordos World element"
schema_version: 1
version: "0.0.3"
api_version: "v1"

requirements:
  core:
    from_version: "0.1.4"
  dbaas:
    from_version: "2.3.6"
  s3aas:
    from_version: "0.0.2"

resources:

  # IAM
  $core.iam.organizations:
    world_organization:
      name: "World organization"
      description: "World organization"

  $core.iam.projects:
    world_project:
      name: "World project"
      organization: $core.iam.organizations.$world_organization:uuid
      description: "World project"

  $core.iam.permissions:
    world_permission:
      name: "exordos_world.world.permission"

  $core.iam.permissionbinding:
    world_some_permission_binding:
      role: $core.iam.roles.$world_role:uuid
      permission: $core.iam.permissions.$world_permission:uuid
      project_id: "12345678-c625-4fee-81d5-f691897b8142"

  $core.iam.roles:
    world_role:
      name: world_role

  $core.iam.users:
    world_user:
      username: world
      first_name: "World system user"
      last_name: "World system user"
      email: "noreply+world@exordos.com"
      password: $core.secret.passwords.$world_user_password:value

  $core.iam.rolebinding:
    world_some_role_binding:
      role: $core.iam.roles.$world_role:uuid
      user: $core.iam.users.$world_user:uuid
      project: $core.iam.projects.$world_project:uuid

  # Compute
  $core.compute.nodes:
    world_node:
      name: world-node
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      cores: 1
      ram: 2048
      disk_spec:
        kind: "root_disk"
        size: 10
        image: "https://repo.exordos.com/exordos-base/latest/exordos-base.raw.zst"

  # Config
  $core.config.configs:
    world_config:
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      path: /etc/exordos_world.txt
      target:
        kind: node
        node: $core.compute.nodes.$world_node:uuid
      body:
        kind: text
        content: |
          f"
          HELLO=world
          "

  # EM
  $core.em.services:
    world_service:
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      name: "world-service"
      path: "/usr/bin/python3 -m http.server 8080"
      user: "ubuntu"
      group: "ubuntu"
      target:
        kind: "node"
        node: "$core.compute.nodes.$world_node:uuid"
      service_type:
        kind: "simple"
        count: 1
      target_status: "enabled"

  # VS
  $core.vs.values:
    world_value:
      name: world_value
      value: "hello world"
      project_id: "12345678-c625-4fee-81d5-f691897b8142"

  # LB
  $core.network.lb:
    world_lb:
      name: world-lb
      project_id: "12345678-c625-4fee-81d5-f691897b8142"

  $core.network.lb.$world_lb.backend_pools:
    world_backend_http:
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      parent: $core.network.lb.$world_lb:uuid
      endpoints:
        - kind: host
          host: $core.compute.nodes.$world_node:default_network:ipv4
          port: 8080
          weight: 1

  $core.network.lb.$world_lb.vhosts:
    world_http:
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      parent: $core.network.lb.$world_lb:uuid
      domains:
        - world.com
        - www.world.com
      protocol: http
      port: 8080

  $core.network.lb.$world_lb.vhosts.$world_http.routes:
    world_http_route:
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      parent: $core.network.lb.$world_lb.vhosts.$world_http:uuid
      condition:
        kind: prefix
        value: /
        actions:
          - kind: backend
            pool: $core.network.lb.$world_lb.backend_pools.$world_backend_http:uuid
            protocol:
              kind: http
        modifiers:
          - kind: auto_header
            headers:
              - 'Host'
              - 'X-Forwarded-For'
              - 'X-Forwarded-Port'
              - 'X-Forwarded-Proto'
              - 'X-Forwarded-Prefix'
        allowed_ips:
          - 0.0.0.0/0
  # DNS
  $core.dns.domains:
    some_world_domain:
      name: "some.world.com"
      project_id: "12345678-c625-4fee-81d5-f691897b8142"

  $core.dns.domains.$some_world_domain.records:
    some_soa_record:
      domain: "$core.dns.domains.$some_world_domain:uuid"
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      type: "SOA"
      record:
        kind: "SOA"
        name: "@"
        ttl: 3600
        retry: 3600
        expire: 604800
        serial: 0
        refresh: 10800
        primary_dns: "a.misconfigured.dns.server.invalid"
    some_core_record:
      domain: "$core.dns.domains.$some_world_domain:uuid"
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      type: "A"
      record:
        kind: "A"
        name: "core"
        address: $core.compute.nodes.$world_node:default_network:ipv4

  # DB
  $dbaas.types.postgres.instances:
    world_cluster_pg:
      name: "world-pg-cluster"
      nodes_number: 1
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      cpu: 1
      ram: 2048
      disk_size: 10
      version: $world.imports.$pg18:uuid

  $dbaas.types.postgres.instances.$world_cluster_pg.users:
    world_db_user:
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      name: world_db_user
      password: $core.secret.passwords.$world_db_password:value
      instance: $dbaas.types.postgres.instances.$world_cluster_pg:uuid

  $dbaas.types.postgres.instances.$world_cluster_pg.databases:
    world_db:
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      name: world_db
      owner: $dbaas.types.postgres.instances.$world_cluster_pg.users.$world_db_user:uuid
      instance: $dbaas.types.postgres.instances.$world_cluster_pg:uuid

  # S3
  $s3aas.types.s3.instances:
    world_s3:
      name: "world_s3"
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      cpu: $world.imports.$var_default_cores:value
      ram: $world.imports.$var_default_ram:value
      disk_size: 10
      nodes_number: 1
      kind: "single_node"
      version: $world.imports.$rustfs_1:uuid

  $s3aas.types.s3.instances.$world_s3.buckets:
    world_bucket:
      name: "world_bucket"
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      instance: $s3aas.types.s3.instances.$world_s3:uuid
      versioning_enabled: false
      quota_bytes: 0
      object_lock_enabled: false
      public: true

  # Secret
  $core.secret.passwords:
    world_db_password:
      name: world_db_password
      description: "World DB password"
      constructor:
        kind: plain
      method: AUTO_HEX

    world_user_password:
      name: world_user_password
      description: "World system user password"
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      constructor:
        kind: plain
      method: AUTO_HEX

imports:
  pg18:
    element: "$dbaas"
    kind: "resource"
    link: "$dbaas.types.postgres.versions.$pg18"
  rustfs_1:
    element: "$s3aas"
    kind: "resource"
    link: "$s3aas.types.s3.versions.$rustfs_1"
  var_default_cores:
    element: "$core"
    kind: "resource"
    link: "$core.vs.variables.$default_cores"
  var_default_ram:
    element: "$core"
    kind: "resource"
    link: "$core.vs.variables.$default_ram"