This module is IaC - infrastructure as code which contains a nomad job of postgres.
make test
The command will run a standalone instance of postgres found in the example folder.
Name | Description | Type | Default | Required |
---|---|---|---|---|
nomad_datacenters | Nomad data centers | list(string) | ["dc1"] | no |
nomad_namespace | [Enterprise] Nomad namespace | string | "default" | no |
nomad_host_volume | Nomad host volume name | string | "persistence" | no |
service_name | Postgres service name | string | "postgres" | no |
container_port | Postgres port | number | 5432 | no |
container_image | Postgres docker image | string | "postgres:12-alpine" | no |
admin_user | Postgres admin username | string or data obj | "postgres" | yes |
admin_password | Postgres admin password | string or data obj | "postgres" | yes |
admin_password | Postgres database name | string | "metastore" | yes |
container_environment_variables | Postgres container environement variables | list(string) | ["PGDATA=/var/lib/postgresql/data"] | no |
volume_destination | Postgres volume destination | string | "/var/lib/postgresql/data" | no |
use_host_volume | Use nomad host volume | bool | false | no |
Name | Description | Type |
---|---|---|
service_name | Postgres service name | string |
username | Postgres username | string |
password | Postgres password | string |
database_name | Postgres database name | string |
port | Postgres port | number |
The example-code shows the minimum of what you need to use this module.
module "postgres" {
source = "github.com/fredrikhgrelland/terraform-nomad-postgres.git?ref=0.0.2"
# nomad
nomad_datacenters = ["dc1"]
nomad_namespace = "default"
nomad_host_volume = "persistence"
# postgres
service_name = "postgres"
container_image = "postgres:12-alpine"
container_port = 5432
admin_user = "postgres"
admin_password = "postgres"
database = "metastore"
volume_destination = "/var/lib/postgresql/data"
use_host_volume = true
container_environment_variables = ["PGDATA=/var/lib/postgresql/data"]
}
You can verify that postgres is running by checking the connection. This can be done using the consul
docker image to set up a proxy. Check out the required software section.
make proxy-to-postgres
We are using host volume to store postgres data.
If the use_host_volume
is set to true
, Postgres data will be available in root /persistence/postgres
folder inside the Vagrant box.
The postgres username and password is generated and put in /secret/postgres
inside Vault.
To get the username and password from Vault you can login to the Vault-UI with token master
and reveal the username and password in /secret/postgres
.
Alternatively, you can ssh into the vagrant box with vagrant ssh
, and use the vault binary to get the username and password. See the following commands:
# get username
vault kv get -field='username' secret/postgres
# get password
vault kv get -field='password' secret/postgres
This work is licensed under Apache 2 License. See LICENSE for full details.