|
| 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 | +} |
0 commit comments