Skip to content

Instantly share code, notes, and snippets.

@anaisbetts
Created August 30, 2019 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anaisbetts/e59b9af4c2300043cfb711a058e63afc to your computer and use it in GitHub Desktop.
Save anaisbetts/e59b9af4c2300043cfb711a058e63afc to your computer and use it in GitHub Desktop.
PostgreSQL + Pulumi
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