Skip to main content
The module exposes three independent monitoring layers: Enhanced Monitoring (OS-level metrics via CloudWatch), Performance Insights (query-level diagnostics), and Database Insights (AI-assisted analysis). CloudWatch log exports capture engine-specific log streams for long-term retention and alerting.
Enhanced Monitoring collects operating-system metrics (CPU, memory, I/O, network) from an agent running on the DB host. Metrics are published to CloudWatch Logs every monitoring_interval seconds.

Variables

VariableDefaultDescription
monitoring_interval0Seconds between metric collection. 0 disables Enhanced Monitoring. Valid values: 0, 1, 5, 10, 15, 30, 60.
create_monitoring_rolefalseCreate the IAM role required to publish metrics to CloudWatch.
monitoring_role_arnnullARN of an existing IAM role to use. Provide this when create_monitoring_role = false and monitoring_interval > 0.
monitoring_role_name"rds-monitoring-role"Name of the IAM role to create when create_monitoring_role = true.
monitoring_role_use_name_prefixfalseWhen true, use monitoring_role_name as a prefix.
monitoring_role_descriptionnullDescription of the monitoring IAM role.
monitoring_role_permissions_boundarynullARN of the IAM permissions boundary to attach to the monitoring role.

Let the module create the IAM role

module "db" {
  source = "terraform-aws-modules/rds/aws"

  identifier = "enhanced-monitoring"

  engine               = "mysql"
  engine_version       = "8.0"
  family               = "mysql8.0"
  major_engine_version = "8.0"
  instance_class       = "db.t4g.large"

  allocated_storage     = 20
  max_allocated_storage = 100

  db_name  = "completeMysql"
  username = "complete_mysql"
  port     = 3306

  multi_az               = true
  db_subnet_group_name   = module.vpc.database_subnet_group
  vpc_security_group_ids = [module.security_group.security_group_id]

  maintenance_window              = "Mon:00:00-Mon:03:00"
  backup_window                   = "03:00-06:00"
  enabled_cloudwatch_logs_exports = ["audit", "general"]

  backup_retention_period = 0
  skip_final_snapshot     = true
  deletion_protection     = false

  # Enhanced Monitoring
  monitoring_interval    = 30
  create_monitoring_role = true

  # Also enable Performance Insights
  performance_insights_enabled          = true
  performance_insights_retention_period = 7

  tags = local.tags
}

Bring your own IAM role

The enhanced-monitoring example shows how to create the role manually and pass its ARN. When using an externally managed role, set create_monitoring_role = false (the default) and provide monitoring_role_arn:
data "aws_iam_policy_document" "rds_enhanced_monitoring" {
  statement {
    actions = ["sts:AssumeRole"]
    effect  = "Allow"

    principals {
      type        = "Service"
      identifiers = ["monitoring.rds.amazonaws.com"]
    }
  }
}

resource "aws_iam_role" "rds_enhanced_monitoring" {
  name_prefix        = "rds-enhanced-monitoring-"
  assume_role_policy = data.aws_iam_policy_document.rds_enhanced_monitoring.json
}

resource "aws_iam_role_policy_attachment" "rds_enhanced_monitoring" {
  role       = aws_iam_role.rds_enhanced_monitoring.name
  policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonRDSEnhancedMonitoringRole"
}

module "db" {
  source = "terraform-aws-modules/rds/aws"

  identifier = "enhanced-monitoring"

  # ... engine, storage, etc.

  # Enhanced Monitoring using an externally managed role
  # create_monitoring_role = false (default) — do not create a role
  monitoring_interval = 30
  monitoring_role_arn = aws_iam_role.rds_enhanced_monitoring.arn

  tags = local.tags
}

PostgreSQL with named role and prefix

The complete-postgres example demonstrates using a name prefix for the role:
module "db" {
  source = "terraform-aws-modules/rds/aws"

  # ...

  create_monitoring_role          = true
  monitoring_interval             = 60
  monitoring_role_name            = "example-monitoring-role-name"
  monitoring_role_use_name_prefix = true
  monitoring_role_description     = "Description for monitoring role"

  # ...
}

Build docs developers (and LLMs) love