Skip to content

Commit 662b481

Browse files
authored
enhancement: Allow subnet group to be supplied when using the database module (#51)
1 parent 68fdf1a commit 662b481

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

modules/database/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Create an RDS database.
2323
|------|-------------|------|---------|:--------:|
2424
| allowed\_security\_group\_id | The security group to allow access | `any` | n/a | yes |
2525
| database\_engine | Which database engine to use, currently supports `postgres` or `mysql` | `any` | n/a | yes |
26+
| db\_subnet\_group | The subnet group to create dbs in. The default is to use the one created by the vpc module | `string` | `""` | no |
2627
| environment | The environment (stage/prod) | `any` | n/a | yes |
2728
| instance\_class | The AWS instance class of the db | `any` | n/a | yes |
2829
| password\_secret\_suffix | Suffix to add to the secret that will be generated containing the database credentials | `any` | n/a | yes |

modules/database/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ module "rds_postgres" {
7373

7474
# Subnet is created by the vpc module
7575
create_db_subnet_group = false
76-
db_subnet_group_name = "${var.project}-${var.environment}-vpc"
76+
db_subnet_group_name = var.db_subnet_group != "" ? var.db_subnet_group : "${var.project}-${var.environment}-vpc"
7777

7878
# DB parameter and option group
7979
family = "postgres11"
@@ -123,7 +123,7 @@ module "rds_mysql" {
123123

124124
# Subnet is created by the vpc module
125125
create_db_subnet_group = false
126-
db_subnet_group_name = "${var.project}-${var.environment}-vpc"
126+
db_subnet_group_name = var.db_subnet_group != "" ? var.db_subnet_group : "${var.project}-${var.environment}-vpc"
127127

128128
# DB parameter and option group
129129
family = "mysql5.7"

modules/database/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ variable "allowed_security_group_id" {
1919
description = "The security group to allow access"
2020
}
2121

22+
variable "db_subnet_group" {
23+
description = "The subnet group to create dbs in. The default is to use the one created by the vpc module"
24+
default = ""
25+
}
26+
2227
variable "instance_class" {
2328
description = "The AWS instance class of the db"
2429
}

0 commit comments

Comments
 (0)