Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for aws_db_instance_automated_backups_replication #413

Merged
merged 6 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/complete-mssql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Note that this example may create resources which cost money. Run `terraform des
| Name | Source | Version |
|------|--------|---------|
| <a name="module_db"></a> [db](#module\_db) | ../../ | n/a |
| <a name="module_db_automated_backups_replication"></a> [db\_automated\_backups\_replication](#module\_db\_automated\_backups\_replication) | ../../modules/db_instance_automated_backups_replication | n/a |
| <a name="module_db_disabled"></a> [db\_disabled](#module\_db\_disabled) | ../../ | n/a |
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
Expand Down
28 changes: 25 additions & 3 deletions examples/complete-mssql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ provider "aws" {
}

locals {
name = "complete-mssql"
region = "eu-west-1"
name = "complete-mssql"
region = "eu-west-1"
region2 = "eu-central-1"
tags = {
Owner = "user"
Environment = "dev"
Expand Down Expand Up @@ -135,6 +136,9 @@ module "db" {
allocated_storage = 20
max_allocated_storage = 100

# Encryption at rest is not available for DB instances running SQL Server Express Edition
storage_encrypted = false

username = "complete_mssql"
port = 1433

Expand All @@ -150,7 +154,7 @@ module "db" {
enabled_cloudwatch_logs_exports = ["error"]
create_cloudwatch_log_group = true

backup_retention_period = 0
backup_retention_period = 1
skip_final_snapshot = true
deletion_protection = false

Expand All @@ -177,3 +181,21 @@ module "db_disabled" {
create_db_parameter_group = false
create_db_option_group = false
}

################################################################################
# RDS Automated Backups Replication Module
################################################################################
provider "aws" {
alias = "region2"
region = local.region2
}

module "db_automated_backups_replication" {
source = "../../modules/db_instance_automated_backups_replication"

source_db_instance_arn = module.db.db_instance_arn

providers = {
aws = aws.region2
}
}
9 changes: 7 additions & 2 deletions examples/complete-oracle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,25 @@ Note that this example may create resources which cost money. Run `terraform des

## Providers

