Skip to content

Commit cc1cef1

Browse files
committed
feat: add db subnet group prefix
Signed-off-by: nitrocode <[email protected]>
1 parent a8501c4 commit cc1cef1

File tree

7 files changed

+20
-1
lines changed

7 files changed

+20
-1
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ Available targets:
408408
| <a name="input_db_name"></a> [db\_name](#input\_db\_name) | Database name (default is not to create a database) | `string` | `""` | no |
409409
| <a name="input_db_parameter_group_name"></a> [db\_parameter\_group\_name](#input\_db\_parameter\_group\_name) | The name to give to the created `aws_db_parameter_group` resource.<br/>If omitted, the module will generate a name. | `string` | `""` | no |
410410
| <a name="input_db_port"></a> [db\_port](#input\_db\_port) | Database port | `number` | `3306` | no |
411+
| <a name="input_db_subnet_group_name_prefix_enabled"></a> [db\_subnet\_group\_name\_prefix\_enabled](#input\_db\_subnet\_group\_name\_prefix\_enabled) | Set to `true` to use `name_prefix` to name of the DB subnet group name. Set to `false` to use `name` instead | `bool` | `false` | no |
411412
| <a name="input_deletion_protection"></a> [deletion\_protection](#input\_deletion\_protection) | If the DB instance should have deletion protection enabled | `bool` | `false` | no |
412413
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br/>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
413414
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br/>Map of maps. Keys are names of descriptors. Values are maps of the form<br/>`{<br/> format = string<br/> labels = list(string)<br/>}`<br/>(Type is `any` so the map values can later be enhanced to provide additional options.)<br/>`format` is a Terraform format string to be passed to the `format()` function.<br/>`labels` is a list of labels, in order, to pass to `format()` function.<br/>Label values will be normalized before being passed to `format()` so they will be<br/>identical to how they appear in `id`.<br/>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |

Diff for: docs/terraform.md

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
| <a name="input_db_name"></a> [db\_name](#input\_db\_name) | Database name (default is not to create a database) | `string` | `""` | no |
9595
| <a name="input_db_parameter_group_name"></a> [db\_parameter\_group\_name](#input\_db\_parameter\_group\_name) | The name to give to the created `aws_db_parameter_group` resource.<br/>If omitted, the module will generate a name. | `string` | `""` | no |
9696
| <a name="input_db_port"></a> [db\_port](#input\_db\_port) | Database port | `number` | `3306` | no |
97+
| <a name="input_db_subnet_group_name_prefix_enabled"></a> [db\_subnet\_group\_name\_prefix\_enabled](#input\_db\_subnet\_group\_name\_prefix\_enabled) | Set to `true` to use `name_prefix` to name of the DB subnet group name. Set to `false` to use `name` instead | `bool` | `false` | no |
9798
| <a name="input_deletion_protection"></a> [deletion\_protection](#input\_deletion\_protection) | If the DB instance should have deletion protection enabled | `bool` | `false` | no |
9899
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br/>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
99100
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br/>Map of maps. Keys are names of descriptors. Values are maps of the form<br/>`{<br/> format = string<br/> labels = list(string)<br/>}`<br/>(Type is `any` so the map values can later be enhanced to provide additional options.)<br/>`format` is a Terraform format string to be passed to the `format()` function.<br/>`labels` is a list of labels, in order, to pass to `format()` function.<br/>Label values will be normalized before being passed to `format()` so they will be<br/>identical to how they appear in `id`.<br/>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |

Diff for: examples/complete/fixtures.us-east-2.tfvars

+2
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@ parameter_group_name_prefix_enabled = true
4040
rds_cluster_identifier_prefix_enabled = true
4141

4242
security_group_name_prefix_enabled = true
43+
44+
db_subnet_group_name_prefix_enabled = true

Diff for: examples/complete/main.tf

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ module "rds_cluster" {
4949
parameter_group_name_prefix_enabled = var.parameter_group_name_prefix_enabled
5050
rds_cluster_identifier_prefix_enabled = var.rds_cluster_identifier_prefix_enabled
5151
security_group_name_prefix_enabled = var.security_group_name_prefix_enabled
52+
db_subnet_group_name_prefix_enabled = var.db_subnet_group_name_prefix_enabled
5253

5354
cluster_parameters = [
5455
{

Diff for: examples/complete/variables.tf

+5
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,8 @@ variable "security_group_name_prefix_enabled" {
110110
description = "Set to `true` to use `name_prefix` to name of the security group. Set to `false` to use `name` instead"
111111
}
112112

113+
variable "db_subnet_group_name_prefix_enabled" {
114+
type = bool
115+
default = false
116+
description = "Set to `true` to use `name_prefix` to name of the DB subnet group name. Set to `false` to use `name` instead"
117+
}

Diff for: main.tf

+4-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,10 @@ resource "aws_rds_cluster_instance" "default" {
405405

406406
resource "aws_db_subnet_group" "default" {
407407
count = local.enabled ? 1 : 0
408-
name = try(length(var.subnet_group_name), 0) == 0 ? module.this.id : var.subnet_group_name
408+
409+
name_prefix = var.db_subnet_group_name_prefix_enabled ? (try(length(var.subnet_group_name), 0) == 0 ? "${module.this.id}${module.delimiter.id}" : var.subnet_group_name) : null
410+
name = !var.db_subnet_group_name_prefix_enabled ? (try(length(var.subnet_group_name), 0) == 0 ? module.this.id : var.subnet_group_name) : null
411+
409412
description = "Allowed subnets for DB cluster instances"
410413
subnet_ids = var.subnets
411414
tags = module.this.tags

Diff for: variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,12 @@ variable "security_group_name_prefix_enabled" {
571571
description = "Set to `true` to use `name_prefix` to name of the security group. Set to `false` to use `name` instead"
572572
}
573573

574+
variable "db_subnet_group_name_prefix_enabled" {
575+
type = bool
576+
default = false
577+
description = "Set to `true` to use `name_prefix` to name of the DB subnet group name. Set to `false` to use `name` instead"
578+
}
579+
574580
variable "enable_global_write_forwarding" {
575581
type = bool
576582
default = null

0 commit comments

Comments
 (0)