From 9991541d5a6789a1e778b994b17c13a1d2bb1737 Mon Sep 17 00:00:00 2001 From: Michael Barrientos Date: Thu, 8 Jul 2021 14:22:22 -0700 Subject: [PATCH] [feature] Add 'snapshot_identifier' to all aws-aurora modules (#323) * Add 'snapshot_identifier' to all aws-aurora modules This will support creating a new RDS cluster from an existing snapshot, e.g. for data mirroring to a different env. * Set empty default for aurora inital snapshot variable * Make default snapshot identifier null Co-authored-by: Andrew Tolopko --- aws-aurora-mysql/main.tf | 1 + aws-aurora-mysql/variables.tf | 6 ++++++ aws-aurora-postgres/main.tf | 1 + aws-aurora-postgres/variables.tf | 6 ++++++ aws-aurora/main.tf | 1 + aws-aurora/variables.tf | 6 ++++++ 6 files changed, 21 insertions(+) diff --git a/aws-aurora-mysql/main.tf b/aws-aurora-mysql/main.tf index 939d0fa9..9b9d90f6 100755 --- a/aws-aurora-mysql/main.tf +++ b/aws-aurora-mysql/main.tf @@ -32,6 +32,7 @@ module "aurora" { instance_count = var.instance_count backtrack_window = var.backtrack_window + snapshot_identifier = var.snapshot_identifier skip_final_snapshot = var.skip_final_snapshot kms_key_id = var.kms_key_id diff --git a/aws-aurora-mysql/variables.tf b/aws-aurora-mysql/variables.tf index 42dd2527..a15f4cf8 100755 --- a/aws-aurora-mysql/variables.tf +++ b/aws-aurora-mysql/variables.tf @@ -57,6 +57,12 @@ variable "project" { description = "Project for tagging and naming. See [doc](../README.md#consistent-tagging)" } +variable "snapshot_identifier" { + type = string + 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." + default = null +} + variable "skip_final_snapshot" { type = string description = "When you destroy a database RDS will, by default, take snapshot. Set this to skip that step." diff --git a/aws-aurora-postgres/main.tf b/aws-aurora-postgres/main.tf index 4e4dec7e..72d4104a 100755 --- a/aws-aurora-postgres/main.tf +++ b/aws-aurora-postgres/main.tf @@ -40,6 +40,7 @@ module "aurora" { # backtrack_window not supported yet backtrack_window = 0 + snapshot_identifier = var.snapshot_identifier skip_final_snapshot = var.skip_final_snapshot kms_key_id = var.kms_key_id apply_immediately = var.apply_immediately diff --git a/aws-aurora-postgres/variables.tf b/aws-aurora-postgres/variables.tf index 6e1898df..e73b9454 100755 --- a/aws-aurora-postgres/variables.tf +++ b/aws-aurora-postgres/variables.tf @@ -73,6 +73,12 @@ variable "publicly_accessible" { default = false } +variable "snapshot_identifier" { + type = string + 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." + default = null +} + variable "skip_final_snapshot" { type = string description = "When you destroy a database RDS will, by default, take snapshot. Set this to skip that step." diff --git a/aws-aurora/main.tf b/aws-aurora/main.tf index 57c437c5..2f234c92 100755 --- a/aws-aurora/main.tf +++ b/aws-aurora/main.tf @@ -59,6 +59,7 @@ resource "aws_rds_cluster" "db" { storage_encrypted = true iam_database_authentication_enabled = var.iam_database_authentication_enabled backup_retention_period = 28 + snapshot_identifier = var.snapshot_identifier final_snapshot_identifier = "${local.name}-snapshot" skip_final_snapshot = var.skip_final_snapshot backtrack_window = var.backtrack_window diff --git a/aws-aurora/variables.tf b/aws-aurora/variables.tf index 1db7e059..6ea5ae87 100755 --- a/aws-aurora/variables.tf +++ b/aws-aurora/variables.tf @@ -51,6 +51,12 @@ variable "project" { description = "Project for tagging and naming. See [doc](../README.md#consistent-tagging)" } +variable "snapshot_identifier" { + type = string + 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." + default = null +} + variable "skip_final_snapshot" { default = false }