From 6fd834243483551f0ef2ab888a89096457e58397 Mon Sep 17 00:00:00 2001 From: Vince Tse Date: Fri, 9 Aug 2019 12:43:46 +0000 Subject: [PATCH] Clean up --- main.tf | 6 +++--- outputs.tf | 18 +++++++++--------- variables.tf | 5 +++-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/main.tf b/main.tf index 7faf238..4aa2a26 100644 --- a/main.tf +++ b/main.tf @@ -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" { diff --git a/outputs.tf b/outputs.tf index 1d465db..0458191 100644 --- a/outputs.tf +++ b/outputs.tf @@ -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}" } diff --git a/variables.tf b/variables.tf index 65404d9..6ccb96b 100644 --- a/variables.tf +++ b/variables.tf @@ -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" { @@ -11,6 +11,7 @@ variable "pg_host" { variable "pg_port" { type = "string" description = "Postgresql port" + default = "5432" } variable "pg_user" {