diff --git a/main.tf b/main.tf index 5890b75c..a472ce29 100644 --- a/main.tf +++ b/main.tf @@ -1,6 +1,7 @@ locals { port = "${var.port == "" ? "${var.engine == "aurora-postgresql" ? "5432" : "3306"}" : var.port}" master_password = "${var.password == "" ? random_id.master_password.b64 : var.password}" + db_subnet_group_name = "${var.db_subnet_group_name == "" ? join("", aws_db_subnet_group.this.*.name) : var.db_subnet_group_name}" backtrack_window = "${var.backtrack_window == "" ? "${var.engine == "aurora" ? "0" : ""}" : var.backtrack_window}" } @@ -10,6 +11,8 @@ resource "random_id" "master_password" { } resource "aws_db_subnet_group" "this" { + count = "${var.db_subnet_group_name == "" ? 1 : 0}" + name = "${var.name}" description = "For Aurora cluster ${var.name}" subnet_ids = ["${var.subnets}"] @@ -36,7 +39,7 @@ resource "aws_rds_cluster" "this" { preferred_backup_window = "${var.preferred_backup_window}" preferred_maintenance_window = "${var.preferred_maintenance_window}" port = "${local.port}" - db_subnet_group_name = "${aws_db_subnet_group.this.name}" + db_subnet_group_name = "${local.db_subnet_group_name}" vpc_security_group_ids = ["${concat(list(aws_security_group.this.id), var.vpc_security_group_ids)}"] scaling_configuration = "${var.scaling_configuration}" snapshot_identifier = "${var.snapshot_identifier}" @@ -60,7 +63,7 @@ resource "aws_rds_cluster_instance" "this" { engine_version = "${var.engine_version}" instance_class = "${var.instance_type}" publicly_accessible = "${var.publicly_accessible}" - db_subnet_group_name = "${aws_db_subnet_group.this.name}" + db_subnet_group_name = "${local.db_subnet_group_name}" db_parameter_group_name = "${var.db_parameter_group_name}" preferred_maintenance_window = "${var.preferred_maintenance_window}" apply_immediately = "${var.apply_immediately}" diff --git a/variables.tf b/variables.tf index 59511913..fd79427f 100644 --- a/variables.tf +++ b/variables.tf @@ -235,6 +235,11 @@ variable "vpc_security_group_ids" { default = [] } +variable "db_subnet_group_name" { + description = "The existing subnet group name to use" + default = "" +} + variable "backtrack_window" { description = "The target backtrack window, in seconds. Only available for aurora engine currently. To disable backtracking, set this value to 0. Defaults to 0. Must be between 0 and 259200 (72 hours)" default = "0"