Skip to content

Commit 078c52c

Browse files
greutCyril Gaudinvthiery
authored
feat: use a randomly generated password for the owner when empty (#5)
Signed-off-by: Yoan Blanc <yblanc@edgelab.ch> Co-authored-by: Cyril Gaudin <cgaudin@edgelab.ch> Co-authored-by: Vincent Thiery <vjmthiery@gmail.com>
1 parent 0205f55 commit 078c52c

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,20 @@ In particular:
1919
- `${vault_backend_path}/${DB_NAME}_ro`, that obtains credentials for the `${DB_NAME}_ro` role;
2020
- `${vault_backend_path}/${DB_NAME}_rw`, that obtains credentials for the `${DB_NAME}_rw` role.
2121

22+
- When the intent is to use Vault, it's recommended to **NOT** provide the `owner_password`. In this case, it's not possible to log directly with the owner username, but only with the credentials generated by Vault.
23+
2224

2325
## Usage
2426

2527
```hcl
2628
module "foo" {
27-
source = "git@github.com:edgelaboratories/terraform-postgresql-db?ref=v0.3.1"
29+
source = "git@github.com:edgelaboratories/terraform-postgresql-db?ref=v0.4.0"
2830
2931
database = "foo"
30-
owner = "admin"
31-
owner_password = "admin"
32+
owner = "admin" # Optional, default to database name
33+
owner_password = "admin" # Optional when using Vault
3234
35+
# Optional
3336
vault_backend_path = "postgresql/elmer"
3437
vault_db_connection_name = "elmer"
3538
}

database.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
resource "postgresql_role" "owner" {
2-
name = var.owner
3-
login = true
2+
name = coalesce(var.owner, var.database)
3+
login = var.owner_password != null ? true : false
44
password = var.owner_password
55
roles = var.roles
66

variables.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ variable "schemas" {
1515
}
1616

1717
variable "owner" {
18-
description = "The name of the owner of the database"
18+
description = "The name of the owner of the database, defaults to database name"
19+
default = ""
1920
}
2021

2122
variable "owner_password" {
2223
description = "The password for the owner of the database"
24+
type = string
25+
default = null
2326
}
2427

2528
variable "roles" {

vault.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
locals {
22
vault_roles = var.vault_backend_path == "" ? {} : {
3-
"${postgresql_database.this.name}" = postgresql_role.owner.name
3+
"${postgresql_role.owner.name}" = postgresql_role.owner.name
44
"${postgresql_database.this.name}-ro" = postgresql_role.read_only.name
55
"${postgresql_database.this.name}-rw" = postgresql_role.read_write.name
66
}

0 commit comments

Comments
 (0)