Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
vincetse committed Aug 11, 2019
1 parent 6874b13 commit 6fd8342
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
6 changes: 3 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ locals {
db_rw_pass = "${random_string.rw_pass.result}"
db_ro_user = "uro${random_string.ro_user.result}"
db_ro_pass = "${random_string.ro_pass.result}"
db_name = "${var.database_name}-${random_string.dbsuffix.result}-db"
db_name = "${var.database_name_prefix}_${random_string.dbsuffix.result}_db"
}

################################################################################
# The ro+rw roles that users inherit from
locals {
db_rw_role = "${local.db_name}-rw-role"
db_ro_role = "${local.db_name}-ro-role"
db_rw_role = "${local.db_name}_rw_role"
db_ro_role = "${local.db_name}_ro_role"
}

resource "postgresql_role" "rw" {
Expand Down
18 changes: 9 additions & 9 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
output "db-name" {
output "database_name" {
value = "${local.db_name}"
}

# rw role
output "db-rw-user" {
output "db_rw_user" {
value = "${local.db_rw_user}"
}

output "db-rw-pass" {
output "db_rw_pass" {
value = "${local.db_rw_pass}"
}

output "rw-psql" {
output "rw_psql" {
value = "PGHOST=${local.db_host} PGPORT=${local.db_port} PGUSER=${local.db_rw_user} PGPASSWORD=${local.db_rw_pass} PGDATABASE=${local.db_name} psql"
}

output "rw-database-url" {
output "rw_database_url" {
value = "postgres://${local.db_rw_user}:${local.db_rw_pass}@${local.db_host}:${local.db_port}/${local.db_name}"
}

# ro role
output "db-ro-user" {
output "db_ro_user" {
value = "${local.db_ro_user}"
}

output "db-ro-pass" {
output "db_ro_pass" {
value = "${local.db_ro_pass}"
}

output "ro-psql" {
output "ro_psql" {
value = "PGHOST=${local.db_host} PGPORT=${local.db_port} PGUSER=${local.db_ro_user} PGPASSWORD=${local.db_ro_pass} PGDATABASE=${local.db_name} psql"
}

output "ro-database-url" {
output "ro_database_url" {
value = "postgres://${local.db_ro_user}:${local.db_ro_pass}@${local.db_host}:${local.db_port}/${local.db_name}"
}
5 changes: 3 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
variable "database_name" {
variable "database_name_prefix" {
type = "string"
description = "Name of database to be created"
description = "Name prefix of database to be created. Actual database name will be returned in output."
}

variable "pg_host" {
Expand All @@ -11,6 +11,7 @@ variable "pg_host" {
variable "pg_port" {
type = "string"
description = "Postgresql port"
default = "5432"
}

variable "pg_user" {
Expand Down

0 comments on commit 6fd8342

Please sign in to comment.