No providers.
| Name | Version |
|------|---------|
| <a name="provider_aws.region2"></a> [aws.region2](#provider\_aws.region2) | >= 4.6 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_db"></a> [db](#module\_db) | ../../ | n/a |
| <a name="module_db_automated_backups_replication"></a> [db\_automated\_backups\_replication](#module\_db\_automated\_backups\_replication) | ../../modules/db_instance_automated_backups_replication | n/a |
| <a name="module_db_disabled"></a> [db\_disabled](#module\_db\_disabled) | ../../ | n/a |
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |

## Resources

No resources.
| Name | Type |
|------|------|
| [aws_kms_key.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |

## Inputs

Expand Down
39 changes: 33 additions & 6 deletions examples/complete-oracle/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ provider "aws" {
}

locals {
name = "complete-oracle"
region = "eu-west-1"
name = "complete-oracle"
region = "eu-west-1"
region2 = "eu-central-1"
tags = {
Owner = "user"
Environment = "dev"
Expand Down Expand Up @@ -65,16 +66,17 @@ module "db" {

engine = "oracle-ee"
engine_version = "19.0.0.0.ru-2021-10.rur-2021-10.r1"
family = "oracle-ee-19.0" # DB parameter group
major_engine_version = "19.0" # DB option group
family = "oracle-ee-19" # DB parameter group
major_engine_version = "19" # DB option group
instance_class = "db.t3.large"
license_model = "bring-your-own-license"

allocated_storage = 20
max_allocated_storage = 100

# Make sure that database name is capitalized, otherwise RDS will try to recreate RDS instance every time
db_name = "COMPLETEORACLE"
# Oracle database name cannot be longer than 8 characters
db_name = "ORACLE"
username = "complete_oracle"
port = 1521

Expand All @@ -87,7 +89,7 @@ module "db" {
enabled_cloudwatch_logs_exports = ["alert", "audit"]
create_cloudwatch_log_group = true

backup_retention_period = 0
backup_retention_period = 1
skip_final_snapshot = true
deletion_protection = false

Expand All @@ -110,3 +112,28 @@ module "db_disabled" {
create_db_parameter_group = false
create_db_option_group = false
}

################################################################################
# RDS Automated Backups Replication Module
################################################################################
provider "aws" {
alias = "region2"
region = local.region2
}

resource "aws_kms_key" "default" {
magreenbaum marked this conversation as resolved.
Show resolved Hide resolved
description = "Encryption key for cross region automated backups"

provider = aws.region2
}

module "db_automated_backups_replication" {
source = "../../modules/db_instance_automated_backups_replication"

source_db_instance_arn = module.db.db_instance_arn
kms_key_arn = aws_kms_key.default.arn
magreenbaum marked this conversation as resolved.
Show resolved Hide resolved

providers = {
aws = aws.region2
}
}
9 changes: 7 additions & 2 deletions examples/complete-postgres/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,26 @@ Note that this example may create resources which cost money. Run `terraform des

## Providers

No providers.
| Name | Version |
|------|---------|
| <a name="provider_aws.region2"></a> [aws.region2](#provider\_aws.region2) | >= 4.6 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_db"></a> [db](#module\_db) | ../../ | n/a |
| <a name="module_db_automated_backups_replication"></a> [db\_automated\_backups\_replication](#module\_db\_automated\_backups\_replication) | ../../modules/db_instance_automated_backups_replication | n/a |
| <a name="module_db_default"></a> [db\_default](#module\_db\_default) | ../../ | n/a |
| <a name="module_db_disabled"></a> [db\_disabled](#module\_db\_disabled) | ../../ | n/a |
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |

## Resources

No resources.
| Name | Type |
|------|------|
| [aws_kms_key.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |

## Inputs

Expand Down
32 changes: 29 additions & 3 deletions examples/complete-postgres/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ provider "aws" {
}

locals {
name = "complete-postgresql"
region = "eu-west-1"
name = "complete-postgresql"
region = "eu-west-1"
region2 = "eu-central-1"
tags = {
Owner = "user"
Environment = "dev"
Expand Down Expand Up @@ -90,7 +91,7 @@ module "db" {
enabled_cloudwatch_logs_exports = ["postgresql", "upgrade"]
create_cloudwatch_log_group = true

backup_retention_period = 0
backup_retention_period = 1
skip_final_snapshot = true
deletion_protection = false

Expand Down Expand Up @@ -165,3 +166,28 @@ module "db_disabled" {
create_db_parameter_group = false
create_db_option_group = false
}

################################################################################
# RDS Automated Backups Replication Module
################################################################################
provider "aws" {
alias = "region2"
region = local.region2
}

resource "aws_kms_key" "default" {
description = "Encryption key for cross region automated backups"

provider = aws.region2
}

module "db_automated_backups_replication" {
source = "../../modules/db_instance_automated_backups_replication"

source_db_instance_arn = module.db.db_instance_arn
kms_key_arn = aws_kms_key.default.arn

providers = {
aws = aws.region2
}
}
9 changes: 9 additions & 0 deletions modules/db_instance_automated_backups_replication/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "aws_db_instance_automated_backups_replication" "this" {
count = var.create ? 1 : 0

source_db_instance_arn = var.source_db_instance_arn
kms_key_id = var.kms_key_arn
pre_signed_url = var.pre_signed_url
retention_period = var.retention_period

}
4 changes: 4 additions & 0 deletions modules/db_instance_automated_backups_replication/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "db_instance_automated_backups_replication_id" {
description = "The automated backups replication id"
value = try(aws_db_instance_automated_backups_replication.this[0].id, "")
}
29 changes: 29 additions & 0 deletions modules/db_instance_automated_backups_replication/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
variable "create" {
description = "Whether to create this resource or not?"
type = bool
default = true
}

variable "kms_key_arn" {
description = "The KMS encryption key ARN in the destination AWS Region"
type = string
default = null
}

variable "pre_signed_url" {
description = "A URL that contains a Signature Version 4 signed request for the StartDBInstanceAutomatedBackupsReplication action to be called in the AWS Region of the source DB instance"
type = string
default = null
}

variable "retention_period" {
description = "The retention period for the replicated automated backups"
type = number
default = 7
}

variable "source_db_instance_arn" {
description = "The ARN of the source DB instance for the replicated automated backups"
type = string
default = null
}
10 changes: 10 additions & 0 deletions modules/db_instance_automated_backups_replication/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 0.13.1"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.9"
}
}
}