Skip to main content
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 second 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

The engine_version, family, and major_engine_version values must be consistent with each other:

Parameter group settings

The example sets character_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 = true with monitoring_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

After terraform apply, the following outputs are available:

Parameter groups

Configure database engine parameters for tuning MySQL behavior.

Option groups

Add optional engine features such as MARIADB_AUDIT_PLUGIN to MySQL instances.