Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.

Commit

Permalink
Revert "Move external db out of module."
Browse files Browse the repository at this point in the history
This reverts commit f6a7355.
  • Loading branch information
Pivotal committed Mar 26, 2018
1 parent 8a9d19c commit 0736b12
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 24 deletions.
5 changes: 4 additions & 1 deletion cloud_sql.tf → external_database/cloud_sql.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
resource "random_id" "db-name" {
byte_length = 8
count = "${var.count}"
}

resource "google_sql_database_instance" "master" {
Expand All @@ -8,7 +9,7 @@ resource "google_sql_database_instance" "master" {
name = "${var.env_name}-${replace(lower(random_id.db-name.b64), "_", "-")}"

settings {
tier = "db-f1-micro"
tier = "${var.sql_db_tier}"

ip_configuration = {
ipv4_enabled = true
Expand All @@ -21,4 +22,6 @@ resource "google_sql_database_instance" "master" {
]
}
}

count = "${var.count}"
}
2 changes: 2 additions & 0 deletions opsman_database.tf → external_database/opsman_database.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ resource "google_sql_database" "opsman" {
name = "${var.env_name}"
instance = "${google_sql_database_instance.master.name}"
depends_on = ["google_sql_database.nfsvolume"]

count = "${var.count}"
}
29 changes: 29 additions & 0 deletions external_database/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
output "sql_db_ip" {
value = "${element(concat(google_sql_database_instance.master.*.ip_address.0.ip_address, list("")), 0)}"
}

output "opsman_sql_db_name" {
value = "${element(concat(google_sql_database.opsman.*.name, list("")), 0)}"
}

output "opsman_sql_username" {
value = "${element(concat(random_id.opsman_db_username.*.b64, list("")), 0)}"
}

output "opsman_sql_password" {
sensitive = true
value = "${element(concat(random_id.opsman_db_password.*.b64, list("")), 0)}"
}

output "pas_sql_username" {
value = "${element(concat(random_id.pas_db_username.*.b64, list("")), 0)}"
}

output "pas_sql_password" {
sensitive = true
value = "${element(concat(random_id.pas_db_password.*.b64, list("")), 0)}"
}

output "ip" {
value = "${element(concat(google_sql_database_instance.master.*.ip_address.0.ip_address, list("")), 0)}"
}
28 changes: 28 additions & 0 deletions pas_database.tf → external_database/pas_database.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,110 @@ resource "google_sql_database" "uaa" {
name = "uaa"
instance = "${google_sql_database_instance.master.name}"
depends_on = ["google_sql_user.pas", "google_sql_user.opsman"]

count = "${var.count}"
}

resource "google_sql_database" "ccdb" {
name = "ccdb"
instance = "${google_sql_database_instance.master.name}"
depends_on = ["google_sql_database.uaa"]

count = "${var.count}"
}

resource "google_sql_database" "notifications" {
name = "notifications"
instance = "${google_sql_database_instance.master.name}"
depends_on = ["google_sql_database.ccdb"]

count = "${var.count}"
}

resource "google_sql_database" "autoscale" {
name = "autoscale"
instance = "${google_sql_database_instance.master.name}"
depends_on = ["google_sql_database.notifications"]

count = "${var.count}"
}

resource "google_sql_database" "app_usage_service" {
name = "app_usage_service"
instance = "${google_sql_database_instance.master.name}"
depends_on = ["google_sql_database.autoscale"]

count = "${var.count}"
}

resource "google_sql_database" "console" {
name = "console"
instance = "${google_sql_database_instance.master.name}"
depends_on = ["google_sql_database.app_usage_service"]

count = "${var.count}"
}

resource "google_sql_database" "diego" {
name = "diego"
instance = "${google_sql_database_instance.master.name}"
depends_on = ["google_sql_database.console"]

count = "${var.count}"
}

resource "google_sql_database" "routing" {
name = "routing"
instance = "${google_sql_database_instance.master.name}"
depends_on = ["google_sql_database.diego"]

count = "${var.count}"
}

resource "google_sql_database" "account" {
name = "account"
instance = "${google_sql_database_instance.master.name}"
depends_on = ["google_sql_database.routing"]

count = "${var.count}"
}

resource "google_sql_database" "networkpolicyserver" {
name = "networkpolicyserver"
instance = "${google_sql_database_instance.master.name}"
depends_on = ["google_sql_database.account"]

count = "${var.count}"
}

resource "google_sql_database" "nfsvolume" {
name = "nfsvolume"
instance = "${google_sql_database_instance.master.name}"
depends_on = ["google_sql_database.networkpolicyserver"]

count = "${var.count}"
}

resource "google_sql_database" "silk" {
name = "silk"
instance = "${google_sql_database_instance.master.name}"
depends_on = ["google_sql_database.nfsvolume"]

count = "${var.count}"
}

resource "google_sql_database" "locket" {
name = "locket"
instance = "${google_sql_database_instance.master.name}"
depends_on = ["google_sql_database.silk"]

count = "${var.count}"
}

resource "google_sql_database" "credhub" {
name = "credhub"
instance = "${google_sql_database_instance.master.name}"
depends_on = ["google_sql_database.locket"]

count = "${var.count}"
}
8 changes: 8 additions & 0 deletions sql_users.tf → external_database/sql_users.tf
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
resource "random_id" "opsman_db_username" {
byte_length = 8
count = "${var.count}"
}

resource "random_id" "opsman_db_password" {
byte_length = 32
count = "${var.count}"
}

resource "random_id" "pas_db_username" {
byte_length = 8
count = "${var.count}"
}

resource "random_id" "pas_db_password" {
byte_length = 32
count = "${var.count}"
}

resource "google_sql_user" "pas" {
name = "${random_id.pas_db_username.b64}"
password = "${random_id.pas_db_password.b64}"
instance = "${google_sql_database_instance.master.name}"
host = "${var.pas_sql_db_host}"

count = "${var.count}"
}

resource "google_sql_user" "opsman" {
Expand All @@ -27,4 +33,6 @@ resource "google_sql_user" "opsman" {
instance = "${google_sql_database_instance.master.name}"
host = "${var.opsman_sql_db_host}"
depends_on = ["google_sql_user.pas"]

count = "${var.count}"
}
11 changes: 11 additions & 0 deletions external_database/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
variable "count" {}

variable "region" {}

variable "env_name" {}

variable "sql_db_tier" {}

variable "pas_sql_db_host" {}

variable "opsman_sql_db_host" {}
13 changes: 13 additions & 0 deletions modules.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
module "external_database" {
source = "./external_database"

count = "${var.external_database ? 1 : 0}"

env_name = "${var.env_name}"
region = "${var.region}"
sql_db_tier = "db-f1-micro"

pas_sql_db_host = "${var.pas_sql_db_host}"
opsman_sql_db_host = "${var.opsman_sql_db_host}"
}

module "isolation_segment" {
source = "./isolation_segment"

Expand Down
46 changes: 23 additions & 23 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ output "network_name" {
value = "${google_compute_network.pcf-network.name}"
}

output "sql_db_ip" {
value = "${module.external_database.ip}"
}

output "management_subnet_gateway" {
value = "${google_compute_subnetwork.management-subnet.gateway_address}"
}
Expand Down Expand Up @@ -195,6 +199,24 @@ output "director_blobstore_bucket" {
value = "${element(concat(google_storage_bucket.director.*.name, list("")), 0)}"
}

output "pas_sql_username" {
value = "${module.external_database.pas_sql_username}"
}

output "pas_sql_password" {
sensitive = true
value = "${module.external_database.pas_sql_password}"
}

output "opsman_sql_username" {
value = "${module.external_database.opsman_sql_username}"
}

output "opsman_sql_password" {
sensitive = true
value = "${module.external_database.opsman_sql_password}"
}

output "ops_manager_ssh_private_key" {
sensitive = true
value = "${tls_private_key.ops-manager.private_key_pem}"
Expand All @@ -213,30 +235,8 @@ output "dns_managed_zone" {
value = "${google_dns_managed_zone.env_dns_zone.name}"
}

output "sql_db_ip" {
value = "${google_sql_database_instance.master.ip_address.0.ip_address}"
}

output "opsman_sql_db_name" {
value = "${google_sql_database.opsman.name}"
}

output "opsman_sql_username" {
value = "${random_id.opsman_db_username.b64}"
}

output "opsman_sql_password" {
sensitive = true
value = "${random_id.opsman_db_password.b64}"
}

output "pas_sql_username" {
value = "${random_id.pas_db_username.b64}"
}

output "pas_sql_password" {
sensitive = true
value = "${random_id.pas_db_password.b64}"
value = "${module.external_database.opsman_sql_db_name}"
}

// PKS output
Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ variable "create_iam_service_account_members" {
default = true
}

variable "external_database" {
description = "standups up a cloud sql database instance for the ops manager and PAS"
default = false
}

/******************
* OpsMan Options *
******************/
Expand Down

0 comments on commit 0736b12

Please sign in to comment.