Skip to content

Commit f1e15a1

Browse files
authored
feat: Add support for aws_db_instance_automated_backups_replication (#413)
1 parent d219043 commit f1e15a1

File tree

10 files changed

+186
-16
lines changed

10 files changed

+186
-16
lines changed

examples/complete-mssql/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Note that this example may create resources which cost money. Run `terraform des
3333
| Name | Source | Version |
3434
|------|--------|---------|
3535
| <a name="module_db"></a> [db](#module\_db) | ../../ | n/a |
36+
| <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 |
3637
| <a name="module_db_disabled"></a> [db\_disabled](#module\_db\_disabled) | ../../ | n/a |
3738
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
3839
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |

examples/complete-mssql/main.tf

+25-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ provider "aws" {
33
}
44

55
locals {
6-
name = "complete-mssql"
7-
region = "eu-west-1"
6+
name = "complete-mssql"
7+
region = "eu-west-1"
8+
region2 = "eu-central-1"
89
tags = {
910
Owner = "user"
1011
Environment = "dev"
@@ -135,6 +136,9 @@ module "db" {
135136
allocated_storage = 20
136137
max_allocated_storage = 100
137138

139+
# Encryption at rest is not available for DB instances running SQL Server Express Edition
140+
storage_encrypted = false
141+
138142
username = "complete_mssql"
139143
port = 1433
140144

@@ -150,7 +154,7 @@ module "db" {
150154
enabled_cloudwatch_logs_exports = ["error"]
151155
create_cloudwatch_log_group = true
152156

153-
backup_retention_period = 0
157+
backup_retention_period = 1
154158
skip_final_snapshot = true
155159
deletion_protection = false
156160

@@ -177,3 +181,21 @@ module "db_disabled" {
177181
create_db_parameter_group = false
178182
create_db_option_group = false
179183
}
184+
185+
################################################################################
186+
# RDS Automated Backups Replication Module
187+
################################################################################
188+
provider "aws" {
189+
alias = "region2"
190+
region = local.region2
191+
}
192+
193+
module "db_automated_backups_replication" {
194+
source = "../../modules/db_instance_automated_backups_replication"
195+
196+
source_db_instance_arn = module.db.db_instance_arn
197+
198+
providers = {
199+
aws = aws.region2
200+
}
201+
}

examples/complete-oracle/README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,26 @@ Note that this example may create resources which cost money. Run `terraform des
2424

2525
## Providers
2626

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

2931
## Modules
3032

3133
| Name | Source | Version |
3234
|------|--------|---------|
3335
| <a name="module_db"></a> [db](#module\_db) | ../../ | n/a |
36+
| <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 |
3437
| <a name="module_db_disabled"></a> [db\_disabled](#module\_db\_disabled) | ../../ | n/a |
38+
| <a name="module_kms"></a> [kms](#module\_kms) | terraform-aws-modules/kms/aws | ~> 1.0 |
3539
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
3640
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
3741

3842
## Resources
3943

40-
No resources.
44+
| Name | Type |
45+
|------|------|
46+
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
4147

4248
## Inputs
4349

examples/complete-oracle/main.tf

+48-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ provider "aws" {
22
region = local.region
33
}
44

5+
data "aws_caller_identity" "current" {}
6+
57
locals {
6-
name = "complete-oracle"
7-
region = "eu-west-1"
8+
name = "complete-oracle"
9+
region = "eu-west-1"
10+
region2 = "eu-central-1"
11+
current_identity = data.aws_caller_identity.current.arn
812
tags = {
913
Owner = "user"
1014
Environment = "dev"
@@ -65,16 +69,17 @@ module "db" {
6569

6670
engine = "oracle-ee"
6771
engine_version = "19.0.0.0.ru-2021-10.rur-2021-10.r1"
68-
family = "oracle-ee-19.0" # DB parameter group
69-
major_engine_version = "19.0" # DB option group
72+
family = "oracle-ee-19" # DB parameter group
73+
major_engine_version = "19" # DB option group
7074
instance_class = "db.t3.large"
7175
license_model = "bring-your-own-license"
7276

7377
allocated_storage = 20
7478
max_allocated_storage = 100
7579

7680
# Make sure that database name is capitalized, otherwise RDS will try to recreate RDS instance every time
77-
db_name = "COMPLETEORACLE"
81+
# Oracle database name cannot be longer than 8 characters
82+
db_name = "ORACLE"
7883
username = "complete_oracle"
7984
port = 1521
8085

@@ -87,7 +92,7 @@ module "db" {
8792
enabled_cloudwatch_logs_exports = ["alert", "audit"]
8893
create_cloudwatch_log_group = true
8994

90-
backup_retention_period = 0
95+
backup_retention_period = 1
9196
skip_final_snapshot = true
9297
deletion_protection = false
9398

@@ -110,3 +115,40 @@ module "db_disabled" {
110115
create_db_parameter_group = false
111116
create_db_option_group = false
112117
}
118+
119+
################################################################################
120+
# RDS Automated Backups Replication Module
121+
################################################################################
122+
provider "aws" {
123+
alias = "region2"
124+
region = local.region2
125+
}
126+
127+
module "kms" {
128+
source = "terraform-aws-modules/kms/aws"
129+
version = "~> 1.0"
130+
description = "KMS key for cross region automated backups replication"
131+
132+
# Aliases
133+
aliases = [local.name]
134+
aliases_use_name_prefix = true
135+
136+
key_owners = [local.current_identity]
137+
138+
tags = local.tags
139+
140+
providers = {
141+
aws = aws.region2
142+
}
143+
}
144+
145+
module "db_automated_backups_replication" {
146+
source = "../../modules/db_instance_automated_backups_replication"
147+
148+
source_db_instance_arn = module.db.db_instance_arn
149+
kms_key_arn = module.kms.key_arn
150+
151+
providers = {
152+
aws = aws.region2
153+
}
154+
}

examples/complete-postgres/README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,27 @@ Note that this example may create resources which cost money. Run `terraform des
2424

2525
## Providers
2626

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

2931
## Modules
3032

3133
| Name | Source | Version |
3234
|------|--------|---------|
3335
| <a name="module_db"></a> [db](#module\_db) | ../../ | n/a |
36+
| <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 |
3437
| <a name="module_db_default"></a> [db\_default](#module\_db\_default) | ../../ | n/a |
3538
| <a name="module_db_disabled"></a> [db\_disabled](#module\_db\_disabled) | ../../ | n/a |
39+
| <a name="module_kms"></a> [kms](#module\_kms) | terraform-aws-modules/kms/aws | ~> 1.0 |
3640
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
3741
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
3842

3943
## Resources
4044

41-
No resources.
45+
| Name | Type |
46+
|------|------|
47+
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
4248

4349
## Inputs
4450

examples/complete-postgres/main.tf

+44-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ provider "aws" {
22
region = local.region
33
}
44

5+
data "aws_caller_identity" "current" {}
6+
57
locals {
6-
name = "complete-postgresql"
7-
region = "eu-west-1"
8+
name = "complete-postgresql"
9+
region = "eu-west-1"
10+
region2 = "eu-central-1"
11+
current_identity = data.aws_caller_identity.current.arn
812
tags = {
913
Owner = "user"
1014
Environment = "dev"
@@ -90,7 +94,7 @@ module "db" {
9094
enabled_cloudwatch_logs_exports = ["postgresql", "upgrade"]
9195
create_cloudwatch_log_group = true
9296

93-
backup_retention_period = 0
97+
backup_retention_period = 1
9498
skip_final_snapshot = true
9599
deletion_protection = false
96100

@@ -166,3 +170,40 @@ module "db_disabled" {
166170
create_db_parameter_group = false
167171
create_db_option_group = false
168172
}
173+
174+
################################################################################
175+
# RDS Automated Backups Replication Module
176+
################################################################################
177+
provider "aws" {
178+
alias = "region2"
179+
region = local.region2
180+
}
181+
182+
module "kms" {
183+
source = "terraform-aws-modules/kms/aws"
184+
version = "~> 1.0"
185+
description = "KMS key for cross region automated backups replication"
186+
187+
# Aliases
188+
aliases = [local.name]
189+
aliases_use_name_prefix = true
190+
191+
key_owners = [local.current_identity]
192+
193+
tags = local.tags
194+
195+
providers = {
196+
aws = aws.region2
197+
}
198+
}
199+
200+
module "db_automated_backups_replication" {
201+
source = "../../modules/db_instance_automated_backups_replication"
202+
203+
source_db_instance_arn = module.db.db_instance_arn
204+
kms_key_arn = module.kms.key_arn
205+
206+
providers = {
207+
aws = aws.region2
208+
}
209+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
resource "aws_db_instance_automated_backups_replication" "this" {
2+
count = var.create ? 1 : 0
3+
4+
source_db_instance_arn = var.source_db_instance_arn
5+
kms_key_id = var.kms_key_arn
6+
pre_signed_url = var.pre_signed_url
7+
retention_period = var.retention_period
8+
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "db_instance_automated_backups_replication_id" {
2+
description = "The automated backups replication id"
3+
value = try(aws_db_instance_automated_backups_replication.this[0].id, "")
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
variable "create" {
2+
description = "Whether to create this resource or not?"
3+
type = bool
4+
default = true
5+
}
6+
7+
variable "kms_key_arn" {
8+
description = "The KMS encryption key ARN in the destination AWS Region"
9+
type = string
10+
default = null
11+
}
12+
13+
variable "pre_signed_url" {
14+
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"
15+
type = string
16+
default = null
17+
}
18+
19+
variable "retention_period" {
20+
description = "The retention period for the replicated automated backups"
21+
type = number
22+
default = 7
23+
}
24+
25+
variable "source_db_instance_arn" {
26+
description = "The ARN of the source DB instance for the replicated automated backups"
27+
type = string
28+
default = null
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 0.13.1"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 4.9"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)