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(mysql): aurora serverless #39

Merged
merged 1 commit into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 17 additions & 3 deletions default.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
locals {
default_mysql_cluster = {
engine = "aurora-mysql"
engine_mode = "provisioned"
mode = "provisioned"
family = "aurora-mysql5.7"
version = "5.7.12"
version = "5.7.mysql_aurora.2.07.1"
port = "3306"
database = "yourdb"
user = "yourid"
Expand All @@ -13,6 +13,13 @@ locals {
backup_retention = 7
apply_immediately = false
cluster_parameters = {}
scaling = {
auto_pause = true
max_capacity = 128
min_capacity = 1
seconds_until_auto_pause = 300
timeout_action = "ForceApplyCapacityChange"
}
}
default_mysql_instances = [
{
Expand All @@ -23,7 +30,7 @@ locals {

default_postgresql_cluster = {
engine = "aurora-postgresql"
engine_mode = "provisioned"
mode = "provisioned"
family = "aurora-postgresql11"
version = "11.7"
port = "5432"
Expand All @@ -35,6 +42,13 @@ locals {
backup_retention = 7
apply_immediately = false
cluster_parameters = {}
scaling = {
auto_pause = true
max_capacity = 128
min_capacity = 1
seconds_until_auto_pause = 300
timeout_action = "ForceApplyCapacityChange"
}
}
default_postgresql_instances = [
{
Expand Down
2 changes: 1 addition & 1 deletion examples/mysql/fixture.tc1.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name = "aurora-mysql-tc1-multi-az"
tags = { test = "tc1" }
aurora_cluster = {
engine = "aurora-mysql"
version = "5.7.12"
version = "5.7.mysql_aurora.2.07.1"
port = "3306"
user = "yourid"
database = "yourdb"
Expand Down
2 changes: 1 addition & 1 deletion examples/mysql/fixture.tc2.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name = "aurora-mysql-tc2-cluster-only"
tags = { test = "tc2" }
aurora_cluster = {
engine = "aurora-mysql"
version = "5.7.12"
version = "5.7.mysql_aurora.2.07.1"
port = "3306"
user = "yourid"
database = "yourdb"
Expand Down
3 changes: 2 additions & 1 deletion examples/mysql/fixture.tc3.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ name = "aurora-mysql-tc3-custom-pw"
tags = { test = "tc3" }
aurora_cluster = {
engine = "aurora-mysql"
version = "5.7.12"
family = "aurora-mysql8.0"
version = "8.0.mysql_aurora.3.01.0"
port = "3306"
user = "yourid"
password = "supersecret"
Expand Down
17 changes: 17 additions & 0 deletions examples/mysql/fixture.tc4.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
aws_region = "ap-northeast-2"
azs = ["ap-northeast-2a", "ap-northeast-2b", "ap-northeast-2c"]
cidrs = ["10.0.0.0/16"]
name = "aurora-mysql-tc4-serverless"
tags = {
test = "tc4"
scaling = "default"
serverless_version = "v1"
}
aurora_cluster = {
engine = "aurora-mysql"
mode = "serverless"
user = "yourid"
database = "yourdb"
apply_immediately = "false"
}
aurora_instances = []
17 changes: 17 additions & 0 deletions examples/mysql/fixture.tc5.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
aws_region = "ap-northeast-2"
azs = ["ap-northeast-2a", "ap-northeast-2b", "ap-northeast-2c"]
cidrs = ["10.0.0.0/16"]
name = "aurora-mysql-tc5-serverless"
tags = {
test = "tc5"
scaling = "customized"
serverless_version = "v1"
}
aurora_cluster = {
engine = "aurora-mysql"
mode = "serverless"
user = "yourid"
database = "yourdb"
apply_immediately = "false"
}
aurora_instances = []
27 changes: 27 additions & 0 deletions examples/mysql/fixture.tc6.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
aws_region = "ap-northeast-2"
azs = ["ap-northeast-2a", "ap-northeast-2b", "ap-northeast-2c"]
cidrs = ["10.0.0.0/16"]
name = "aurora-mysql-tc6-serverlessv2"
tags = {
test = "tc6"
scaling = "customized"
serverless_version = "v2"
}
aurora_cluster = {
engine = "aurora-mysql"
family = "aurora-mysql8.0"
version = "8.0.mysql_aurora.3.02.0"
mode = "provisioned"
user = "yourid"
database = "yourdb"
apply_immediately = "false"
scaling_v2 = {
max_capacity = 128.0
min_capacity = 0.5
}
}
aurora_instances = [
{
instance_type = "db.serverless"
},
]
21 changes: 20 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ resource "aws_db_parameter_group" "db" {
resource "aws_rds_cluster" "db" {
cluster_identifier = local.name
engine = lookup(var.aurora_cluster, "engine", local.default_cluster.engine)
engine_mode = lookup(var.aurora_cluster, "engine_mode", local.default_cluster.engine_mode)
engine_mode = lookup(var.aurora_cluster, "mode", local.default_cluster.mode)
engine_version = lookup(var.aurora_cluster, "version", local.default_cluster.version)
port = lookup(var.aurora_cluster, "port", local.default_cluster.port)
skip_final_snapshot = lookup(var.aurora_cluster, "skip_final_snapshot", local.default_cluster.skip_final_snapshot)
Expand All @@ -81,6 +81,25 @@ resource "aws_rds_cluster" "db" {
vpc_security_group_ids = coalescelist(aws_security_group.db.*.id, [])
tags = merge(local.default-tags, var.tags)

dynamic "scaling_configuration" {
for_each = { for k, v in var.aurora_cluster : k => v if k == "scaling" }
content {
max_capacity = lookup(scaling_configuration.value, "max_capacity", 256)
min_capacity = lookup(scaling_configuration.value, "min_capacity", 2)
auto_pause = lookup(scaling_configuration.value, "auto_pause", true)
seconds_until_auto_pause = lookup(scaling_configuration.value, "seconds_until_auto_pause", 300)
timeout_action = lookup(scaling_configuration.value, "timeout_action", "ForceApplyCapacityChange")
}
}

dynamic "serverlessv2_scaling_configuration" {
for_each = { for k, v in var.aurora_cluster : k => v if k == "scaling_v2" }
content {
max_capacity = lookup(serverlessv2_scaling_configuration.value, "max_capacity", 128.0)
min_capacity = lookup(serverlessv2_scaling_configuration.value, "min_capacity", 0.5)
}
}

lifecycle {
ignore_changes = [snapshot_identifier, master_password]
create_before_destroy = true
Expand Down
1 change: 1 addition & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ variable "aurora_cluster" {
description = "RDS Aurora for mysql cluster definition"
default = {
engine = "aurora-mysql"
mode = "provisioned" # Allowed values: global, multimaster, parallelquery, provisioned, serverless.
version = "5.7.12"
port = "3306"
user = "yourid"
Expand Down
6 changes: 6 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@

terraform {
required_version = ">= 0.13"
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.0"
}
}
}