name: "{{ project_name }}"
description: "{{ manifest_description }}"
schema_version: 1
version: "{{ "{{" }} version {{ "}}" }}"
api_version: "v1"

requirements:
  core:
    from_version: "0.0.0"
  dbaas:
    from_version: "0.2.1"
  communal_pg_cluster:
    from_version: "0.2.2"


resources:

  # Compute
  $core.compute.sets:
    {{ project_name | replace('-', '_') }}_set:
      name: "{{ project_name | replace('_', '-') }}"
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      cores: ${{ project_name | replace('-', '_') }}.imports.$var_default_cores:value
      ram: ${{ project_name | replace('-', '_') }}.imports.$var_default_ram:value
      replicas: ${{ project_name | replace('-', '_') }}.imports.$var_default_replicas:value
      disk_spec:
        kind: "root_disk"
        size: 10
        image: "{{ "{{" }} repository | default('{{ repository }}') {{ "}}" }}/{{ project_name }}/{{ "{{" }} version {{ "}}" }}/images/{{ project_name | replace('_', '-') }}.raw.gz"
  
  # Secret
  $core.secret.passwords:
    db_password:
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      name: "{{ project_name | replace('_', '-') }}-pg-pass"
      description: "{{ project_name | replace('_', '-') }} password"

  # PG
  $dbaas.types.postgres.instances.$cluster_pg.users:
    db_user:
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      name: "{{ pgsql_username }}"
      password: $core.secret.passwords.$db_password:value
      instance: ${{ project_name | replace('-', '_') }}.imports.$communal_pg_cluster:uuid

  $dbaas.types.postgres.instances.$cluster_pg.databases:
    database:
      project_id: "12345678-c625-4fee-81d5-f691897b8142"
      name: "{{ pgsql_database_name }}"
      owner: $dbaas.types.postgres.instances.$cluster_pg.users.$db_user:uuid
      instance: ${{ project_name | replace('-', '_') }}.imports.$communal_pg_cluster:uuid

imports:
  var_default_replicas:
    element: "$core"
    kind: "resource"
    link: "$core.vs.variables.$default_replicas"
  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"
  communal_pg_cluster:
    element: "$communal_pg_cluster"
    kind: "resource"
    link: "$communal_pg_cluster.types.postgres.instances.$cluster_pg"
