feat: keep last backup once a managed db is deleted

This commit is contained in:
Pierre Mavro
2021-03-13 11:07:45 +01:00
committed by Pierre Mavro
parent 33d704ab4b
commit 4d79d21118
11 changed files with 28 additions and 3 deletions

View File

@@ -117,5 +117,5 @@ resource "aws_docdb_cluster" "documentdb_cluster" {
# Backups
backup_retention_period = var.backup_retention_period
preferred_backup_window = var.preferred_backup_window
skip_final_snapshot = true
skip_final_snapshot = var.delete_automated_backups
}

View File

@@ -114,6 +114,12 @@ variable "preferred_backup_window" {
type = string
}
variable "skip_final_snapshot" {
description = "Skip final snapshot"
default = {{ skip_final_snapshot }}
type = bool
}
{%- if snapshot is defined %}
# Snapshots
variable "snapshot_identifier" {

View File

@@ -113,7 +113,7 @@ resource "aws_db_instance" "mysql_instance" {
# Backups
backup_retention_period = var.backup_retention_period
backup_window = var.backup_window
skip_final_snapshot = true
skip_final_snapshot = var.delete_automated_backups
delete_automated_backups = var.delete_automated_backups
}

View File

@@ -152,6 +152,12 @@ variable "delete_automated_backups" {
type = bool
}
variable "skip_final_snapshot" {
description = "Skip final snapshot"
default = {{ skip_final_snapshot }}
type = bool
}
{%- if snapshot is defined %}
# Snapshots
variable "snapshot_identifier" {

View File

@@ -115,7 +115,7 @@ resource "aws_db_instance" "postgresql_instance" {
# Backups
backup_retention_period = var.backup_retention_period
backup_window = var.backup_window
skip_final_snapshot = true
skip_final_snapshot = var.delete_automated_backups
delete_automated_backups = var.delete_automated_backups
}

View File

@@ -166,6 +166,12 @@ variable "delete_automated_backups" {
type = bool
}
variable "skip_final_snapshot" {
description = "Skip final snapshot"
default = {{ skip_final_snapshot }}
type = bool
}
# Snapshots
# TODO later
#variable "snapshot_identifier" {

View File

@@ -106,5 +106,8 @@ resource "aws_elasticache_cluster" "elasticache_cluster" {
# Backups
snapshot_window = var.preferred_backup_window
snapshot_retention_limit = var.backup_retention_period
{%- if skip_final_snapshot %}
final_snapshot_identifier = "${var.elasticache_identifier}-final"
{%- endif %}
}

View File

@@ -183,6 +183,7 @@ impl Service for MongoDB {
context.insert("tfstate_suffix_name", &get_tfstate_suffix(self));
context.insert("tfstate_name", &get_tfstate_name(self));
context.insert("skip_final_snapshot", &self.context().is_test_cluster());
if self.context.resource_expiration_in_seconds().is_some() {
context.insert(
"resource_expiration_in_seconds",

View File

@@ -180,6 +180,7 @@ impl Service for MySQL {
context.insert("tfstate_name", &get_tfstate_name(self));
context.insert("delete_automated_backups", &self.context().is_test_cluster());
context.insert("skip_final_snapshot", &self.context().is_test_cluster());
if self.context.resource_expiration_in_seconds().is_some() {
context.insert(
"resource_expiration_in_seconds",

View File

@@ -180,6 +180,7 @@ impl Service for PostgreSQL {
context.insert("tfstate_suffix_name", &get_tfstate_suffix(self));
context.insert("tfstate_name", &get_tfstate_name(self));
context.insert("skip_final_snapshot", &self.context().is_test_cluster());
context.insert("delete_automated_backups", &self.context().is_test_cluster());
if self.context.resource_expiration_in_seconds().is_some() {

View File

@@ -194,6 +194,7 @@ impl Service for Redis {
context.insert("tfstate_suffix_name", &get_tfstate_suffix(self));
context.insert("tfstate_name", &get_tfstate_name(self));
context.insert("skip_final_snapshot", &self.context().is_test_cluster());
if self.context.resource_expiration_in_seconds().is_some() {
context.insert(
"resource_expiration_in_seconds",