diff --git a/README.md b/README.md
index 3f8cdac..62c8e4f 100644
--- a/README.md
+++ b/README.md
@@ -92,7 +92,7 @@ module "documentdb_cluster" {
| Name | Version |
|------|---------|
| [terraform](#requirement\_terraform) | >= 1.3 |
-| [aws](#requirement\_aws) | >= 5.29.0 |
+| [aws](#requirement\_aws) | >= 6.8.0 |
| [local](#requirement\_local) | >= 1.3 |
| [random](#requirement\_random) | >= 1.0 |
@@ -100,7 +100,7 @@ module "documentdb_cluster" {
| Name | Version |
|------|---------|
-| [aws](#provider\_aws) | >= 5.29.0 |
+| [aws](#provider\_aws) | >= 6.8.0 |
| [random](#provider\_random) | >= 1.0 |
## Modules
@@ -177,6 +177,7 @@ module "documentdb_cluster" {
| [reader\_dns\_name](#input\_reader\_dns\_name) | Name of the reader endpoint CNAME record to create in the parent DNS zone specified by `zone_id`. If left empty, the name will be auto-asigned using the format `replicas.var.name` | `string` | `""` | no |
| [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.
Characters matching the regex will be removed from the ID elements.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
| [retention\_period](#input\_retention\_period) | Number of days to retain backups for | `number` | `5` | no |
+| [serverless\_v2\_scaling\_configuration](#input\_serverless\_v2\_scaling\_configuration) | Configuration for serverless v2 scaling. See https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/docdb_cluster#serverless_v2_scaling_configuration |
object({
min_capacity = optional(number, 0.5)
max_capacity = optional(number, 256)
}) | `null` | no |
| [skip\_final\_snapshot](#input\_skip\_final\_snapshot) | Determines whether a final DB snapshot is created before the DB cluster is deleted | `bool` | `true` | no |
| [snapshot\_identifier](#input\_snapshot\_identifier) | Specifies whether or not to create this cluster from a snapshot. You can use either the name or ARN when specifying a DB cluster snapshot, or the ARN when specifying a DB snapshot | `string` | `""` | no |
| [ssm\_parameter\_enabled](#input\_ssm\_parameter\_enabled) | Whether an SSM parameter store value is created to store the database password. | `bool` | `false` | no |
diff --git a/examples/complete/versions.tf b/examples/complete/versions.tf
index 64ee71a..38300fb 100644
--- a/examples/complete/versions.tf
+++ b/examples/complete/versions.tf
@@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
- version = ">= 5.21.0"
+ version = ">= 6.8.0"
}
local = {
source = "hashicorp/local"
diff --git a/examples/serverless/context.tf b/examples/serverless/context.tf
new file mode 100644
index 0000000..5e0ef88
--- /dev/null
+++ b/examples/serverless/context.tf
@@ -0,0 +1,279 @@
+#
+# ONLY EDIT THIS FILE IN github.com/cloudposse/terraform-null-label
+# All other instances of this file should be a copy of that one
+#
+#
+# Copy this file from https://github.com/cloudposse/terraform-null-label/blob/master/exports/context.tf
+# and then place it in your Terraform module to automatically get
+# Cloud Posse's standard configuration inputs suitable for passing
+# to Cloud Posse modules.
+#
+# curl -sL https://raw.githubusercontent.com/cloudposse/terraform-null-label/master/exports/context.tf -o context.tf
+#
+# Modules should access the whole context as `module.this.context`
+# to get the input variables with nulls for defaults,
+# for example `context = module.this.context`,
+# and access individual variables as `module.this.`,
+# with final values filled in.
+#
+# For example, when using defaults, `module.this.context.delimiter`
+# will be null, and `module.this.delimiter` will be `-` (hyphen).
+#
+
+module "this" {
+ source = "cloudposse/label/null"
+ version = "0.25.0" # requires Terraform >= 0.13.0
+
+ enabled = var.enabled
+ namespace = var.namespace
+ tenant = var.tenant
+ environment = var.environment
+ stage = var.stage
+ name = var.name
+ delimiter = var.delimiter
+ attributes = var.attributes
+ tags = var.tags
+ additional_tag_map = var.additional_tag_map
+ label_order = var.label_order
+ regex_replace_chars = var.regex_replace_chars
+ id_length_limit = var.id_length_limit
+ label_key_case = var.label_key_case
+ label_value_case = var.label_value_case
+ descriptor_formats = var.descriptor_formats
+ labels_as_tags = var.labels_as_tags
+
+ context = var.context
+}
+
+# Copy contents of cloudposse/terraform-null-label/variables.tf here
+
+variable "context" {
+ type = any
+ default = {
+ enabled = true
+ namespace = null
+ tenant = null
+ environment = null
+ stage = null
+ name = null
+ delimiter = null
+ attributes = []
+ tags = {}
+ additional_tag_map = {}
+ regex_replace_chars = null
+ label_order = []
+ id_length_limit = null
+ label_key_case = null
+ label_value_case = null
+ descriptor_formats = {}
+ # Note: we have to use [] instead of null for unset lists due to
+ # https://github.com/hashicorp/terraform/issues/28137
+ # which was not fixed until Terraform 1.0.0,
+ # but we want the default to be all the labels in `label_order`
+ # and we want users to be able to prevent all tag generation
+ # by setting `labels_as_tags` to `[]`, so we need
+ # a different sentinel to indicate "default"
+ labels_as_tags = ["unset"]
+ }
+ description = <<-EOT
+ Single object for setting entire context at once.
+ See description of individual variables for details.
+ Leave string and numeric variables as `null` to use default value.
+ Individual variable settings (non-null) override settings in context object,
+ except for attributes, tags, and additional_tag_map, which are merged.
+ EOT
+
+ validation {
+ condition = lookup(var.context, "label_key_case", null) == null ? true : contains(["lower", "title", "upper"], var.context["label_key_case"])
+ error_message = "Allowed values: `lower`, `title`, `upper`."
+ }
+
+ validation {
+ condition = lookup(var.context, "label_value_case", null) == null ? true : contains(["lower", "title", "upper", "none"], var.context["label_value_case"])
+ error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
+ }
+}
+
+variable "enabled" {
+ type = bool
+ default = null
+ description = "Set to false to prevent the module from creating any resources"
+}
+
+variable "namespace" {
+ type = string
+ default = null
+ description = "ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique"
+}
+
+variable "tenant" {
+ type = string
+ default = null
+ description = "ID element _(Rarely used, not included by default)_. A customer identifier, indicating who this instance of a resource is for"
+}
+
+variable "environment" {
+ type = string
+ default = null
+ description = "ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT'"
+}
+
+variable "stage" {
+ type = string
+ default = null
+ description = "ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release'"
+}
+
+variable "name" {
+ type = string
+ default = null
+ description = <<-EOT
+ ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
+ This is the only ID element not also included as a `tag`.
+ The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input.
+ EOT
+}
+
+variable "delimiter" {
+ type = string
+ default = null
+ description = <<-EOT
+ Delimiter to be used between ID elements.
+ Defaults to `-` (hyphen). Set to `""` to use no delimiter at all.
+ EOT
+}
+
+variable "attributes" {
+ type = list(string)
+ default = []
+ description = <<-EOT
+ ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,
+ in the order they appear in the list. New attributes are appended to the
+ end of the list. The elements of the list are joined by the `delimiter`
+ and treated as a single ID element.
+ EOT
+}
+
+variable "labels_as_tags" {
+ type = set(string)
+ default = ["default"]
+ description = <<-EOT
+ Set of labels (ID elements) to include as tags in the `tags` output.
+ Default is to include all labels.
+ Tags with empty values will not be included in the `tags` output.
+ Set to `[]` to suppress all generated tags.
+ **Notes:**
+ The value of the `name` tag, if included, will be the `id`, not the `name`.
+ Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be
+ changed in later chained modules. Attempts to change it will be silently ignored.
+ EOT
+}
+
+variable "tags" {
+ type = map(string)
+ default = {}
+ description = <<-EOT
+ Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).
+ Neither the tag keys nor the tag values will be modified by this module.
+ EOT
+}
+
+variable "additional_tag_map" {
+ type = map(string)
+ default = {}
+ description = <<-EOT
+ Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.
+ This is for some rare cases where resources want additional configuration of tags
+ and therefore take a list of maps with tag key, value, and additional configuration.
+ EOT
+}
+
+variable "label_order" {
+ type = list(string)
+ default = null
+ description = <<-EOT
+ The order in which the labels (ID elements) appear in the `id`.
+ Defaults to ["namespace", "environment", "stage", "name", "attributes"].
+ You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present.
+ EOT
+}
+
+variable "regex_replace_chars" {
+ type = string
+ default = null
+ description = <<-EOT
+ Terraform regular expression (regex) string.
+ Characters matching the regex will be removed from the ID elements.
+ If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits.
+ EOT
+}
+
+variable "id_length_limit" {
+ type = number
+ default = null
+ description = <<-EOT
+ Limit `id` to this many characters (minimum 6).
+ Set to `0` for unlimited length.
+ Set to `null` for keep the existing setting, which defaults to `0`.
+ Does not affect `id_full`.
+ EOT
+ validation {
+ condition = var.id_length_limit == null ? true : var.id_length_limit >= 6 || var.id_length_limit == 0
+ error_message = "The id_length_limit must be >= 6 if supplied (not null), or 0 for unlimited length."
+ }
+}
+
+variable "label_key_case" {
+ type = string
+ default = null
+ description = <<-EOT
+ Controls the letter case of the `tags` keys (label names) for tags generated by this module.
+ Does not affect keys of tags passed in via the `tags` input.
+ Possible values: `lower`, `title`, `upper`.
+ Default value: `title`.
+ EOT
+
+ validation {
+ condition = var.label_key_case == null ? true : contains(["lower", "title", "upper"], var.label_key_case)
+ error_message = "Allowed values: `lower`, `title`, `upper`."
+ }
+}
+
+variable "label_value_case" {
+ type = string
+ default = null
+ description = <<-EOT
+ Controls the letter case of ID elements (labels) as included in `id`,
+ set as tag values, and output by this module individually.
+ Does not affect values of tags passed in via the `tags` input.
+ Possible values: `lower`, `title`, `upper` and `none` (no transformation).
+ Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.
+ Default value: `lower`.
+ EOT
+
+ validation {
+ condition = var.label_value_case == null ? true : contains(["lower", "title", "upper", "none"], var.label_value_case)
+ error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
+ }
+}
+
+variable "descriptor_formats" {
+ type = any
+ default = {}
+ description = <<-EOT
+ Describe additional descriptors to be output in the `descriptors` output map.
+ Map of maps. Keys are names of descriptors. Values are maps of the form
+ `{
+ format = string
+ labels = list(string)
+ }`
+ (Type is `any` so the map values can later be enhanced to provide additional options.)
+ `format` is a Terraform format string to be passed to the `format()` function.
+ `labels` is a list of labels, in order, to pass to `format()` function.
+ Label values will be normalized before being passed to `format()` so they will be
+ identical to how they appear in `id`.
+ Default is `{}` (`descriptors` output will be empty).
+ EOT
+}
+
+#### End of copy of cloudposse/terraform-null-label/variables.tf
diff --git a/examples/serverless/fixtures.us-east-2.tfvars b/examples/serverless/fixtures.us-east-2.tfvars
new file mode 100644
index 0000000..91ce460
--- /dev/null
+++ b/examples/serverless/fixtures.us-east-2.tfvars
@@ -0,0 +1,45 @@
+region = "us-east-2"
+
+availability_zones = ["us-east-2a", "us-east-2b"]
+
+namespace = "eg"
+
+stage = "test"
+
+name = "documentdb-cluster"
+
+vpc_cidr_block = "172.16.0.0/16"
+
+instance_class = "db.serverless"
+
+cluster_size = 1
+
+db_port = 27017
+
+master_username = "admin1"
+
+master_password = "password1"
+
+retention_period = 5
+
+preferred_backup_window = "07:00-09:00"
+
+cluster_family = "docdb5.0"
+engine_version = "5.0.0"
+
+engine = "docdb"
+
+storage_encrypted = true
+
+storage_type = "standard"
+
+skip_final_snapshot = true
+
+apply_immediately = true
+
+ssm_parameter_enabled = true
+
+serverless_v2_scaling_configuration = {
+ min_capacity = 0.5
+ max_capacity = 2
+}
diff --git a/examples/serverless/main.tf b/examples/serverless/main.tf
new file mode 100644
index 0000000..49bfc42
--- /dev/null
+++ b/examples/serverless/main.tf
@@ -0,0 +1,73 @@
+/*
+Useful references:
+
+https://docs.aws.amazon.com/documentdb/latest/developerguide/db-instance-classes.html#db-instance-class-specs
+https://docs.aws.amazon.com/documentdb/latest/developerguide/db-cluster-parameter-group-create.html
+https://www.terraform.io/docs/providers/aws/r/docdb_cluster.html
+https://www.terraform.io/docs/providers/aws/r/docdb_cluster_instance.html
+https://www.terraform.io/docs/providers/aws/r/docdb_cluster_parameter_group.html
+https://www.terraform.io/docs/providers/aws/r/docdb_subnet_group.html
+https://docs.aws.amazon.com/documentdb/latest/developerguide/troubleshooting.html
+*/
+
+provider "aws" {
+ region = var.region
+}
+
+module "vpc" {
+ source = "cloudposse/vpc/aws"
+ version = "2.1.1"
+
+ ipv4_primary_cidr_block = var.vpc_cidr_block
+
+ context = module.this.context
+}
+
+module "subnets" {
+ source = "cloudposse/dynamic-subnets/aws"
+ version = "2.4.2"
+
+ availability_zones = var.availability_zones
+ vpc_id = module.vpc.vpc_id
+ igw_id = [module.vpc.igw_id]
+ ipv4_cidr_block = [module.vpc.vpc_cidr_block]
+ nat_gateway_enabled = false
+ nat_instance_enabled = false
+
+ context = module.this.context
+}
+
+module "documentdb_cluster" {
+ source = "../../"
+ cluster_size = var.cluster_size
+ master_username = var.master_username
+ master_password = var.master_password
+ instance_class = var.instance_class
+ db_port = var.db_port
+ vpc_id = module.vpc.vpc_id
+ subnet_ids = module.subnets.private_subnet_ids
+ zone_id = var.zone_id
+ apply_immediately = var.apply_immediately
+ auto_minor_version_upgrade = var.auto_minor_version_upgrade
+ allowed_security_groups = var.allowed_security_groups
+ allowed_cidr_blocks = var.allowed_cidr_blocks
+ snapshot_identifier = var.snapshot_identifier
+ retention_period = var.retention_period
+ preferred_backup_window = var.preferred_backup_window
+ preferred_maintenance_window = var.preferred_maintenance_window
+ cluster_parameters = var.cluster_parameters
+ cluster_family = var.cluster_family
+ engine = var.engine
+ engine_version = var.engine_version
+ storage_encrypted = var.storage_encrypted
+ storage_type = var.storage_type
+ kms_key_id = var.kms_key_id
+ skip_final_snapshot = var.skip_final_snapshot
+ enabled_cloudwatch_logs_exports = var.enabled_cloudwatch_logs_exports
+ cluster_dns_name = var.cluster_dns_name
+ reader_dns_name = var.reader_dns_name
+ ssm_parameter_enabled = var.ssm_parameter_enabled
+ serverless_v2_scaling_configuration = var.serverless_v2_scaling_configuration
+
+ context = module.this.context
+}
diff --git a/examples/serverless/outputs.tf b/examples/serverless/outputs.tf
new file mode 100644
index 0000000..384b37a
--- /dev/null
+++ b/examples/serverless/outputs.tf
@@ -0,0 +1,64 @@
+output "public_subnet_cidrs" {
+ value = module.subnets.public_subnet_cidrs
+ description = "Public subnet CIDRs"
+}
+
+output "private_subnet_cidrs" {
+ value = module.subnets.private_subnet_cidrs
+ description = "Private subnet CIDRs"
+}
+
+output "vpc_cidr" {
+ value = module.vpc.vpc_cidr_block
+ description = "VPC ID"
+}
+
+output "master_username" {
+ value = module.documentdb_cluster.master_username
+ description = "DocumentDB Username for the master DB user"
+}
+
+output "cluster_name" {
+ value = module.documentdb_cluster.cluster_name
+ description = "DocumentDB Cluster Identifier"
+}
+
+output "arn" {
+ value = module.documentdb_cluster.arn
+ description = "Amazon Resource Name (ARN) of the DocumentDB cluster"
+}
+
+output "endpoint" {
+ value = module.documentdb_cluster.endpoint
+ description = "Endpoint of the DocumentDB cluster"
+}
+
+output "reader_endpoint" {
+ value = module.documentdb_cluster.reader_endpoint
+ description = "Read-only endpoint of the DocumentDB cluster, automatically load-balanced across replicas"
+}
+
+output "master_host" {
+ value = module.documentdb_cluster.master_host
+ description = "DocumentDB master hostname"
+}
+
+output "replicas_host" {
+ value = module.documentdb_cluster.replicas_host
+ description = "DocumentDB replicas hostname"
+}
+
+output "security_group_id" {
+ value = module.documentdb_cluster.security_group_id
+ description = "ID of the DocumentDB cluster Security Group"
+}
+
+output "security_group_arn" {
+ value = module.documentdb_cluster.security_group_arn
+ description = "ARN of the DocumentDB cluster Security Group"
+}
+
+output "security_group_name" {
+ value = module.documentdb_cluster.security_group_name
+ description = "Name of the DocumentDB cluster Security Group"
+}
diff --git a/examples/serverless/variables.tf b/examples/serverless/variables.tf
new file mode 100644
index 0000000..298b8c2
--- /dev/null
+++ b/examples/serverless/variables.tf
@@ -0,0 +1,187 @@
+variable "region" {
+ type = string
+ description = "AWS Region for S3 bucket"
+}
+
+variable "availability_zones" {
+ type = list(string)
+ description = "List of availability zones"
+}
+
+variable "vpc_cidr_block" {
+ type = string
+ description = "VPC CIDR block"
+}
+
+variable "zone_id" {
+ type = string
+ default = ""
+ description = "Route53 parent zone ID. If provided (not empty), the module will create sub-domain DNS records for the DocumentDB master and replicas"
+}
+
+variable "allowed_security_groups" {
+ type = list(string)
+ default = []
+ description = "List of existing Security Groups to be allowed to connect to the DocumentDB cluster"
+}
+
+variable "allowed_cidr_blocks" {
+ type = list(string)
+ default = []
+ description = "List of CIDR blocks to be allowed to connect to the DocumentDB cluster"
+}
+
+variable "instance_class" {
+ type = string
+ default = "db.r4.large"
+ description = "The instance class to use. For more details, see https://docs.aws.amazon.com/documentdb/latest/developerguide/db-instance-classes.html#db-instance-class-specs"
+}
+
+variable "cluster_size" {
+ type = number
+ default = 2
+ description = "Number of DB instances to create in the cluster"
+}
+
+variable "snapshot_identifier" {
+ type = string
+ default = ""
+ description = "Specifies whether or not to create this cluster from a snapshot. You can use either the name or ARN when specifying a DB cluster snapshot, or the ARN when specifying a DB snapshot"
+}
+
+variable "db_port" {
+ type = number
+ default = 27017
+ description = "DocumentDB port"
+}
+
+variable "master_username" {
+ type = string
+ default = "admin1"
+ description = "(Required unless a snapshot_identifier is provided) Username for the master DB user"
+}
+
+variable "master_password" {
+ type = string
+ default = ""
+ description = "(Required unless a snapshot_identifier is provided) Password for the master DB user. Note that this may show up in logs, and it will be stored in the state file. Please refer to the DocumentDB Naming Constraints"
+}
+
+variable "retention_period" {
+ type = number
+ default = 5
+ description = "Number of days to retain backups for"
+}
+
+variable "preferred_backup_window" {
+ type = string
+ default = "07:00-09:00"
+ description = "Daily time range during which the backups happen"
+}
+
+variable "preferred_maintenance_window" {
+ type = string
+ default = "Mon:22:00-Mon:23:00"
+ description = "The window to perform maintenance in. Syntax: `ddd:hh24:mi-ddd:hh24:mi`."
+}
+
+variable "cluster_parameters" {
+ type = list(object({
+ apply_method = string
+ name = string
+ value = string
+ }))
+ default = []
+ description = "List of DB parameters to apply"
+}
+
+variable "cluster_family" {
+ type = string
+ default = "docdb3.6"
+ description = "The family of the DocumentDB cluster parameter group. For more details, see https://docs.aws.amazon.com/documentdb/latest/developerguide/db-cluster-parameter-group-create.html"
+}
+
+variable "engine" {
+ type = string
+ default = "docdb"
+ description = "The name of the database engine to be used for this DB cluster. Defaults to `docdb`. Valid values: `docdb`"
+}
+
+variable "engine_version" {
+ type = string
+ default = "3.6.0"
+ description = "The version number of the database engine to use"
+}
+
+variable "storage_encrypted" {
+ type = bool
+ description = "Specifies whether the DB cluster is encrypted"
+ default = true
+}
+
+variable "storage_type" {
+ type = string
+ description = "The storage type to associate with the DB cluster. Valid values: standard, iopt1"
+ default = "standard"
+
+ validation {
+ condition = contains(["standard", "iopt1"], var.storage_type)
+ error_message = "Error: storage_type value must be one of two options - 'standard' or 'iopt1'."
+ }
+}
+
+variable "kms_key_id" {
+ type = string
+ description = "The ARN for the KMS encryption key. When specifying `kms_key_id`, `storage_encrypted` needs to be set to `true`"
+ default = ""
+}
+
+variable "skip_final_snapshot" {
+ type = bool
+ description = "Determines whether a final DB snapshot is created before the DB cluster is deleted"
+ default = true
+}
+
+variable "apply_immediately" {
+ type = bool
+ description = "Specifies whether any cluster modifications are applied immediately, or during the next maintenance window"
+ default = true
+}
+
+variable "auto_minor_version_upgrade" {
+ type = bool
+ description = "Specifies whether any minor engine upgrades will be applied automatically to the DB instance during the maintenance window or not"
+ default = true
+}
+
+variable "enabled_cloudwatch_logs_exports" {
+ type = list(string)
+ description = "List of log types to export to cloudwatch. The following log types are supported: `audit`, `profiler`"
+ default = []
+}
+
+variable "cluster_dns_name" {
+ type = string
+ description = "Name of the cluster CNAME record to create in the parent DNS zone specified by `zone_id`. If left empty, the name will be auto-asigned using the format `master.var.name`"
+ default = ""
+}
+
+variable "reader_dns_name" {
+ type = string
+ description = "Name of the reader endpoint CNAME record to create in the parent DNS zone specified by `zone_id`. If left empty, the name will be auto-asigned using the format `replicas.var.name`"
+ default = ""
+}
+
+variable "ssm_parameter_enabled" {
+ type = bool
+ description = "Whether an SSM parameter store value is created to store the database password."
+}
+
+variable "serverless_v2_scaling_configuration" {
+ type = object({
+ min_capacity = number
+ max_capacity = number
+ })
+ default = null
+ description = "Configuration for serverless v2 scaling."
+}
diff --git a/examples/serverless/versions.tf b/examples/serverless/versions.tf
new file mode 100644
index 0000000..38300fb
--- /dev/null
+++ b/examples/serverless/versions.tf
@@ -0,0 +1,14 @@
+terraform {
+ required_version = ">= 1.3"
+
+ required_providers {
+ aws = {
+ source = "hashicorp/aws"
+ version = ">= 6.8.0"
+ }
+ local = {
+ source = "hashicorp/local"
+ version = ">= 1.3"
+ }
+ }
+}
diff --git a/main.tf b/main.tf
index caf8f4b..5f3ce2d 100644
--- a/main.tf
+++ b/main.tf
@@ -93,6 +93,21 @@ resource "aws_docdb_cluster" "default" {
enabled_cloudwatch_logs_exports = var.enabled_cloudwatch_logs_exports
allow_major_version_upgrade = var.allow_major_version_upgrade
tags = module.this.tags
+
+ dynamic "serverless_v2_scaling_configuration" {
+ for_each = var.serverless_v2_scaling_configuration != null ? [1] : []
+ content {
+ min_capacity = var.serverless_v2_scaling_configuration.min_capacity
+ max_capacity = var.serverless_v2_scaling_configuration.max_capacity
+ }
+ }
+
+ lifecycle {
+ precondition {
+ condition = (var.serverless_v2_scaling_configuration != null && contains(["db.serverless"], var.instance_class)) || (var.serverless_v2_scaling_configuration == null && var.instance_class != "db.serverless")
+ error_message = "Error: when serverless_v2_scaling_configuration is set, instance_class must be set to 'db.serverless'"
+ }
+ }
}
resource "aws_docdb_cluster_instance" "default" {
diff --git a/test/Makefile b/test/Makefile
index 095a5b7..3e5ce39 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -31,13 +31,19 @@ clean:
## Run all tests
all: module examples/complete
+all: module examples/serverless
## Run basic sanity checks against the module itself
module: export TESTS ?= installed lint module-pinning provider-pinning validate terraform-docs input-descriptions output-descriptions
module: deps
$(call RUN_TESTS, ../)
-## Run tests against example
+## Run tests against complete example
examples/complete: export TESTS ?= installed lint validate
examples/complete: deps
$(call RUN_TESTS, ../$@)
+
+## Run tests against serverless example
+examples/serverless: export TESTS ?= installed lint validate
+examples/serverless: deps
+ $(call RUN_TESTS, ../$@)
diff --git a/test/src/default_test.go b/test/src/default_test.go
index 114507d..1134bd9 100644
--- a/test/src/default_test.go
+++ b/test/src/default_test.go
@@ -7,20 +7,21 @@
package test
import (
- "github.com/gruntwork-io/terratest/modules/logger"
- "github.com/gruntwork-io/terratest/modules/terraform"
- "github.com/stretchr/testify/assert"
"os"
"regexp"
"strings"
"testing"
+
+ "github.com/gruntwork-io/terratest/modules/logger"
+ "github.com/gruntwork-io/terratest/modules/terraform"
+ "github.com/stretchr/testify/assert"
)
// Test the Terraform module in examples/complete using Terratest.
func TestExamplesComplete(t *testing.T) {
t.Parallel()
- testRunner(t, nil, testExamplesComplete)
+ testRunner(t, nil, testExamplesComplete, "examples/complete")
}
func TestExamplesCompleteDisabled(t *testing.T) {
@@ -29,7 +30,7 @@ func TestExamplesCompleteDisabled(t *testing.T) {
vars := map[string]interface{}{
"enabled": false,
}
- testRunner(t, vars, testExamplesCompleteDisabled)
+ testRunner(t, vars, testExamplesCompleteDisabled, "examples/complete")
}
func testExamplesCompleteDisabled(t *testing.T, terraformOptions *terraform.Options, randID string, results string) {
@@ -40,6 +41,13 @@ func testExamplesCompleteDisabled(t *testing.T, terraformOptions *terraform.Opti
assert.Equal(t, "Resources: 0 added, 0 changed, 0 destroyed.", match, "Re-applying the same configuration should not change any resources")
}
+// Test the Terraform module in examples/serverless using Terratest.
+func TestExamplesServerless(t *testing.T) {
+ t.Parallel()
+
+ testRunner(t, nil, testExamplesServerless, "examples/serverless")
+}
+
// To speed up debugging, allow running the tests on an existing deployment,
// without creating and destroying one.
// Run this manually by creating a deployment in examples/complete with:
diff --git a/test/src/examples_serverless_test.go b/test/src/examples_serverless_test.go
new file mode 100644
index 0000000..551bd11
--- /dev/null
+++ b/test/src/examples_serverless_test.go
@@ -0,0 +1,43 @@
+package test
+
+import (
+ "context"
+ "testing"
+
+ "github.com/aws/aws-sdk-go-v2/aws"
+ "github.com/aws/aws-sdk-go-v2/service/docdb"
+ "github.com/gruntwork-io/terratest/modules/terraform"
+ "github.com/stretchr/testify/assert"
+)
+
+// Test the Terraform module in examples/serverless using Terratest.
+func testExamplesServerless(t *testing.T, terraformOptions *terraform.Options, randID string, _ string) {
+
+ // Run `terraform output` to get the value of an output variable
+ clusterName := terraform.Output(t, terraformOptions, "cluster_name")
+ // Verify we're getting back the outputs we expect
+ assert.Equal(t, "eg-test-documentdb-cluster-"+randID, clusterName)
+
+ // Assert that AWS says the cluster is available
+ docdbSvc := docdb.NewFromConfig(AWSConfig())
+
+ // Describe the cluster
+ result, err := docdbSvc.DescribeDBClusters(context.TODO(), &docdb.DescribeDBClustersInput{
+ DBClusterIdentifier: &clusterName,
+ })
+ assert.NoError(t, err)
+
+ // Check if the slice is not empty and the status is available
+ if len(result.DBClusters) > 0 {
+ assert.Equal(t, "available", aws.ToString(result.DBClusters[0].Status), "Cluster is not in an available state")
+ } else {
+ assert.Fail(t, "No clusters found or cluster data is incomplete")
+ }
+
+ if result.DBClusters[0].ServerlessV2ScalingConfiguration != nil {
+ assert.Equal(t, float64(0.5), aws.ToFloat64(result.DBClusters[0].ServerlessV2ScalingConfiguration.MinCapacity), "Min capacity is not as expected")
+ assert.Equal(t, float64(2), aws.ToFloat64(result.DBClusters[0].ServerlessV2ScalingConfiguration.MaxCapacity), "Max capacity is not as expected")
+ } else {
+ assert.Fail(t, "Serverless V2 scaling configuration is not set")
+ }
+}
diff --git a/test/src/framework_test.go b/test/src/framework_test.go
index 5af5a8c..a5539fb 100644
--- a/test/src/framework_test.go
+++ b/test/src/framework_test.go
@@ -29,9 +29,8 @@ import (
"github.com/aws/aws-sdk-go/service/eks"
)
-// Test the Terraform module in examples/complete using Terratest.
-func testRunner(t *testing.T, vars map[string]interface{}, testFunc func(t *testing.T, terraformOptions *terraform.Options, randID string, results string)) {
- terraformFolderRelativeToRoot := "examples/complete"
+// Test the Terraform module in terraformFolderRelativeToRoot using Terratest.
+func testRunner(t *testing.T, vars map[string]interface{}, testFunc func(t *testing.T, terraformOptions *terraform.Options, randID string, results string), terraformFolderRelativeToRoot string) {
varFiles := []string{"fixtures.us-east-2.tfvars"}
terraformOptions := &terraform.Options{
diff --git a/test/src/go.mod b/test/src/go.mod
index 8f5c3c5..b80213a 100644
--- a/test/src/go.mod
+++ b/test/src/go.mod
@@ -6,9 +6,9 @@ toolchain go1.24.0
require (
github.com/aws/aws-sdk-go v1.44.332
- github.com/aws/aws-sdk-go-v2 v1.30.0
+ github.com/aws/aws-sdk-go-v2 v1.38.0
github.com/aws/aws-sdk-go-v2/config v1.27.21
- github.com/aws/aws-sdk-go-v2/service/docdb v1.35.1
+ github.com/aws/aws-sdk-go-v2/service/docdb v1.45.0
github.com/aws/aws-sdk-go-v2/service/ssm v1.51.1
github.com/gruntwork-io/terratest v0.46.15
github.com/stretchr/testify v1.8.4
@@ -28,15 +28,15 @@ require (
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.21 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.8 // indirect
- github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.12 // indirect
- github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.12 // indirect
+ github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.3 // indirect
+ github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.3 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
- github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect
- github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.14 // indirect
+ github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.0 // indirect
+ github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.21.1 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.25.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.29.1 // indirect
- github.com/aws/smithy-go v1.20.2 // indirect
+ github.com/aws/smithy-go v1.22.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
diff --git a/test/src/go.sum b/test/src/go.sum
index 3b52acb..33af0be 100644
--- a/test/src/go.sum
+++ b/test/src/go.sum
@@ -201,26 +201,26 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkY
github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
github.com/aws/aws-sdk-go v1.44.332 h1:Ze+98F41+LxoJUdsisAFThV+0yYYLYw17/Vt0++nFYM=
github.com/aws/aws-sdk-go v1.44.332/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
-github.com/aws/aws-sdk-go-v2 v1.30.0 h1:6qAwtzlfcTtcL8NHtbDQAqgM5s6NDipQTkPxyH/6kAA=
-github.com/aws/aws-sdk-go-v2 v1.30.0/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM=
+github.com/aws/aws-sdk-go-v2 v1.38.0 h1:UCRQ5mlqcFk9HJDIqENSLR3wiG1VTWlyUfLDEvY7RxU=
+github.com/aws/aws-sdk-go-v2 v1.38.0/go.mod h1:9Q0OoGQoboYIAJyslFyF1f5K1Ryddop8gqMhWx/n4Wg=
github.com/aws/aws-sdk-go-v2/config v1.27.21 h1:yPX3pjGCe2hJsetlmGNB4Mngu7UPmvWPzzWCv1+boeM=
github.com/aws/aws-sdk-go-v2/config v1.27.21/go.mod h1:4XtlEU6DzNai8RMbjSF5MgGZtYvrhBP/aKZcRtZAVdM=
github.com/aws/aws-sdk-go-v2/credentials v1.17.21 h1:pjAqgzfgFhTv5grc7xPHtXCAaMapzmwA7aU+c/SZQGw=
github.com/aws/aws-sdk-go-v2/credentials v1.17.21/go.mod h1:nhK6PtBlfHTUDVmBLr1dg+WHCOCK+1Fu/WQyVHPsgNQ=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.8 h1:FR+oWPFb/8qMVYMWN98bUZAGqPvLHiyqg1wqQGfUAXY=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.8/go.mod h1:EgSKcHiuuakEIxJcKGzVNWh5srVAQ3jKaSrBGRYvM48=
-github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.12 h1:SJ04WXGTwnHlWIODtC5kJzKbeuHt+OUNOgKg7nfnUGw=
-github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.12/go.mod h1:FkpvXhA92gb3GE9LD6Og0pHHycTxW7xGpnEh5E7Opwo=
-github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.12 h1:hb5KgeYfObi5MHkSSZMEudnIvX30iB+E21evI4r6BnQ=
-github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.12/go.mod h1:CroKe/eWJdyfy9Vx4rljP5wTUjNJfb+fPz1uMYUhEGM=
+github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.3 h1:o9RnO+YZ4X+kt5Z7Nvcishlz0nksIt2PIzDglLMP0vA=
+github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.3/go.mod h1:+6aLJzOG1fvMOyzIySYjOFjcguGvVRL68R+uoRencN4=
+github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.3 h1:joyyUFhiTQQmVK6ImzNU9TQSNRNeD9kOklqTzyk5v6s=
+github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.3/go.mod h1:+vNIyZQP3b3B1tSLI0lxvrU9cfM7gpdRXMFfm67ZcPc=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY=
-github.com/aws/aws-sdk-go-v2/service/docdb v1.35.1 h1:ONQmD3KEK/HEN9Fd+DX97tN4spsRb8EigGX+Q2hkefE=
-github.com/aws/aws-sdk-go-v2/service/docdb v1.35.1/go.mod h1:F8EZZZUOZ0QNB1wiYJ5LQuzQUvXg0RPfMkZfYVglEH8=
-github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 h1:Ji0DY1xUsUr3I8cHps0G+XM3WWU16lP6yG8qu1GAZAs=
-github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2/go.mod h1:5CsjAbs3NlGQyZNFACh+zztPDI7fU6eW9QsxjfnuBKg=
-github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.14 h1:zSDPny/pVnkqABXYRicYuPf9z2bTqfH13HT3v6UheIk=
-github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.14/go.mod h1:3TTcI5JSzda1nw/pkVC9dhgLre0SNBFj2lYS4GctXKI=
+github.com/aws/aws-sdk-go-v2/service/docdb v1.45.0 h1:sFzfpQ9wg2aHBKLP/pphRDFuV2QXFlcWMU+ZVwN1UF8=
+github.com/aws/aws-sdk-go-v2/service/docdb v1.45.0/go.mod h1:KHmHW5rJJ7bf8J56Rn2voXfsNTbUXS/TKdGNDurx7EQ=
+github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.0 h1:6+lZi2JeGKtCraAj1rpoZfKqnQ9SptseRZioejfUOLM=
+github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.0/go.mod h1:eb3gfbVIxIoGgJsi9pGne19dhCBpK6opTYpQqAmdy44=
+github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.3 h1:ieRzyHXypu5ByllM7Sp4hC5f/1Fy5wqxqY0yB85hC7s=
+github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.3/go.mod h1:O5ROz8jHiOAKAwx179v+7sHMhfobFVi6nZt8DEyiYoM=
github.com/aws/aws-sdk-go-v2/service/ssm v1.51.1 h1:MuFdaoXYgw4CPsiSa2G/T5CGOuSk90lb/eSTa+lRp9I=
github.com/aws/aws-sdk-go-v2/service/ssm v1.51.1/go.mod h1:pC8vyMIahlJIUKdXBto0R+JzoTK7+iEplKqq7DbWodY=
github.com/aws/aws-sdk-go-v2/service/sso v1.21.1 h1:sd0BsnAvLH8gsp2e3cbaIr+9D7T1xugueQ7V/zUAsS4=
@@ -229,8 +229,8 @@ github.com/aws/aws-sdk-go-v2/service/ssooidc v1.25.1 h1:1uEFNNskK/I1KoZ9Q8wJxMz5
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.25.1/go.mod h1:z0P8K+cBIsFXUr5rzo/psUeJ20XjPN0+Nn8067Nd+E4=
github.com/aws/aws-sdk-go-v2/service/sts v1.29.1 h1:myX5CxqXE0QMZNja6FA1/FSE3Vu1rVmeUmpJMMzeZg0=
github.com/aws/aws-sdk-go-v2/service/sts v1.29.1/go.mod h1:N2mQiucsO0VwK9CYuS4/c2n6Smeh1v47Rz3dWCPFLdE=
-github.com/aws/smithy-go v1.20.2 h1:tbp628ireGtzcHDDmLT/6ADHidqnwgF57XOXZe6tp4Q=
-github.com/aws/smithy-go v1.20.2/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E=
+github.com/aws/smithy-go v1.22.5 h1:P9ATCXPMb2mPjYBgueqJNCA5S9UfktsW0tTxi+a7eqw=
+github.com/aws/smithy-go v1.22.5/go.mod h1:t1ufH5HMublsJYulve2RKmHDC15xu1f26kHCp/HgceI=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas=
diff --git a/variables.tf b/variables.tf
index b93152c..d7045df 100644
--- a/variables.tf
+++ b/variables.tf
@@ -250,3 +250,11 @@ variable "allow_major_version_upgrade" {
default = false
}
+variable "serverless_v2_scaling_configuration" {
+ type = object({
+ min_capacity = optional(number, 0.5)
+ max_capacity = optional(number, 256)
+ })
+ default = null
+ description = "Configuration for serverless v2 scaling. See https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/docdb_cluster#serverless_v2_scaling_configuration"
+}
diff --git a/versions.tf b/versions.tf
index cb86f2c..c0fa4bc 100644
--- a/versions.tf
+++ b/versions.tf
@@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
- version = ">= 5.29.0"
+ version = ">= 6.8.0"
}
local = {
source = "hashicorp/local"