Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Monitoring disabled in RDS auto scaling read instance #17674

Open
gmattar opened this issue Feb 18, 2021 · 1 comment
Open

Enhance Monitoring disabled in RDS auto scaling read instance #17674

gmattar opened this issue Feb 18, 2021 · 1 comment
Labels
bug Addresses a defect in current functionality. stale Old or inactive issues managed by automation, if no further action taken these will get closed.

Comments

@gmattar
Copy link

gmattar commented Feb 18, 2021

I created an Aurora Postgres DB and enabled enhance monitoring (EM). It worked well for a single instance dev DB but not for the autoscaling production version. In this case, the write instance gets the EM enabled but the autoscaled write instance don't.
I checked the aws_appautoscaling terraform docs for any missing parameter on my. side but couldn't find (only role_arn but that seems to be another thing).

this is a simplified version of the module

terraform {
  required_version = "= 0.12.28"
}

provider "aws" {
  version = "= 2.70.0"
}

locals {
  rds_enhanced_monitoring_arn  = join("", aws_iam_role.rds_enhanced_monitoring.*.arn)
  rds_enhanced_monitoring_name = join("", aws_iam_role.rds_enhanced_monitoring.*.name)
}

//
// Create the database
//

data "aws_iam_policy_document" "monitoring_rds_assume_role" {
  statement {
    actions = ["sts:AssumeRole"]

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

resource "aws_iam_role" "rds_enhanced_monitoring" {
  name               = "rds-enhanced-monitoring"
  assume_role_policy = data.aws_iam_policy_document.monitoring_rds_assume_role.json
  tags               = local.tags
}

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

resource "aws_rds_cluster" "default" {
  cluster_identifier                  = local.name
  deletion_protection                 = var.deletion_protection
  engine                              = "aurora-postgresql"
  engine_version                      = "11.6"
  storage_encrypted                   = true
  apply_immediately                   = true
  enabled_cloudwatch_logs_exports     = ["postgresql"]

  lifecycle {
    create_before_destroy = true
  }
}

resource "aws_rds_cluster_instance" "default" {
  monitoring_interval          = var.monitoring_interval
  performance_insights_enabled = true
  monitoring_role_arn          = local.rds_enhanced_monitoring_arn
}

resource "aws_appautoscaling_target" "read_replica_count" {
  min_capacity       = var.replica_scale_min
  max_capacity       = var.replica_scale_max
  resource_id        = "cluster:${aws_rds_cluster.default.cluster_identifier}"
  scalable_dimension = "rds:cluster:ReadReplicaCount"
  service_namespace  = "rds"
  role_arn           = local.rds_enhanced_monitoring_arn
}

resource "aws_appautoscaling_policy" "autoscaling_read_replica_count" {
  name               = "target-metric"
  policy_type        = "TargetTrackingScaling"
  resource_id        = "cluster:${aws_rds_cluster.default.cluster_identifier}"
  scalable_dimension = "rds:cluster:ReadReplicaCount"
  service_namespace  = "rds"

  target_tracking_scaling_policy_configuration {
    predefined_metric_specification {
      predefined_metric_type = var.predefined_metric_type
    }

    scale_in_cooldown  = var.replica_scale_in_cooldown
    scale_out_cooldown = var.replica_scale_out_cooldown
    target_value       = var.predefined_metric_type == "RDSReaderAverageCPUUtilization" ? var.replica_scale_cpu : var.replica_scale_connections
  }

  depends_on = [aws_appautoscaling_target.read_replica_count]
}
@ghost ghost added service/applicationautoscaling service/iam Issues and PRs that pertain to the iam service. service/rds Issues and PRs that pertain to the rds service. labels Feb 18, 2021
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Feb 18, 2021
@bill-rich bill-rich added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. service/iam Issues and PRs that pertain to the iam service. service/rds Issues and PRs that pertain to the rds service. labels Feb 19, 2021
Copy link

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!

@github-actions github-actions bot added the stale Old or inactive issues managed by automation, if no further action taken these will get closed. label Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Addresses a defect in current functionality. stale Old or inactive issues managed by automation, if no further action taken these will get closed.
Projects
None yet
Development

No branches or pull requests

3 participants