This example provisions a production-ready MySQL 8.0 RDS instance along with all supporting resources: VPC, security groups, parameter group, option group, CloudWatch log groups, and an enhanced monitoring IAM role. A secondDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/terraform-aws-modules/terraform-aws-rds/llms.txt
Use this file to discover all available pages before exploring further.
db_default instance is also shown using AWS-managed default parameter and option groups.
Use
"8.0" (not "8.0.x") for engine_version. AWS resolves the minor version automatically and manages patch upgrades. Specifying a full patch version such as "8.0.32" can cause Terraform to detect drift after AWS applies a patch.Configuration
main.tf
Key configuration choices
Engine version and parameter group family
Theengine_version, family, and major_engine_version values must be consistent with each other:
| Variable | Value | Purpose |
|---|---|---|
engine_version | "8.0" | The MySQL version to deploy |
family | "mysql8.0" | The parameter group family |
major_engine_version | "8.0" | The option group major version |
Parameter group settings
The example setscharacter_set_client and character_set_server to utf8mb4, which is the recommended encoding for MySQL deployments that need full Unicode support (including emoji and supplementary characters). The utf8 alias in MySQL only supports the BMP subset; utf8mb4 is the correct choice for modern applications.
Storage autoscaling
max_allocated_storage = 100 enables storage autoscaling. RDS will automatically increase allocated storage up to 100 GiB when utilization exceeds 10% of the current allocation. Set this to 0 to disable autoscaling.
Performance Insights and enhanced monitoring
The example enables both:performance_insights_enabled = true— collects query-level metrics, retained for 7 days (free tier)create_monitoring_role = truewithmonitoring_interval = 60— creates an IAM role and collects OS-level metrics every 60 seconds
Default instance variant
module.db_default demonstrates using AWS-managed default groups by setting create_db_option_group = false and create_db_parameter_group = false. This is useful for development environments where custom parameter tuning is not required.
Disabled instance variant
module.db_disabled shows how to use create_db_instance = false to prevent resource creation while still defining the module block. This pattern is useful for feature flags or staged rollouts.
Outputs
Afterterraform apply, the following outputs are available:
| Output | Description |
|---|---|
db_instance_address | DNS hostname of the RDS instance |
db_instance_endpoint | Full connection endpoint including port |
db_instance_identifier | The RDS instance identifier |
db_instance_engine_version_actual | The actual engine version running (resolved minor version) |
db_instance_port | Database port (3306) |
db_instance_name | The database name |
db_instance_username | Master username (sensitive) |
db_instance_master_user_secret_arn | ARN of the Secrets Manager secret for the master password |
db_parameter_group_id | The parameter group name |
db_parameter_group_arn | ARN of the parameter group |
db_enhanced_monitoring_iam_role_arn | ARN of the enhanced monitoring IAM role |
db_instance_cloudwatch_log_groups | Map of created CloudWatch log group names and ARNs |
Related guides
Parameter groups
Configure database engine parameters for tuning MySQL behavior.
Option groups
Add optional engine features such as MARIADB_AUDIT_PLUGIN to MySQL instances.