General Cleanup
This commit is contained in:
parent
f268bd5a65
commit
a7ccc1f2b1
6 changed files with 16 additions and 15 deletions
|
@ -1,3 +1,3 @@
|
|||
module "admin_identity" {
|
||||
source = "github.com/matthewbaggett/terraform_modules//utils/identity"
|
||||
source = "../../../../utils/identity"
|
||||
}
|
|
@ -14,7 +14,6 @@ resource "local_file" "debug" {
|
|||
resolved = {
|
||||
engine = data.aws_rds_engine_version.latest.engine,
|
||||
version = data.aws_rds_engine_version.latest.version,
|
||||
match = data.aws_rds_engine_version.latest,
|
||||
}
|
||||
}
|
||||
#endpoints = {
|
||||
|
@ -43,7 +42,6 @@ resource "local_file" "debug_result" {
|
|||
resolved = {
|
||||
engine = data.aws_rds_engine_version.latest.engine,
|
||||
version = data.aws_rds_engine_version.latest.version,
|
||||
match = data.aws_rds_engine_version.latest,
|
||||
}
|
||||
}
|
||||
endpoints = aws_db_instance.instance.endpoint
|
||||
|
|
|
@ -4,7 +4,6 @@ module "tenants" {
|
|||
debug_path = local.debug_path
|
||||
username = each.value.username
|
||||
database = each.value.database
|
||||
vpc_id = data.aws_vpc.current.id
|
||||
engine = var.engine
|
||||
admin_identity = module.admin_identity
|
||||
endpoint = local.endpoints.write
|
||||
|
|
|
@ -5,12 +5,12 @@ locals {
|
|||
endpoints = {
|
||||
write = {
|
||||
# Host should be the same as the cluster endpoint, sans the port
|
||||
host = split(":", aws_rds_cluster_endpoint.endpoint["write"].endpoint)[0]
|
||||
port = split(":", aws_rds_cluster_endpoint.endpoint["write"].endpoint)[1]
|
||||
host = aws_rds_cluster_endpoint.endpoint["write"].endpoint
|
||||
port = local.port
|
||||
}
|
||||
read = {
|
||||
host = split(":", aws_rds_cluster_endpoint.endpoint["read"].endpoint)[0]
|
||||
port = split(":", aws_rds_cluster_endpoint.endpoint["read"].endpoint)[1]
|
||||
host = aws_rds_cluster_endpoint.endpoint["read"].endpoint
|
||||
port = local.port
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,13 +4,17 @@ variable "endpoint" {
|
|||
port = number
|
||||
})
|
||||
description = "The endpoint of the RDS cluster or instance"
|
||||
validation {
|
||||
error_message = "Host isn't supposed to contain a port!"
|
||||
condition = can(regex("^[^:]+$", var.endpoint.host))
|
||||
}
|
||||
}
|
||||
locals {
|
||||
db_tunnel_remote = {
|
||||
host = var.endpoint.host
|
||||
port = local.is_mysql ? 3306 : 5432
|
||||
port = local.is_mysql ? 3306 : (local.is_postgres ? 5432 : null)
|
||||
}
|
||||
mysql_command = try("${var.mysql_binary} -h ${data.ssh_tunnel.db.local.host} -P ${data.ssh_tunnel.db.local.port} -u ${var.admin_identity.username}", "")
|
||||
mysql_command = try("${var.mysql_binary} --ssl-verify-server-cert=false -h ${data.ssh_tunnel.db.local.host} -P ${data.ssh_tunnel.db.local.port} -u ${var.admin_identity.username}", "")
|
||||
postgres_command = try("${var.postgres_binary} -h ${data.ssh_tunnel.db.local.host} -p ${data.ssh_tunnel.db.local.port} -U ${var.admin_identity.username} -d ${var.admin_identity.username}", "")
|
||||
database_environment_variables = {
|
||||
PGPASSWORD = !local.is_mysql ? nonsensitive(var.admin_identity.password) : null,
|
||||
|
@ -32,8 +36,12 @@ data "ssh_tunnel" "db" {
|
|||
remote = local.db_tunnel_remote
|
||||
}
|
||||
resource "terraform_data" "db" {
|
||||
connection {
|
||||
host = data.ssh_tunnel.db.remote.host
|
||||
port = data.ssh_tunnel.db.remote.port
|
||||
}
|
||||
provisioner "local-exec" {
|
||||
command = "echo 'Connecting to \"${local.db_tunnel_remote.host}:${local.db_tunnel_remote.port}\" as \"${var.admin_identity.username}\" via \"${data.ssh_tunnel.db.connection_name}\"'"
|
||||
command = "echo 'Connecting to ${local.db_tunnel_remote.host}:${local.db_tunnel_remote.port} as ${var.admin_identity.username} via ${data.ssh_tunnel.db.connection_name}'"
|
||||
}
|
||||
provisioner "local-exec" {
|
||||
command = (local.is_mysql
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
variable "vpc_id" {
|
||||
type = string
|
||||
description = "VPC ID"
|
||||
}
|
||||
variable "username" {
|
||||
type = string
|
||||
description = "The username for the tenant"
|
||||
|
|
Loading…
Reference in a new issue