From 9d70697c538268d23e7de05268cd5c5f5df974b3 Mon Sep 17 00:00:00 2001 From: Kai Ehrhardt Date: Fri, 9 Aug 2024 16:28:38 +0200 Subject: [PATCH] fix: add customizable final_snapshot_identifier to be able to have multiple db apply/destroy lifecycles in the same account --- docs/terraform.md | 1 + main.tf | 2 +- variables.tf | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/terraform.md b/docs/terraform.md index a1e3edd..9abc102 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -71,6 +71,7 @@ | [engine](#input\_engine) | The name of the database engine to be used for this DB cluster. Defaults to `docdb`. Valid values: `docdb` | `string` | `"docdb"` | no | | [engine\_version](#input\_engine\_version) | The version number of the database engine to use | `string` | `"3.6.0"` | no | | [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no | +| [final\_snapshot\_identifier](#input\_final\_snapshot\_identifier) | Name of the final DB snapshot, if skip_final_snapshot is false. | `string` | `""` | no | | [external\_security\_group\_id\_list](#input\_external\_security\_group\_id\_list) | List of external security group IDs to attach to the Document DB | `list(string)` | `[]` | no | | [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).
Set to `0` for unlimited length.
Set to `null` for keep the existing setting, which defaults to `0`.
Does not affect `id_full`. | `number` | `null` | no | | [instance\_class](#input\_instance\_class) | The instance class to use. For more details, see https://docs.aws.amazon.com/documentdb/latest/developerguide/db-instance-classes.html#db-instance-class-specs | `string` | `"db.r4.large"` | no | diff --git a/main.tf b/main.tf index 496678b..1be9ccd 100644 --- a/main.tf +++ b/main.tf @@ -64,7 +64,7 @@ resource "aws_docdb_cluster" "default" { backup_retention_period = var.retention_period preferred_backup_window = var.preferred_backup_window preferred_maintenance_window = var.preferred_maintenance_window - final_snapshot_identifier = lower(module.this.id) + final_snapshot_identifier = var.final_snapshot_identifier != "" ? var.final_snapshot_identifier : lower(module.this.id) skip_final_snapshot = var.skip_final_snapshot deletion_protection = var.deletion_protection apply_immediately = var.apply_immediately diff --git a/variables.tf b/variables.tf index f622a4f..a5bd53c 100644 --- a/variables.tf +++ b/variables.tf @@ -81,6 +81,12 @@ variable "snapshot_identifier" { description = "Specifies whether or not to create this cluster from a snapshot. You can use either the name or ARN when specifying a DB cluster snapshot, or the ARN when specifying a DB snapshot" } +variable "final_snapshot_identifier" { + type = string + default = "" + description = "Name of the final DB snapshot, if skip_final_snapshot is false." +} + variable "db_port" { type = number default = 27017