Skip to content

Commit

Permalink
added vars, locals and changed argument for cloudwatch logging (#5)
Browse files Browse the repository at this point in the history
Co-authored-by: Garegin <[email protected]>
  • Loading branch information
garegintamrazyan07 and gareginatprovectus authored Sep 10, 2021
1 parent ac40d17 commit 87fd190
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
33 changes: 32 additions & 1 deletion rds/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,37 @@ data "aws_subnet_ids" "all" {
vpc_id = var.vpc_id
}

locals {
db_engine_log_group_mapping = var.rds_cloudwatch_logging_enabled ? {
postgres = ["postgres", "upgrade"]
mariadb = ["audit", "general", "slowquery", "error"]
oracle-ee = ["audit", "alert", "trace", "listener"]
oracle-ee-cdb = ["audit", "alert", "trace", "listener"]
oracle-se2 = ["audit", "alert", "trace", "listener"]
oracle-se2-cdb = ["audit", "alert", "trace", "listener"]
mysql = ["audit", "general", "slowquery", "error"]
sqlserver-ee = ["error", "agent"]
sqlserver-se = ["error", "agent"]
sqlserver-ex = ["error", "agent"]
sqlserver-web = ["error", "agent"]


} : {
postgres = []
mariadb = []
oracle-ee = []
oracle-ee-cdb = []
oracle-se2 = []
oracle-se2-cdb = []
mysql = []
sqlserver-ee = []
sqlserver-se = []
sqlserver-ex = []
sqlserver-web = []

}
}

resource "aws_security_group" "eks_workers" {
name = "${var.cluster_name}-rds-access-from-eks"
description = "Allow EKS workers access to RDS databases"
Expand Down Expand Up @@ -77,7 +108,7 @@ module "db" {
},
)

enabled_cloudwatch_logs_exports = var.rds_enabled_cloudwatch_logs_exports
enabled_cloudwatch_logs_exports = (length(var.rds_enabled_cloudwatch_logs_exports) != 0 && var.rds_cloudwatch_logging_enabled) ? var.rds_enabled_cloudwatch_logs_exports : lookup(local.db_engine_log_group_mapping, var.rds_database_engine, [])

# DB subnet group
subnet_ids = var.subnets
Expand Down
5 changes: 5 additions & 0 deletions rds/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,8 @@ variable "worker_security_group_id" {

}

variable "rds_cloudwatch_logging_enabled" {
description = "Enable cloudwatch logs"
type = bool
default = false
}

0 comments on commit 87fd190

Please sign in to comment.