Skip to content

Commit 7ce592e

Browse files
author
air3ijai
authored
feat: Do not create snapshot_identifier when skip_final_snapshot = true (#332)
* Do not create snapshot_identifier when skip_final_snapshot is true * Set default for skip_final_snapshot to false * Update docs
1 parent 7d4c25b commit 7ce592e

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ No modules.
363363
| <a name="input_security_group_tags"></a> [security\_group\_tags](#input\_security\_group\_tags) | Additional tags for the security group | `map(string)` | `{}` | no |
364364
| <a name="input_security_group_use_name_prefix"></a> [security\_group\_use\_name\_prefix](#input\_security\_group\_use\_name\_prefix) | Determines whether the security group name (`name`) is used as a prefix | `bool` | `true` | no |
365365
| <a name="input_serverlessv2_scaling_configuration"></a> [serverlessv2\_scaling\_configuration](#input\_serverlessv2\_scaling\_configuration) | Map of nested attributes with serverless v2 scaling properties. Only valid when `engine_mode` is set to `provisioned` | `map(string)` | `{}` | no |
366-
| <a name="input_skip_final_snapshot"></a> [skip\_final\_snapshot](#input\_skip\_final\_snapshot) | Determines whether a final snapshot is created before the cluster is deleted. If true is specified, no snapshot is created | `bool` | `null` | no |
366+
| <a name="input_skip_final_snapshot"></a> [skip\_final\_snapshot](#input\_skip\_final\_snapshot) | Determines whether a final snapshot is created before the cluster is deleted. If true is specified, no snapshot is created | `bool` | `false` | no |
367367
| <a name="input_snapshot_identifier"></a> [snapshot\_identifier](#input\_snapshot\_identifier) | 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 | `string` | `null` | no |
368368
| <a name="input_source_region"></a> [source\_region](#input\_source\_region) | The source region for an encrypted replica DB cluster | `string` | `null` | no |
369369
| <a name="input_storage_encrypted"></a> [storage\_encrypted](#input\_storage\_encrypted) | Specifies whether the DB cluster is encrypted. The default is `true` | `bool` | `true` | no |

main.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ locals {
1515
backtrack_window = (var.engine == "aurora-mysql" || var.engine == "aurora") && var.engine_mode != "serverless" ? var.backtrack_window : 0
1616

1717
is_serverless = var.engine_mode == "serverless"
18+
19+
final_snapshot_identifier_prefix = "${var.final_snapshot_identifier_prefix}-${var.name}-${try(random_id.snapshot_identifier[0].hex, "")}"
1820
}
1921

2022
################################################################################
@@ -29,7 +31,7 @@ resource "random_password" "master_password" {
2931
}
3032

3133
resource "random_id" "snapshot_identifier" {
32-
count = local.create_cluster ? 1 : 0
34+
count = local.create_cluster && !var.skip_final_snapshot ? 1 : 0
3335

3436
keepers = {
3537
id = var.name
@@ -81,7 +83,7 @@ resource "aws_rds_cluster" "this" {
8183
engine = var.engine
8284
engine_mode = var.engine_mode
8385
engine_version = var.engine_version
84-
final_snapshot_identifier = "${var.final_snapshot_identifier_prefix}-${var.name}-${try(random_id.snapshot_identifier[0].hex, "")}"
86+
final_snapshot_identifier = var.skip_final_snapshot ? null : local.final_snapshot_identifier_prefix
8587
global_cluster_identifier = var.global_cluster_identifier
8688
iam_database_authentication_enabled = var.iam_database_authentication_enabled
8789
# iam_roles has been removed from this resource and instead will be used with aws_rds_cluster_role_association below to avoid conflicts per docs

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ variable "serverlessv2_scaling_configuration" {
277277
variable "skip_final_snapshot" {
278278
description = "Determines whether a final snapshot is created before the cluster is deleted. If true is specified, no snapshot is created"
279279
type = bool
280-
default = null
280+
default = false
281281
}
282282

283283
variable "snapshot_identifier" {

0 commit comments

Comments
 (0)