Skip to content

Commit

Permalink
Merge pull request #6 from opzkit/add-enhanced-monitoring-role
Browse files Browse the repository at this point in the history
fix: make enhanced monitoring actually work for new instance
  • Loading branch information
argoyle authored Dec 17, 2021
2 parents 0b30f1c + 822838a commit 76339c5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions iam.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
resource "aws_iam_role" "rds_enhanced_monitoring" {
count = var.enhanced_monitoring ? 1 : 0
name = "${var.identifier}-rds-enhanced-monitoring"
assume_role_policy = data.aws_iam_policy_document.rds_enhanced_monitoring.json
}

resource "aws_iam_role_policy_attachment" "rds_enhanced_monitoring" {
count = var.enhanced_monitoring ? 1 : 0
role = aws_iam_role.rds_enhanced_monitoring[0].name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonRDSEnhancedMonitoringRole"
}

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

effect = "Allow"

principals {
type = "Service"
identifiers = ["monitoring.rds.amazonaws.com"]
}
}
}
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ resource "aws_db_instance" "default" {
username = var.master_username
password = local.password
monitoring_interval = var.enhanced_monitoring ? 60 : 0
monitoring_role_arn = var.enhanced_monitoring ? aws_iam_role.rds_enhanced_monitoring[0].arn : null
maintenance_window = "mon:02:00-mon:03:30"
backup_window = "03:30-05:00"
backup_retention_period = 14
Expand Down

0 comments on commit 76339c5

Please sign in to comment.