Skip to content

Commit 53033bb

Browse files
authored
Fix aurora deletion parameter group (#62)
* Testing with removing the lifecycle block * Test snap name change * Snapshot overwrite * testing alternative * testing sth that won't work * removing lifecycle block * Fix README * Adding a time-sleep * adding lifecycle * Don't think this will work * no again * Changing db_cluster_param_group_name * missing index * typo * Cleanup * cleanup 2
1 parent 8428867 commit 53033bb

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ The following inputs can be used as `step.with` keys
257257
#### **Aurora Inputs**
258258
| Name | Type | Description |
259259
|------------------|---------|------------------------------------|
260-
| `aws_aurora_enable` | Boolean | Toggles deployment of an Aurora database. Defaults to `true`. |
260+
| `aws_aurora_enable` | Boolean | Toggles deployment of an Aurora database. Defaults to `false`. |
261261
| `aws_aurora_proxy` | Boolean | Aurora DB Proxy Toggle. Defaults to `false`. |
262262
| `aws_aurora_cluster_name` | String | The name of the cluster. Defaults to `aws_resource_identifier` if none set. |
263263
| `aws_aurora_engine` | String | The database engine to use. Defaults to `aurora-postgresql`. |
@@ -293,12 +293,12 @@ The following inputs can be used as `step.with` keys
293293
| `aws_aurora_backup_window` | String | Daily time range during which the backups happen. |
294294
| `aws_aurora_maintenance_window` | String | Maintenance window. |
295295
| `aws_aurora_database_final_snapshot` | String | Set the name to generate a snapshot of the database before deletion. |
296-
| `aws_aurora_deletion_protection` | Boolean | Protects the database from deletion. Defaults to `false`. This won't prevent Terraform from destroying it. |
296+
| `aws_aurora_deletion_protection` | Boolean | Protects the database from deletion. Defaults to `false`. **This won't prevent db instances to be deleted.** |
297297
| `aws_aurora_delete_auto_backups` | Boolean | Specifies whether to remove automated backups immediately after the DB cluster is deleted. Default is `true`. |
298298
| `aws_aurora_restore_snapshot_id` | String | Restore an initial snapshot of the DB if specified. |
299299
| `aws_aurora_restore_to_point_in_time` | map{String} | Restore database to a point in time. Will require a map of strings. Like `{"restore_to_time"="W","restore_type"="X","source_cluster_identifier"="Y", "use_latest_restorable_time"="Z"}`. Default `{}`. |
300-
| `aws_aurora_snapshot_name` | String | Takes a snapshot of the DB. |
301-
| `aws_aurora_snapshot_overwrite` | Boolean | Overwrites snapshot if same name is set. Defaults to `false`. |
300+
| `aws_aurora_snapshot_name` | String | Takes a snapshot of the DB. This is treated as one resource, meaning only one can be created, even if name changes.|
301+
| `aws_aurora_snapshot_overwrite` | Boolean | Takes a snapshot of the DB deleteing the previous snapshot. Defaults to `false`. |
302302
| **DB Instance** |||
303303
| `aws_aurora_db_instances_count` | String | Amount of instances to create. Defaults to `1`. |
304304
| `aws_aurora_db_instance_class` | String | Database instance size. Defaults to `db.r6g.large`. |

operations/deployment/terraform/modules/aws/aurora/aws_aurora.tf

+6-7
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ resource "aws_rds_cluster" "aurora" {
7474
master_password = sensitive(random_password.rds.result)
7575
iam_database_authentication_enabled = var.aws_aurora_iam_auth_enabled
7676
iam_roles = var.aws_aurora_iam_roles != "" ? [var.aws_aurora_iam_roles] : []
77-
db_cluster_parameter_group_name = var.aws_resource_identifier
77+
db_cluster_parameter_group_name = strcontains(var.aws_aurora_engine, "mysql") ? aws_rds_cluster_parameter_group.mysql[0].name : strcontains(var.aws_aurora_engine, "postgres") ? aws_rds_cluster_parameter_group.postgresql[0].name : ""
7878
# Backup & Maint
7979
enabled_cloudwatch_logs_exports = var.aws_aurora_cloudwatch_enable ? local.aws_aurora_cloudwatch_log_type : []
8080
backtrack_window = var.aws_aurora_backtrack_window
@@ -129,10 +129,10 @@ resource "aws_rds_cluster_instance" "cluster_instance" {
129129
ca_cert_identifier = var.aws_aurora_db_ca_cert_identifier
130130
preferred_maintenance_window = var.aws_aurora_db_maintenance_window
131131
}
132-
132+
133133
resource "aws_rds_cluster_parameter_group" "mysql" {
134134
count = strcontains(var.aws_aurora_engine, "mysql") ? 1 : 0
135-
name = var.aws_resource_identifier
135+
name = "${var.aws_resource_identifier}-mysql"
136136
description = "${var.aws_resource_identifier} cluster parameter group"
137137
family = var.aws_aurora_database_group_family != "" ? var.aws_aurora_database_group_family : "${var.aws_aurora_engine}8.0"
138138

@@ -141,15 +141,14 @@ resource "aws_rds_cluster_parameter_group" "mysql" {
141141
value = "ON"
142142
apply_method = "immediate"
143143
}
144-
145144
lifecycle {
146145
create_before_destroy = true
147146
}
148147
}
149148

150149
resource "aws_rds_cluster_parameter_group" "postgresql" {
151150
count = strcontains(var.aws_aurora_engine, "postgres")? 1 : 0
152-
name = var.aws_resource_identifier
151+
name = "${var.aws_resource_identifier}-postgres"
153152
description = "${var.aws_resource_identifier} cluster parameter group"
154153
family = var.aws_aurora_database_group_family != "" ? var.aws_aurora_database_group_family : "${var.aws_aurora_engine}15"
155154

@@ -218,7 +217,7 @@ resource "aws_cloudwatch_log_group" "logs" {
218217
### All of this added to handle snapshots
219218
resource "aws_db_cluster_snapshot" "db_snapshot" {
220219
count = var.aws_aurora_snapshot_name != "" ? ( var.aws_aurora_snapshot_overwrite ? 0 : 1 ) : 0
221-
db_cluster_identifier = var.aws_aurora_cluster_name != "" ? var.aws_aurora_cluster_name : var.aws_resource_identifier
220+
db_cluster_identifier = aws_rds_cluster.aurora.cluster_identifier
222221
db_cluster_snapshot_identifier = var.aws_aurora_snapshot_name
223222
lifecycle {
224223
ignore_changes = all
@@ -227,7 +226,7 @@ resource "aws_db_cluster_snapshot" "db_snapshot" {
227226

228227
resource "aws_db_cluster_snapshot" "overwrite_db_snapshot" {
229228
count = var.aws_aurora_snapshot_name != "" ? ( var.aws_aurora_snapshot_overwrite ? 1 : 0 ) : 0
230-
db_cluster_identifier = var.aws_aurora_cluster_name != "" ? var.aws_aurora_cluster_name : var.aws_resource_identifier
229+
db_cluster_identifier = aws_rds_cluster.aurora.cluster_identifier
231230
db_cluster_snapshot_identifier = var.aws_aurora_snapshot_name
232231
lifecycle {
233232
create_before_destroy = true

0 commit comments

Comments
 (0)