How do initialize a postgresql db in terraform's helm provider?

7/24/2019

I am unsuccessful so far in passing an initdbScript into a helm provider for terraform to create the database. Has anybody tried this?

This is my attempt for the .tf file:

resource "helm_release" "database" {
  name  = "database"
  chart = "stable/postgresql"

  set {
    name  = "postgresqlUsername"
    value = "user"
  }

  set {
    name  = "postgresqlPassword"
    value = "xxx"
  }

  set {
    name  = "initdbScripts"
    value = "init.sql: |${file("../backend/init.sql")}"
  }
} 

It looks like as helm does not accept the dictionary.

I get the error:

Error: rpc error: code = Unknown desc = release database failed: ConfigMap in version "v1" cannot be handled as a ConfigMap: v1.ConfigMap.Data: ReadMapCB: expect { or n, but found ", error found in #10 byte of ...|","data":"init.sql: |..., bigger context ...|{"apiVersion":"v1","data":"init.sql: |CREATE DATABASE test;\n","kind":"Config|...

I am using Terraform v0.12.5 + provider.helm v0.10.0 + provider.kubernetes v1.8.1

-- Bernd Prager
kubernetes
kubernetes-helm
postgresql
terraform

0 Answers