Skip to content

Commit 24e3f2c

Browse files
authored
Feature/upgrades (#10)
* Add point in time recovery support * Add full set of examples * re-add data sources
1 parent 258bf46 commit 24e3f2c

File tree

10 files changed

+157
-16
lines changed

10 files changed

+157
-16
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repos:
1818
args: ['--allow-missing-credentials']
1919
- id: trailing-whitespace
2020
- repo: git://github.com/antonbabenko/pre-commit-terraform
21-
rev: v1.44.0
21+
rev: v1.45.0
2222
hooks:
2323
- id: terraform_fmt
2424
- id: terraform_docs

.tflint.hcl

Lines changed: 0 additions & 3 deletions
This file was deleted.

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# terraform-aws-rds-aurora
2-
Terraform module which creates AWS RDS Aurora resources. This module was created to work with Secrets Manager.
2+
Terraform module which creates AWS RDS Aurora resources. It supports MySQL, Postgres, Serverless and Global clusters.
33

44
## Terraform versions
55

@@ -68,6 +68,8 @@ Module is to be used with Terraform > 0.12.
6868

6969
* [Aurora MySQL](https://github.com/umotif-public/terraform-aws-rds-aurora/tree/master/examples/aurora-mysql)
7070
* [Global Aurora MySQL](https://github.com/umotif-public/terraform-aws-rds-aurora/tree/master/examples/global-aurora-mysql)
71+
* [Aurora Serverless](https://github.com/umotif-public/terraform-aws-rds-aurora/tree/master/examples/serverless)
72+
* [Aurora Postgres](https://github.com/umotif-public/terraform-aws-rds-aurora/tree/master/examples/aurora-postgres)
7173

7274
## Authors
7375

@@ -89,14 +91,14 @@ In order to activate global cluster, set `enable_global_cluster = true` when usi
8991
| Name | Version |
9092
|------|---------|
9193
| terraform | >= 0.12.6 |
92-
| aws | >= 3.8 |
94+
| aws | >= 3.15 |
9395
| random | >= 2.3 |
9496

9597
## Providers
9698

9799
| Name | Version |
98100
|------|---------|
99-
| aws | >= 3.8 |
101+
| aws | >= 3.15 |
100102
| random | >= 2.3 |
101103

102104
## Inputs
@@ -125,7 +127,7 @@ In order to activate global cluster, set `enable_global_cluster = true` when usi
125127
| deletion\_protection | If the DB instance should have deletion protection enabled | `bool` | `false` | no |
126128
| enable\_global\_cluster | Set this variable to `true` if DB Cluster is going to be part of a Global Cluster. | `bool` | `false` | no |
127129
| enable\_http\_endpoint | Whether or not to enable the Data API for a serverless Aurora database engine. | `bool` | `false` | no |
128-
| enabled\_cloudwatch\_logs\_exports | List of object which define log types to export to cloudwatch. See in examples. | `list` | `[]` | no |
130+
| enabled\_cloudwatch\_logs\_exports | List of object which define log types to export to AWS Cloudwatch. See in examples. | `list` | `[]` | no |
129131
| engine | Aurora database engine type, currently aurora, aurora-mysql or aurora-postgresql | `string` | `"aurora"` | no |
130132
| engine\_mode | The database engine mode. Valid values: global, parallelquery, provisioned, serverless. | `string` | `"provisioned"` | no |
131133
| engine\_parameter\_family | The database engine paramater group family | `string` | `"aurora-mysql5.7"` | no |
@@ -160,6 +162,7 @@ In order to activate global cluster, set `enable_global_cluster = true` when usi
160162
| replica\_scale\_min | Minimum number of replicas to allow scaling for | `number` | `2` | no |
161163
| replica\_scale\_out\_cooldown | Cooldown in seconds before allowing further scaling operations after a scale out | `number` | `300` | no |
162164
| replication\_source\_identifier | ARN of a source DB cluster or DB instance if this DB cluster is to be created as a Read Replica. | `string` | `""` | no |
165+
| restore\_to\_point\_in\_time | Restore to point in time configuration. See docs for arguments https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster#restore_to_point_in_time-argument-reference | `map(string)` | `{}` | no |
163166
| scaling\_configuration | Map of nested attributes with scaling properties. Only valid when engine\_mode is set to `serverless` | `map(string)` | `{}` | no |
164167
| security\_group\_description | The description of the security group. If value is set to empty string it will contain cluster name in the description. | `string` | `""` | no |
165168
| skip\_final\_snapshot | Should a final snapshot be created on cluster destroy | `bool` | `false` | no |

examples/aurora-mysql/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ data "aws_region" "current" {}
1010
#####
1111
module "vpc" {
1212
source = "terraform-aws-modules/vpc/aws"
13-
version = "~> 2.63"
13+
version = "~> 2.64"
1414

1515
name = "simple-rds-aurora-vpc"
1616

examples/aurora-postgres/main.tf

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
provider "aws" {
2+
region = "eu-west-1"
3+
}
4+
5+
#####
6+
# VPC and subnets
7+
#####
8+
module "vpc" {
9+
source = "terraform-aws-modules/vpc/aws"
10+
version = "~> 2.64"
11+
12+
name = "simple-vpc-aurora-postgres"
13+
14+
cidr = "10.0.0.0/16"
15+
16+
azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
17+
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
18+
19+
enable_nat_gateway = false
20+
21+
tags = {
22+
Environment = "test"
23+
}
24+
}
25+
26+
module "aurora-postgresql" {
27+
source = "../.."
28+
29+
name_prefix = "example-aurora-postgresql"
30+
31+
engine = "aurora-postgresql"
32+
engine_version = "11.8"
33+
engine_parameter_family = "aurora-postgresql11"
34+
35+
apply_immediately = true
36+
allow_major_version_upgrade = true
37+
skip_final_snapshot = true
38+
39+
iam_database_authentication_enabled = true
40+
41+
enabled_cloudwatch_logs_exports = [
42+
{
43+
name = "postgresql"
44+
}
45+
]
46+
47+
48+
vpc_id = module.vpc.vpc_id
49+
subnets = module.vpc.public_subnets
50+
51+
replica_count = 1
52+
instance_type = "db.t3.medium"
53+
54+
allowed_cidr_blocks = ["10.10.0.0/24", "10.20.0.0/24", "10.30.0.0/24"]
55+
56+
tags = {
57+
Environment = "test"
58+
Engine = "aurora-postgresql"
59+
}
60+
}

examples/global-aurora-mysql/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module "vpc_ireland" {
3232
}
3333

3434
source = "terraform-aws-modules/vpc/aws"
35-
version = "~> 2.63"
35+
version = "~> 2.64"
3636

3737
name = "simple-vpc"
3838

examples/serverless/main.tf

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
provider "aws" {
2+
region = "eu-west-1"
3+
}
4+
5+
#####
6+
# VPC and subnets
7+
#####
8+
module "vpc" {
9+
source = "terraform-aws-modules/vpc/aws"
10+
version = "~> 2.64"
11+
12+
name = "simple-vpc-aurora-serverless"
13+
14+
cidr = "10.0.0.0/16"
15+
16+
azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
17+
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
18+
19+
enable_nat_gateway = false
20+
21+
tags = {
22+
Environment = "test"
23+
}
24+
}
25+
26+
module "aurora-serverless" {
27+
source = "../../"
28+
29+
name_prefix = "example-aurora-serverless"
30+
31+
engine = "aurora"
32+
engine_mode = "serverless"
33+
engine_parameter_family = "aurora5.6"
34+
35+
replica_count = 0
36+
37+
vpc_id = module.vpc.vpc_id
38+
subnets = module.vpc.public_subnets
39+
40+
instance_type = "db.t3.medium"
41+
apply_immediately = true
42+
skip_final_snapshot = true
43+
storage_encrypted = true
44+
45+
iam_database_authentication_enabled = false # can't be set to true yet
46+
47+
scaling_configuration = {
48+
auto_pause = true
49+
max_capacity = 256
50+
min_capacity = 2
51+
seconds_until_auto_pause = 300
52+
timeout_action = "ForceApplyCapacityChange"
53+
}
54+
}

main.tf

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ resource "aws_rds_cluster" "main" {
105105
source_region = var.source_region
106106
engine = var.engine
107107
engine_mode = var.engine_mode
108-
engine_version = var.engine_version
108+
engine_version = var.engine_mode == "serverless" ? null : var.engine_version
109109
enable_http_endpoint = var.enable_http_endpoint
110110

111111
kms_key_id = var.kms_key_id
@@ -140,6 +140,17 @@ resource "aws_rds_cluster" "main" {
140140

141141
enabled_cloudwatch_logs_exports = [for log in var.enabled_cloudwatch_logs_exports : log.name]
142142

143+
dynamic "restore_to_point_in_time" {
144+
for_each = length(keys(var.restore_to_point_in_time)) == 0 ? [] : [var.restore_to_point_in_time]
145+
146+
content {
147+
source_cluster_identifier = lookup(restore_to_point_in_time.value, "source_cluster_identifier", null)
148+
restore_type = lookup(restore_to_point_in_time.value, "restore_type", null)
149+
use_latest_restorable_time = lookup(restore_to_point_in_time.value, "use_latest_restorable_time", null)
150+
restore_to_time = lookup(restore_to_point_in_time.value, "restore_to_time", null)
151+
}
152+
}
153+
143154
dynamic "scaling_configuration" {
144155
for_each = length(keys(var.scaling_configuration)) == 0 ? [] : [var.scaling_configuration]
145156

@@ -158,7 +169,7 @@ resource "aws_rds_cluster" "main" {
158169
)
159170

160171
lifecycle {
161-
ignore_changes = [master_username, master_password]
172+
ignore_changes = [master_username, master_password, snapshot_identifier]
162173
}
163174

164175
depends_on = [aws_cloudwatch_log_group.audit_log_group]
@@ -177,7 +188,7 @@ resource "aws_rds_cluster" "global" {
177188
source_region = var.source_region
178189
engine = var.engine
179190
engine_mode = var.engine_mode
180-
engine_version = var.engine_version
191+
engine_version = var.engine_mode == "serverless" ? null : var.engine_version
181192
enable_http_endpoint = var.enable_http_endpoint
182193

183194
kms_key_id = var.kms_key_id
@@ -212,6 +223,17 @@ resource "aws_rds_cluster" "global" {
212223

213224
enabled_cloudwatch_logs_exports = [for log in var.enabled_cloudwatch_logs_exports : log.name]
214225

226+
dynamic "restore_to_point_in_time" {
227+
for_each = length(keys(var.restore_to_point_in_time)) == 0 ? [] : [var.restore_to_point_in_time]
228+
229+
content {
230+
source_cluster_identifier = lookup(restore_to_point_in_time.value, "source_cluster_identifier", null)
231+
restore_type = lookup(restore_to_point_in_time.value, "restore_type", null)
232+
use_latest_restorable_time = lookup(restore_to_point_in_time.value, "use_latest_restorable_time", null)
233+
restore_to_time = lookup(restore_to_point_in_time.value, "restore_to_time", null)
234+
}
235+
}
236+
215237
dynamic "scaling_configuration" {
216238
for_each = length(keys(var.scaling_configuration)) == 0 ? [] : [var.scaling_configuration]
217239

@@ -230,7 +252,7 @@ resource "aws_rds_cluster" "global" {
230252
)
231253

232254
lifecycle {
233-
ignore_changes = [master_username, master_password, replication_source_identifier]
255+
ignore_changes = [master_username, master_password, replication_source_identifier, snapshot_identifier]
234256
}
235257

236258
depends_on = [aws_cloudwatch_log_group.audit_log_group]

variables.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ variable "iam_database_authentication_enabled" {
258258
}
259259

260260
variable "enabled_cloudwatch_logs_exports" {
261-
description = "List of object which define log types to export to cloudwatch. See in examples."
261+
description = "List of object which define log types to export to AWS Cloudwatch. See in examples."
262262
type = list
263263
default = []
264264
}
@@ -404,3 +404,8 @@ variable "enable_global_cluster" {
404404
default = false
405405
}
406406

407+
variable "restore_to_point_in_time" {
408+
description = "Restore to point in time configuration. See docs for arguments https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster#restore_to_point_in_time-argument-reference"
409+
type = map(string)
410+
default = {}
411+
}

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_version = ">= 0.12.6"
33

44
required_providers {
5-
aws = ">= 3.8"
5+
aws = ">= 3.15"
66
random = ">= 2.3"
77
}
88
}

0 commit comments

Comments
 (0)