diff --git a/database.tf b/database.tf index 305924c..19bdeb3 100644 --- a/database.tf +++ b/database.tf @@ -1,3 +1,24 @@ +module "db_subnet_label" { + enabled = "${var.enabled}" + source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.0" + namespace = "${var.namespace}" + stage = "${var.stage}" + name = "db-subnet" + attributes = ["replica"] + tags = "${var.tags}" +} + +resource "aws_db_subnet_group" "replica" { + count = "${var.enabled == "true" ? 1 : 0}" + provider = "aws.replica" + + name = "${module.db_subnet_label.id}" + description = "Database subnet group for ${module.db_subnet_label.name}" + subnet_ids = ["${aws_subnet.zone_1.id}", "${aws_subnet.zone_2.id}", "${aws_subnet.zone_3.id}"] + + tags = "${module.db_subnet_label.tags}" +} + module "kms_label" { enabled = "${var.enabled}" source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.0" diff --git a/vpc.tf b/vpc.tf index c2c0537..22d9f77 100644 --- a/vpc.tf +++ b/vpc.tf @@ -18,9 +18,9 @@ resource "aws_vpc" "replica" { } locals { - zone_1_az = "${element(data.aws_availability_zones.available.names, 0)}" - zone_2_az = "${element(data.aws_availability_zones.available.names, 1)}" - zone_3_az = "${element(data.aws_availability_zones.available.names, 2)}" + zone_1_az = "${element(data.aws_availability_zones.available.names, 0)}" + zone_2_az = "${element(data.aws_availability_zones.available.names, 1)}" + zone_3_az = "${element(data.aws_availability_zones.available.names, 2)}" } module "zone_1_label" { @@ -82,24 +82,3 @@ resource "aws_subnet" "zone_3" { tags = "${module.zone_3_label.tags}" } - -module "db_subnet_label" { - enabled = "${var.enabled}" - source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.0" - namespace = "${var.namespace}" - stage = "${var.stage}" - name = "db-subnet" - attributes = ["replica"] - tags = "${var.tags}" -} - -resource "aws_db_subnet_group" "replica" { - count = "${var.enabled == "true" ? 1 : 0}" - provider = "aws.replica" - - name = "${module.db_subnet_label.id}" - description = "Database subnet group for ${module.db_subnet_label.name}" - subnet_ids = ["${aws_subnet.zone_1.id}", "${aws_subnet.zone_2.id}", "${aws_subnet.zone_1.id}"] - - tags = "${module.db_subnet_label.tags}" -}