Skip to content

Commit 155ab7b

Browse files
authored
[aws/backing-services] Add RDS replica (#85)
* Add replica * pin to a release * Update aws/backing-services/rds-replica.tf Co-Authored-By: osterman <[email protected]> * Update aws/backing-services/rds-replica.tf Co-Authored-By: osterman <[email protected]> * Change default
1 parent 5a44cb5 commit 155ab7b

File tree

2 files changed

+181
-8
lines changed

2 files changed

+181
-8
lines changed
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
variable "rds_replica_name" {
2+
type = "string"
3+
default = "rds-replica"
4+
description = "RDS instance name"
5+
}
6+
7+
variable "rds_replica_enabled" {
8+
type = "string"
9+
default = "false"
10+
description = "Set to false to prevent the module from creating any resources"
11+
}
12+
13+
variable "rds_replica_replicate_source_db" {
14+
type = "string"
15+
description = "Specifies that this resource is a Replicate database, and to use this value as the source database. This correlates to the identifier of another Amazon RDS Database to replicate. Note that if you are creating a cross-region replica of an encrypted database you will also need to specify a `kms_key_id`."
16+
default = "changeme"
17+
}
18+
19+
variable "rds_replica_kms_key_id" {
20+
type = "string"
21+
description = "The ARN for the KMS encryption key. If creating an encrypted replica, set this to the destination KMS ARN."
22+
default = ""
23+
}
24+
25+
# db.t2.micro is free tier
26+
# https://aws.amazon.com/rds/free
27+
variable "rds_replica_instance_type" {
28+
type = "string"
29+
default = "db.t2.micro"
30+
description = "EC2 instance type for RDS DB"
31+
}
32+
33+
variable "rds_replica_port" {
34+
type = "string"
35+
default = "3306"
36+
description = "RDS DB port"
37+
}
38+
39+
variable "rds_replica_snapshot" {
40+
type = "string"
41+
default = ""
42+
description = "Set to a snapshot ID to restore from snapshot"
43+
}
44+
45+
variable "rds_replica_multi_az" {
46+
type = "string"
47+
default = "false"
48+
description = "Run instaces in multiple az"
49+
}
50+
51+
variable "rds_replica_storage_type" {
52+
type = "string"
53+
default = "gp2"
54+
description = "Storage type"
55+
}
56+
57+
variable "rds_replica_storage_size" {
58+
type = "string"
59+
default = "20"
60+
description = "Storage size in Gb"
61+
}
62+
63+
variable "rds_replica_storage_encrypted" {
64+
type = "string"
65+
default = "true"
66+
description = "Set to true to encrypt storage"
67+
}
68+
69+
variable "rds_replica_auto_minor_version_upgrade" {
70+
type = "string"
71+
default = "true"
72+
description = "Allow automated minor version upgrade (e.g. from Postgres 9.5.3 to Postgres 9.5.4)"
73+
}
74+
75+
variable "rds_replica_allow_major_version_upgrade" {
76+
type = "string"
77+
default = "false"
78+
description = "Allow major version upgrade"
79+
}
80+
81+
variable "rds_replica_apply_immediately" {
82+
type = "string"
83+
default = "true"
84+
description = "Specifies whether any database modifications are applied immediately, or during the next maintenance window"
85+
}
86+
87+
variable "rds_replica_skip_final_snapshot" {
88+
type = "string"
89+
default = "false"
90+
description = "If true (default), no snapshot will be made before deleting DB"
91+
}
92+
93+
variable "rds_replica_backup_retention_period" {
94+
type = "string"
95+
default = "7"
96+
description = "Backup retention period in days. Must be > 0 to enable backups"
97+
}
98+
99+
variable "rds_replica_backup_window" {
100+
type = "string"
101+
default = "22:00-03:00"
102+
description = "When AWS can perform DB snapshots, can't overlap with maintenance window"
103+
}
104+
105+
locals {
106+
rds_replica_enabled = "${var.rds_replica_enabled == "true"}"
107+
}
108+
109+
module "rds_replica" {
110+
source = "git::https://github.com/cloudposse/terraform-aws-rds-replica.git?ref=tags/0.1.0"
111+
enabled = "${var.rds_replica_enabled}"
112+
namespace = "${var.namespace}"
113+
stage = "${var.stage}"
114+
name = "${var.rds_replica_name}"
115+
kms_key_id = "${var.rds_replica_kms_key_id}"
116+
replicate_source_db = "${var.rds_replica_replicate_source_db}"
117+
dns_zone_id = "${local.zone_id}"
118+
host_name = "${var.rds_replica_name}"
119+
security_group_ids = ["${module.kops_metadata.nodes_security_group_id}"]
120+
database_port = "${var.rds_replica_port}"
121+
multi_az = "${var.rds_replica_multi_az}"
122+
storage_type = "${var.rds_replica_storage_type}"
123+
storage_encrypted = "${var.rds_replica_storage_encrypted}"
124+
instance_class = "${var.rds_replica_instance_type}"
125+
publicly_accessible = "false"
126+
subnet_ids = ["${module.subnets.private_subnet_ids}"]
127+
vpc_id = "${module.vpc.vpc_id}"
128+
snapshot_identifier = "${var.rds_replica_snapshot}"
129+
auto_minor_version_upgrade = "${var.rds_replica_auto_minor_version_upgrade}"
130+
allow_major_version_upgrade = "${var.rds_replica_allow_major_version_upgrade}"
131+
apply_immediately = "${var.rds_replica_apply_immediately}"
132+
skip_final_snapshot = "${var.rds_replica_skip_final_snapshot}"
133+
copy_tags_to_snapshot = "true"
134+
backup_retention_period = "${var.rds_replica_backup_retention_period}"
135+
backup_window = "${var.rds_replica_backup_window}"
136+
}
137+
138+
resource "aws_ssm_parameter" "rds_replica_hostname" {
139+
count = "${local.rds_replica_enabled ? 1 : 0}"
140+
name = "${format(var.chamber_parameter_name, local.chamber_service, "rds_replica_hostname")}"
141+
value = "${module.rds_replica.hostname}"
142+
description = "RDS replica hostname"
143+
type = "String"
144+
overwrite = "true"
145+
}
146+
147+
resource "aws_ssm_parameter" "rds_replica_port" {
148+
count = "${local.rds_replica_enabled ? 1 : 0}"
149+
name = "${format(var.chamber_parameter_name, local.chamber_service, "rds_replica_port")}"
150+
value = "${var.rds_replica_port}"
151+
description = "RDS replica port"
152+
type = "String"
153+
overwrite = "true"
154+
}
155+
156+
output "rds_replica_instance_id" {
157+
value = "${module.rds_replica.instance_id}"
158+
description = "RDS replica ID of the instance"
159+
}
160+
161+
output "rds_replica_instance_address" {
162+
value = "${module.rds_replica.instance_address}"
163+
description = "RDS replica address of the instance"
164+
}
165+
166+
output "rds_replica_instance_endpoint" {
167+
value = "${module.rds_replica.instance_endpoint}"
168+
description = "RDS replica DNS Endpoint of the instance"
169+
}
170+
171+
output "rds_replica_port" {
172+
value = "${local.rds_replica_enabled ? var.rds_replica_port : local.null}"
173+
description = "RDS replica port"
174+
}
175+
176+
output "rds_replica_hostname" {
177+
value = "${module.rds_replica.hostname}"
178+
description = "RDS replica host name of the instance"
179+
}

aws/backing-services/rds.tf

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ variable "rds_name" {
77
variable "rds_enabled" {
88
type = "string"
99
default = "false"
10-
description = "Set to true to create rds instance"
10+
description = "Set to false to prevent the module from creating any resources"
1111
}
1212

1313
# Don't use `root`
@@ -66,12 +66,6 @@ variable "rds_db_parameter_group" {
6666
description = "RDS DB engine version"
6767
}
6868

69-
variable "rds_cluster_enabled" {
70-
type = "string"
71-
default = "true"
72-
description = "Set to false to prevent the module from creating any resources"
73-
}
74-
7569
variable "rds_snapshot" {
7670
type = "string"
7771
default = ""
@@ -104,7 +98,7 @@ variable "rds_storage_size" {
10498

10599
variable "rds_storage_encrypted" {
106100
type = "string"
107-
default = "false"
101+
default = "true"
108102
description = "Set true to encrypt storage"
109103
}
110104

0 commit comments

Comments
 (0)