Skip to content

Commit

Permalink
feat: Add support for identifier_prefix (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
magreenbaum authored Jul 6, 2022
1 parent 89c3166 commit 125c426
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ Users have the ability to:
| <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 |
| <a name="input_identifier"></a> [identifier](#input\_identifier) | The name of the RDS instance | `string` | n/a | yes |
| <a name="input_instance_class"></a> [instance\_class](#input\_instance\_class) | The instance type of the RDS instance | `string` | `null` | no |
| <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 |
| <a name="input_iops"></a> [iops](#input\_iops) | The amount of provisioned IOPS. Setting this implies a storage\_type of 'io1' | `number` | `0` | no |
| <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 |
| <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 |
Expand Down
3 changes: 2 additions & 1 deletion examples/complete-postgres/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ module "db" {
module "db_default" {
source = "../../"

identifier = "${local.name}-default"
identifier = "${local.name}-default"
instance_use_identifier_prefix = true

create_db_option_group = false
create_db_parameter_group = false
Expand Down
5 changes: 3 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ module "db_option_group" {
module "db_instance" {
source = "./modules/db_instance"

create = local.create_db_instance
identifier = var.identifier
create = local.create_db_instance
identifier = var.identifier
use_identifier_prefix = var.instance_use_identifier_prefix

engine = var.engine
engine_version = var.engine_version
Expand Down
1 change: 1 addition & 0 deletions modules/db_instance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ No modules.
| <a name="input_tags"></a> [tags](#input\_tags) | A mapping of tags to assign to all resources | `map(string)` | `{}` | no |
| <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 |
| <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 |
| <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 |
| <a name="input_username"></a> [username](#input\_username) | Username for the master DB user | `string` | `null` | no |
| <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 |

Expand Down
6 changes: 5 additions & 1 deletion modules/db_instance/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ locals {

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

identifier = var.use_identifier_prefix ? null : var.identifier
identifier_prefix = var.use_identifier_prefix ? "${var.identifier}-" : null

# Replicas will use source metadata
username = var.replicate_source_db != null ? null : var.username
password = var.replicate_source_db != null ? null : var.password
Expand All @@ -26,7 +29,8 @@ resource "random_id" "snapshot_identifier" {
resource "aws_db_instance" "this" {
count = var.create ? 1 : 0

identifier = var.identifier
identifier = local.identifier
identifier_prefix = local.identifier_prefix

engine = local.engine
engine_version = local.engine_version
Expand Down
6 changes: 6 additions & 0 deletions modules/db_instance/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ variable "identifier" {
type = string
}

variable "use_identifier_prefix" {
description = "Determines whether to use `identifier` as is or create a unique identifier beginning with `identifier` as the specified prefix"
type = bool
default = false
}

variable "allocated_storage" {
description = "The allocated storage in gigabytes"
type = string
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ variable "identifier" {
type = string
}

variable "instance_use_identifier_prefix" {
description = "Determines whether to use `identifier` as is or create a unique identifier beginning with `identifier` as the specified prefix"
type = bool
default = false
}

variable "allocated_storage" {
description = "The allocated storage in gigabytes"
type = string
Expand Down

0 comments on commit 125c426

Please sign in to comment.