diff --git a/README.md b/README.md
index e71b99e..cdec846 100644
--- a/README.md
+++ b/README.md
@@ -43,6 +43,7 @@ module "db" {
## Examples
- [PostgreSQL](examples/postgres): A simple example with VPC and PostgreSQL cluster.
+- [PostgreSQL Serverless V2](examples/postgresql-serverlessv2): A simple example with VPC and PostgreSQL Serverless V2 cluster.
- [MySQL](examples/mysql): A simple example with VPC and MySQL cluster.
- [Production](examples/production): A production ready PostgreSQL cluster with enhanced monitoring, autoscaling and cloudwatch alarms.
@@ -60,13 +61,13 @@ terraform-docs md ./ | cat -s | perl -e "print reverse(<>)" | tail -n +2 | perl
| Name | Version |
|------|---------|
-| [aws](#requirement\_aws) | >= 3.63.0 |
+| [aws](#requirement\_aws) | >= 4.12.1 |
## Providers
| Name | Version |
|------|---------|
-| [aws](#provider\_aws) | >= 3.63.0 |
+| [aws](#provider\_aws) | >= 4.12.1 |
| [random](#provider\_random) | n/a |
## Modules
@@ -138,6 +139,7 @@ No modules.
| [deletion\_protection](#input\_deletion\_protection) | The database can't be deleted when this value is set to true. | `bool` | `true` | no |
| [enabled\_cloudwatch\_logs\_exports](#input\_enabled\_cloudwatch\_logs\_exports) | Set of log types to export to cloudwatch. If omitted, no logs will be exported. The following log types are supported: audit, error, general, slowquery, postgresql (PostgreSQL). | `list(any)` | `[]` | no |
| [engine](#input\_engine) | Aurora database engine type, currently aurora, aurora-mysql or aurora-postgresql | `string` | `"aurora"` | no |
+| [engine\_mode](#input\_engine\_mode) | Aurora database engine mode. | `string` | `"provisioned"` | no |
| [engine\_version](#input\_engine\_version) | Aurora database engine version. | `string` | `"5.6.10a"` | no |
| [extra\_security\_groups](#input\_extra\_security\_groups) | A list of Security Group IDs to add to the cluster | `list` | `[]` | no |
| [final\_snapshot\_identifier\_prefix](#input\_final\_snapshot\_identifier\_prefix) | The prefix name to use when creating a final snapshot on cluster destroy, appends a random 8 digits to name to ensure it's unique too. | `string` | `"final-"` | no |
@@ -168,6 +170,8 @@ No modules.
| [route53\_record\_ttl](#input\_route53\_record\_ttl) | TTL of route53 record. Only used if route53\_zone\_id is passed also | `string` | `60` | no |
| [route53\_zone\_id](#input\_route53\_zone\_id) | If specified a route53 record will be created | `string` | `""` | no |
| [security\_group\_name\_prefix](#input\_security\_group\_name\_prefix) | Prefix for security group name | `string` | `"aurora-"` | no |
+| [serverlessv2\_max\_capacity](#input\_serverlessv2\_max\_capacity) | Maximum capacity for an Aurora DB cluster in provisioned(serverless v2) DB engine mode | `number` | `1` | no |
+| [serverlessv2\_min\_capacity](#input\_serverlessv2\_min\_capacity) | Minimum capacity for an Aurora DB cluster in provisioned(serverless v2) DB engine mode | `number` | `0.5` | no |
| [skip\_final\_snapshot](#input\_skip\_final\_snapshot) | Should a final snapshot be created on cluster destroy | `bool` | `false` | no |
| [snapshot\_identifier](#input\_snapshot\_identifier) | DB snapshot to create this database from | `string` | `""` | no |
| [storage\_encrypted](#input\_storage\_encrypted) | Specifies whether the underlying storage layer should be encrypted | `bool` | `false` | no |
diff --git a/examples/postgresql-serverlessv2/README.md b/examples/postgresql-serverlessv2/README.md
new file mode 100644
index 0000000..beec765
--- /dev/null
+++ b/examples/postgresql-serverlessv2/README.md
@@ -0,0 +1,9 @@
+# A simple example
+
+This example will show the bare minimum parameters to create a Serverless V2 PostgreSQL Aurora cluster.
+
+In general setup of the PostgreSQL serverless v2 cluster is very similar to creation of a regular PostgreSQL cluster.
+The only crucial differences are the following:
+* `engine_mode` needs to be specified and set to `provisioned`
+* `instance_type` is to be set to `db.serverless`
+* Scaling params are to be set in `serverlessv2_min_capacity` and `serverlessv2_max_capacity` params.
\ No newline at end of file
diff --git a/examples/postgresql-serverlessv2/main.tf b/examples/postgresql-serverlessv2/main.tf
new file mode 100644
index 0000000..206488c
--- /dev/null
+++ b/examples/postgresql-serverlessv2/main.tf
@@ -0,0 +1,76 @@
+provider "aws" {
+ region = "eu-west-1"
+}
+
+data "aws_availability_zones" "available" {}
+
+module "aurora" {
+ source = "../../"
+ name = "aurora-example-postgresql"
+ engine = "aurora-postgresql"
+ engine_mode = "provisioned"
+ engine_version = "16.4"
+ subnet_ids = ["${module.vpc.database_subnets}"]
+ vpc_id = "${module.vpc.vpc_id}"
+ replica_count = 1
+ instance_type = "db.serverless"
+ apply_immediately = true
+ skip_final_snapshot = true
+ db_parameter_group_name = "${aws_db_parameter_group.aurora_db_postgres164_parameter_group.id}"
+ db_cluster_parameter_group_name = "${aws_rds_cluster_parameter_group.aurora_cluster_postgres164_parameter_group.id}"
+ serverlessv2_min_capacity = 0.5
+ serverlessv2_max_capacity = 2
+}
+
+resource "aws_db_parameter_group" "aurora_db_postgres164_parameter_group" {
+ name = "test-aurora-db-postgres164-parameter-group"
+ family = "aurora-postgresql16.4"
+ description = "test-aurora-db-postgres164-parameter-group"
+}
+
+resource "aws_rds_cluster_parameter_group" "aurora_cluster_postgres164_parameter_group" {
+ name = "test-aurora-postgres164-cluster-parameter-group"
+ family = "aurora-postgresql16.4"
+ description = "test-aurora-postgres164-cluster-parameter-group"
+}
+
+resource "aws_security_group" "app_servers" {
+ name = "app-servers"
+ description = "For application servers"
+ vpc_id = "${module.vpc.vpc_id}"
+}
+
+resource "aws_security_group_rule" "allow_access" {
+ type = "ingress"
+ from_port = "${module.aurora.cluster_port}"
+ to_port = "${module.aurora.cluster_port}"
+ protocol = "tcp"
+ source_security_group_id = "${aws_security_group.app_servers.id}"
+ security_group_id = "${module.aurora.security_group_id}"
+}
+
+module "vpc" {
+ source = "terraform-aws-modules/vpc/aws"
+ version = "1.46.0"
+ name = "example-postgres"
+ cidr = "10.0.0.0/16"
+ azs = ["${data.aws_availability_zones.available.names}"]
+
+ private_subnets = [
+ "10.0.1.0/24",
+ "10.0.2.0/24",
+ "10.0.3.0/25",
+ ]
+
+ public_subnets = [
+ "10.0.4.0/24",
+ "10.0.5.0/24",
+ "10.0.6.0/25",
+ ]
+
+ database_subnets = [
+ "10.0.7.0/24",
+ "10.0.8.0/24",
+ "10.0.9.0/25",
+ ]
+}
diff --git a/main.tf b/main.tf
index bd4447c..b9c842c 100644
--- a/main.tf
+++ b/main.tf
@@ -46,6 +46,7 @@ resource "aws_rds_cluster" "main" {
cluster_identifier = "${var.identifier_prefix}${var.name}"
engine = var.engine
engine_version = var.engine_version
+ engine_mode = var.engine_mode
kms_key_id = var.kms_key_id
master_username = var.username
master_password = local.master_password
@@ -71,6 +72,14 @@ resource "aws_rds_cluster" "main" {
update = var.update_timeout
delete = var.delete_timeout
}
+
+ dynamic "serverlessv2_scaling_configuration" {
+ for_each = var.instance_type == "db.serverless" ? [1] : []
+ content {
+ max_capacity = var.serverlessv2_max_capacity
+ min_capacity = var.serverlessv2_min_capacity
+ }
+ }
}
resource "aws_rds_cluster_instance" "instance" {
diff --git a/variables.tf b/variables.tf
index 907a1e0..87b4efa 100644
--- a/variables.tf
+++ b/variables.tf
@@ -199,6 +199,11 @@ variable "engine_version" {
default = "5.6.10a"
}
+variable "engine_mode" {
+ description = "Aurora database engine mode."
+ default = "provisioned"
+}
+
variable "replica_autoscaling" {
type = string
default = false
@@ -357,3 +362,15 @@ variable "cloudwatch_log_group_retention_in_days" {
type = number
default = 1
}
+
+variable "serverlessv2_min_capacity" {
+ description = "Minimum capacity for an Aurora DB cluster in provisioned (serverless v2) DB engine mode"
+ type = number
+ default = 0.5
+}
+
+variable "serverlessv2_max_capacity" {
+ description = "Maximum capacity for an Aurora DB cluster in provisioned (serverless v2) DB engine mode"
+ type = number
+ default = 1
+}
diff --git a/versions.tf b/versions.tf
index 851b378..fc68dbe 100644
--- a/versions.tf
+++ b/versions.tf
@@ -2,7 +2,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
- version = ">= 3.63.0"
+ version = ">= 4.12.1"
}
}
}