## Manage PostgreSQL with Terraform

### Getting started

Set environment variable `TF_VAR_password` equal to `um_admin`'s password, which can be found in Secrets Manager under `gdb-mct-dev` account.

Ensure you've network access to database instance e.g. your IP address enlisted in the security group, or you're connected to development OpenVPN instance.

Linux/OsX users can use [direnv](https://direnv.net/) to automatically set environment variables. 

#### Import admin user

Import `um_admin` user, since it already exist. 

```shell
terraform import postgresql_role.main_admin um_admin
```

### Password management

We do not use Terraform to manage user passwords, because in this case they will be stored in a state file as a plain text. 

Please manually update user password after user creation using the following snippet.

```postgresql
ALTER ROLE alice WITH PASSWORD 'sup3rS3curePassw0rd!';
```

### Links

[documentation](https://registry.terraform.io/providers/cyrilgdn/postgresql/latest/docs)
