Skip to content

Commit 125c426

Browse files
authored
feat: Add support for identifier_prefix (#416)
1 parent 89c3166 commit 125c426

File tree

7 files changed

+24
-4
lines changed

7 files changed

+24
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ Users have the ability to:
275275
| <a name="input_iam_database_authentication_enabled"></a> [iam\_database\_authentication\_enabled](#input\_iam\_database\_authentication\_enabled) | Specifies whether or not the mappings of AWS Identity and Access Management (IAM) accounts to database accounts are enabled | `bool` | `false` | no |
276276
| <a name="input_identifier"></a> [identifier](#input\_identifier) | The name of the RDS instance | `string` | n/a | yes |
277277
| <a name="input_instance_class"></a> [instance\_class](#input\_instance\_class) | The instance type of the RDS instance | `string` | `null` | no |
278+
| <a name="input_instance_use_identifier_prefix"></a> [instance\_use\_identifier\_prefix](#input\_instance\_use\_identifier\_prefix) | Determines whether to use `identifier` as is or create a unique identifier beginning with `identifier` as the specified prefix | `bool` | `false` | no |
278279
| <a name="input_iops"></a> [iops](#input\_iops) | The amount of provisioned IOPS. Setting this implies a storage\_type of 'io1' | `number` | `0` | no |
279280
| <a name="input_kms_key_id"></a> [kms\_key\_id](#input\_kms\_key\_id) | The ARN for the KMS encryption key. If creating an encrypted replica, set this to the destination KMS ARN. If storage\_encrypted is set to true and kms\_key\_id is not specified the default KMS key created in your account will be used | `string` | `null` | no |
280281
| <a name="input_license_model"></a> [license\_model](#input\_license\_model) | License model information for this DB instance. Optional, but required for some DB engines, i.e. Oracle SE1 | `string` | `null` | no |

examples/complete-postgres/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ module "db" {
124124
module "db_default" {
125125
source = "../../"
126126

127-
identifier = "${local.name}-default"
127+
identifier = "${local.name}-default"
128+
instance_use_identifier_prefix = true
128129

129130
create_db_option_group = false
130131
create_db_parameter_group = false

main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ module "db_option_group" {
6969
module "db_instance" {
7070
source = "./modules/db_instance"
7171

72-
create = local.create_db_instance
73-
identifier = var.identifier
72+
create = local.create_db_instance
73+
identifier = var.identifier
74+
use_identifier_prefix = var.instance_use_identifier_prefix
7475

7576
engine = var.engine
7677
engine_version = var.engine_version

modules/db_instance/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ No modules.
9393
| <a name="input_tags"></a> [tags](#input\_tags) | A mapping of tags to assign to all resources | `map(string)` | `{}` | no |
9494
| <a name="input_timeouts"></a> [timeouts](#input\_timeouts) | Updated Terraform resource management timeouts. Applies to `aws_db_instance` in particular to permit resource management times | `map(string)` | `{}` | no |
9595
| <a name="input_timezone"></a> [timezone](#input\_timezone) | Time zone of the DB instance. timezone is currently only supported by Microsoft SQL Server. The timezone can only be set on creation. See MSSQL User Guide for more information. | `string` | `null` | no |
96+
| <a name="input_use_identifier_prefix"></a> [use\_identifier\_prefix](#input\_use\_identifier\_prefix) | Determines whether to use `identifier` as is or create a unique identifier beginning with `identifier` as the specified prefix | `bool` | `false` | no |
9697
| <a name="input_username"></a> [username](#input\_username) | Username for the master DB user | `string` | `null` | no |
9798
| <a name="input_vpc_security_group_ids"></a> [vpc\_security\_group\_ids](#input\_vpc\_security\_group\_ids) | List of VPC security groups to associate | `list(string)` | `[]` | no |
9899

modules/db_instance/main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ locals {
33

44
final_snapshot_identifier = var.skip_final_snapshot ? null : "${var.final_snapshot_identifier_prefix}-${var.identifier}-${try(random_id.snapshot_identifier[0].hex, "")}"
55

6+
identifier = var.use_identifier_prefix ? null : var.identifier
7+
identifier_prefix = var.use_identifier_prefix ? "${var.identifier}-" : null
8+
69
# Replicas will use source metadata
710
username = var.replicate_source_db != null ? null : var.username
811
password = var.replicate_source_db != null ? null : var.password
@@ -26,7 +29,8 @@ resource "random_id" "snapshot_identifier" {
2629
resource "aws_db_instance" "this" {
2730
count = var.create ? 1 : 0
2831

29-
identifier = var.identifier
32+
identifier = local.identifier
33+
identifier_prefix = local.identifier_prefix
3034

3135
engine = local.engine
3236
engine_version = local.engine_version

modules/db_instance/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ variable "identifier" {
99
type = string
1010
}
1111

12+
variable "use_identifier_prefix" {
13+
description = "Determines whether to use `identifier` as is or create a unique identifier beginning with `identifier` as the specified prefix"
14+
type = bool
15+
default = false
16+
}
17+
1218
variable "allocated_storage" {
1319
description = "The allocated storage in gigabytes"
1420
type = string

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ variable "identifier" {
33
type = string
44
}
55

6+
variable "instance_use_identifier_prefix" {
7+
description = "Determines whether to use `identifier` as is or create a unique identifier beginning with `identifier` as the specified prefix"
8+
type = bool
9+
default = false
10+
}
11+
612
variable "allocated_storage" {
713
description = "The allocated storage in gigabytes"
814
type = string

0 commit comments

Comments
 (0)