-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvault_postgres.tf
30 lines (27 loc) · 1.17 KB
/
vault_postgres.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
resource "vault_mount" "postgres" {
provider = vault.app
path = "postgres"
type = "database"
}
resource "vault_database_secret_backend_connection" "postgres-con" {
provider = vault.app
backend = vault_mount.postgres.path
name = "postgres-con"
allowed_roles = ["postgres-role"]
postgresql {
connection_url = "postgres://${data.aws_db_instance.postgres.master_username}:${var.postgres_password}@${data.aws_db_instance.postgres.endpoint}/${data.aws_db_instance.postgres.db_name}" #?sslmode=disable"
max_open_connections = -1
}
}
resource "vault_database_secret_backend_role" "postgres-role" {
provider = vault.app
depends_on = [vault_database_secret_backend_connection.postgres-con]
backend = vault_mount.postgres.path
name = "postgres-role"
db_name = vault_database_secret_backend_connection.postgres-con.name
creation_statements = ["CREATE ROLE \"{{name}}\" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}';"]
revocation_statements = [
"REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA public FROM \"{{name}}\";",
"DROP USER \"{{name}}\";",
]
}