apiVersion: v1
kind: ConfigMap
metadata:
  name: manila-db-init
  labels:
    system: openstack
    type: configuration
    component: database

data:
  db-init.sh: |
    #!/usr/bin/env bash
    export PGUSER=postgres
    psql <<- EOSQL
        CREATE DATABASE {{.Values.postgresql.postgresDatabase}};
        CREATE ROLE {{.Values.global.dbUser}} WITH ENCRYPTED PASSWORD '{{.Values.global.dbPassword | default (tuple . .Values.global.dbUser | include "postgres.password_for_user")}}' LOGIN;
        GRANT ALL PRIVILEGES ON DATABASE {{.Values.postgresql.postgresDatabase}} TO {{.Values.global.dbUser}};
    EOSQL
