apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres-fhir
  namespace: default
spec:
  selector:
    matchLabels:
      app: postgres-fhir
  template:
    metadata:
      annotations:
        vault.hashicorp.com/agent-init-first: "true"
        vault.hashicorp.com/agent-inject: "true"
        vault.hashicorp.com/agent-inject-secret-postgres: postgres-db/data/fhir
        vault.hashicorp.com/agent-inject-template-postgres: |
          {{- with secret "postgres-db/data/fhir" -}}
              export POSTGRES_DB={{ .Data.data.POSTGRES_DB }}
              export POSTGRES_USER={{ .Data.data.POSTGRES_USER }}
              export POSTGRES_PASSWORD={{ .Data.data.POSTGRES_PASSWORD }}
            {{- end -}}
        vault.hashicorp.com/agent-pre-populate-only: "true"
        vault.hashicorp.com/role: fhir-postgres-db
      labels:
        app: postgres-fhir
    spec:
      containers:
      - args:
        - -c
        - . /vault/secrets/postgres && /usr/local/bin/docker-entrypoint.sh postgres
        command:
        - /bin/sh
        env:
        - name: PROXY_ADDRESS_FORWARDING
          value: "true"
        image: postgres:latest
        imagePullPolicy: IfNotPresent
        name: postgres-fhir
        ports:
        - containerPort: 5432
          name: postgres-fhir
          protocol: TCP
        volumeMounts:
        - mountPath: /var/lib/postgresql/data
          name: postgresdb
      serviceAccount: fhir-postgres-db
      serviceAccountName: fhir-postgres-db
      terminationGracePeriodSeconds: 30
      volumes:
      - name: postgresdb
        persistentVolumeClaim:
          claimName: postgres-pv-claim