Created
August 30, 2019 05:27
-
-
Save anaisbetts/e59b9af4c2300043cfb711a058e63afc to your computer and use it in GitHub Desktop.
PostgreSQL + Pulumi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as pulumi from "@pulumi/pulumi"; | |
import * as docker from "@pulumi/docker"; | |
import * as pg from '@pulumi/postgresql'; | |
const cfg = new pulumi.Config(); | |
const network = new docker.Network("net"); | |
const pgImg = new docker.RemoteImage("postgresql-image", { | |
name: "postgres:11", | |
keepLocally: true | |
}); | |
const pgVol = new docker.Volume('pgdata'); | |
const pgContainer = new docker.Container("postgres", { | |
image: pgImg.name, | |
networksAdvanced: [{ name: network.name }], | |
restart: "on-failure", | |
volumes: [{ volumeName: pgVol.name, containerPath: '/var/lib/postgresql/data' }], | |
envs: [ | |
`POSTGRES_USER=${cfg.require('pguser')}`, | |
cfg.requireSecret('pgpass').apply(p => `POSTGRES_PASSWORD=${p}`), | |
], | |
ports: [{ internal: 5432, external: 5432 }] | |
}); | |
pg.config.host = 'localhost'; | |
pg.config.username = cfg.require('pguser'); | |
cfg.requireSecret('pgpass').apply(p => pg.config.password = p); | |
const db = new pg.Database('MyCoolDatabase'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment