Skip to content

Commit

Permalink
refactor aws-rds-cluster modules
Browse files Browse the repository at this point in the history
  • Loading branch information
mattJsonar committed Aug 22, 2024
1 parent 5f56de1 commit 59ff760
Show file tree
Hide file tree
Showing 18 changed files with 378 additions and 368 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.0.5 (TBD)

### Features
- Refactored Amazon RDS Aurora (MySQL and PostgreSQL) module variables

## 1.0.4 (2024-07-25)

### Features
Expand Down
7 changes: 3 additions & 4 deletions examples/onboard-aws-rds-aurora-mysql-kinesis/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ module "aws-aurora-mysql-kinesis" {
aws_kinesis_region = local.aws_region

cluster_apply_immediately = local.apply_immediately
cluster_db_master_password = local.master_password
cluster_db_master_username = local.master_user
cluster_id = "tf-aurora-mysql-kinesis-cluster"
cluster_final_snapshot = true
cluster_master_password = local.master_password
cluster_master_username = local.master_user
cluster_identifier = "tf-aurora-mysql-kinesis-cluster"

instance_apply_immediately = local.apply_immediately
instance_identifier = "tf-aurora-mysql-kinesis-instance"
Expand Down
6 changes: 3 additions & 3 deletions examples/onboard-aws-rds-aurora-mysql-slowquery/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ module "aws-aurora-mysql-slowquery" {
}
]

cluster_cluster_id = "aurora-mysql-cluster"
cluster_db_master_username = "admin"
cluster_db_master_password = "mypassword"
cluster_identifier = "aurora-mysql-cluster"
cluster_master_username = "admin"
cluster_master_password = "mypassword"
cluster_db_subnet_group_name = local.subnet_group_name
cluster_vpc_security_group_ids = local.vpc_security_group_ids

Expand Down
6 changes: 3 additions & 3 deletions examples/onboard-aws-rds-aurora-mysql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ module "aws-aurora-mysql" {

cluster_parameter_group_name = "aurora-mysql-cpg-tf"

cluster_cluster_id = "aurora-mysql-cluster"
cluster_db_master_username = "admin"
cluster_db_master_password = "mypassword"
cluster_identifier = "aurora-mysql-cluster"
cluster_master_username = "admin"
cluster_master_password = "mypassword"
cluster_db_subnet_group_name = local.subnet_group_name
cluster_vpc_security_group_ids = local.vpc_security_group_ids

Expand Down
20 changes: 10 additions & 10 deletions examples/onboard-aws-rds-aurora-postgresql-kinesis/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ module "aws-aurora-postgresql-kinesis-1" {
aws_kinesis_gateway_id = local.gateway_id
aws_kinesis_region = local.aws_region

cluster_apply_immediately = true
cluster_db_engine_version = "16"
cluster_db_master_password = local.master_password
cluster_db_master_username = local.master_user
cluster_id = "tf-aurora-postgresql-kinesis-cluster"
cluster_apply_immediately = true
cluster_engine_version = "16"
cluster_identifier = "tf-aurora-postgresql-kinesis-cluster"
cluster_master_password = local.master_password
cluster_master_username = local.master_user

instance_apply_immediately = true
instance_class = "db.r5.large"
Expand All @@ -93,11 +93,11 @@ module "aws-aurora-postgresql-kinesis-2" {
aws_kinesis_gateway_id = local.gateway_id
aws_kinesis_region = local.aws_region

cluster_apply_immediately = true
cluster_db_engine_version = "16"
cluster_db_master_password = local.master_password
cluster_db_master_username = local.master_user
cluster_id = "tf-aurora-postgresql-kinesis-cluster"
cluster_apply_immediately = true
cluster_engine_version = "16"
cluster_identifier = "tf-aurora-postgresql-kinesis-cluster"
cluster_master_password = local.master_password
cluster_master_username = local.master_user

instance_apply_immediately = true
instance_class = "db.r5.large"
Expand Down
18 changes: 8 additions & 10 deletions examples/onboard-aws-rds-aurora-postgresql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,11 @@ module "aurora-postgresql-1" {
aws_log_group_gateway_id = local.gateway_id
aws_log_group_region = local.aws_region

cluster_db_engine_version = "16.1"
cluster_db_master_password = local.master_password
cluster_db_master_username = local.master_user
cluster_db_subnet_group_name = local.subnet_group_name
cluster_final_snapshot = true
cluster_id = "tf-aurora-postgresql-cluster"
cluster_engine_version = "16.1"
cluster_identifier = "tf-aurora-postgresql-cluster"
cluster_master_password = local.master_password
cluster_master_username = local.master_user
cluster_parameter_group_name = "tf-aurora-postgresql-instance-pg"
cluster_vpc_security_group_ids = local.vpc_security_groups

Expand All @@ -118,12 +117,11 @@ module "aurora-postgresql-2" {
aws_log_group_gateway_id = local.gateway_id
aws_log_group_region = local.aws_region

cluster_db_engine_version = "16.1"
cluster_db_master_password = local.master_password
cluster_db_master_username = local.master_user
cluster_db_subnet_group_name = local.subnet_group_name
cluster_final_snapshot = true
cluster_id = "tf-aurora-postgresql-cluster"
cluster_engine_version = "16.1"
cluster_identifier = "tf-aurora-postgresql-cluster"
cluster_master_password = local.master_password
cluster_master_username = local.master_user
cluster_parameter_group_name = "tf-aurora-postgresql-instance-pg"
cluster_vpc_security_group_ids = local.vpc_security_groups

Expand Down
22 changes: 11 additions & 11 deletions modules/aws-rds-cluster/main.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
resource "aws_rds_cluster" "this" {
apply_immediately = var.apply_immediately
backup_retention_period = var.backup_retention
cluster_identifier = var.cluster_id
enabled_cloudwatch_logs_exports = var.db_enabled_cloudwatch_logs_exports
engine = var.db_engine
engine_version = var.db_engine_version
master_password = var.db_master_password
master_username = var.db_master_username
port = var.db_port
backup_retention_period = var.backup_retention_period
cluster_identifier = var.cluster_identifier
db_cluster_parameter_group_name = var.db_cluster_parameter_group_name
db_subnet_group_name = var.db_subnet_group_name
skip_final_snapshot = var.final_snapshot
preferred_maintenance_window = var.maintenance_schedule
db_cluster_parameter_group_name = var.parameter_group_name
enabled_cloudwatch_logs_exports = var.enabled_cloudwatch_logs_exports
engine = var.engine
engine_version = var.engine_version
master_password = var.master_password
master_username = var.master_username
network_type = var.network_type
port = var.port
preferred_maintenance_window = var.preferred_maintenance_window
skip_final_snapshot = var.skip_final_snapshot
vpc_security_group_ids = var.vpc_security_group_ids
}
69 changes: 35 additions & 34 deletions modules/aws-rds-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,82 +4,83 @@ variable "apply_immediately" {
default = null
}

variable "backup_retention" {
variable "backup_retention_period" {
description = "Days to retain backups for, Default is 1 day."
type = number
default = null
}

variable "cluster_id" {
description = "The name of the RDS cluster"
variable "cluster_identifier" {
description = "The cluster identifier."
type = string
}

variable "db_enabled_cloudwatch_logs_exports" {
description = "Set of log types to enable for exporting to CloudWatch logs. Valid values: audit, error, general, slowquery."
type = list(any)
variable "db_cluster_parameter_group_name" {
description = "A cluster parameter group to associate with the cluster."
type = string
default = null
}

variable "db_engine" {
description = "Cluster engine e.g., aurora-mysql"
variable "db_subnet_group_name" {
description = "DB subnet group to associate with this DB cluster. DB instance will be created in the VPC associated with the DB subnet group. If unspecified, will be created in the default VPC, or in EC2 Classic, if available."
type = string
default = null
}
variable "db_engine_version" {
description = "Database engine version, e.g., 8.0.mysql_aurora.3.05.1"
type = string

variable "enabled_cloudwatch_logs_exports" {
description = "Set of log types to export to cloudwatch. If omitted, no logs will be exported. The following log types are supported: audit, error, general, slowquery, postgresql (PostgreSQL)."
type = list(string)
default = null
}

variable "db_master_password" {
description = "Password for the master DB user. Note that this may show up in logs, and it will be stored in the state file. Cannot be set if manage_master_user_password is set to true"
variable "engine" {
description = "Name of the database engine to be used for this DB cluster. Valid Values: aurora-mysql, aurora-postgresql, mysql, postgres. (Note that mysql and postgres are Multi-AZ RDS clusters)."
type = string
default = null
}

variable "db_master_username" {
description = "Username for the master DB user, must not use rdsadmin as that is reserved."
variable "engine_version" {
description = "Database engine version, e.g., 8.0.mysql_aurora.3.05.1"
type = string
default = null
}

variable "db_port" {
description = "Port on which the DB accepts connections."
type = number
default = null
variable "master_password" {
description = "Password for the master DB user. Note that this may show up in logs, and it will be stored in the state file."
type = string
}

variable "db_subnet_group_name" {
description = "Name of DB subnet group. DB instance will be created in the VPC associated with the DB subnet group. If unspecified, will be created in the default VPC, or in EC2 Classic, if available."
variable "master_username" {
description = "Username for the master DB user, must not use rdsadmin as that is reserved."
type = string
default = null
}

variable "final_snapshot" {
description = "Determines whether a final DB snapshot is created before the DB cluster is deleted. If true is specified, no DB snapshot is created. If false is specified, a DB snapshot is created before the DB cluster is deleted, using the value from final_snapshot_identifier. Default is false"
type = bool
variable "network_type" {
description = " Network type of the cluster. Valid values: IPV4, DUAL"
type = string
default = null
}

variable "maintenance_schedule" {
description = "Weekly time range during which system maintenance can occur, in (UTC)."
type = string
variable "port" {
description = "Port on which the DB accepts connections."
type = number
default = null
}

variable "network_type" {
description = " Network type of the cluster. Valid values: IPV4, DUAL"
variable "preferred_maintenance_window" {
description = "Weekly time range during which system maintenance can occur, in (UTC) e.g., wed:04:00-wed:04:30."
type = string
default = null
}

variable "parameter_group_name" {
description = "Cluster parameter group associated with the cluster"
type = string
variable "skip_final_snapshot" {
description = "Determines whether a final DB snapshot is created before the DB cluster is deleted. If true is specified, no DB snapshot is created. If false is specified, a DB snapshot is created before the DB cluster is deleted, using the value from final_snapshot_identifier. Default is false"
type = bool
default = null
}

variable "vpc_security_group_ids" {
description = "List of VPC security groups to associate."
description = "List of VPC security groups to associate with the cluster."
type = list(any)
default = null
}
30 changes: 15 additions & 15 deletions modules/onboard-aws-rds-aurora-mysql-kinesis/main.tf
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
module "aurora-mysql-cluster" {
source = "../aws-rds-cluster"

apply_immediately = var.cluster_apply_immediately
backup_retention = var.cluster_backup_retention
cluster_id = var.cluster_id
db_enabled_cloudwatch_logs_exports = var.cluster_db_enabled_cloudwatch_logs_exports
db_engine = "aurora-mysql"
db_engine_version = var.cluster_db_engine_version
db_master_password = var.cluster_db_master_password
db_master_username = var.cluster_db_master_username
db_port = var.cluster_db_port
db_subnet_group_name = var.cluster_db_subnet_group_name
final_snapshot = var.cluster_final_snapshot
maintenance_schedule = var.cluster_maintenance_schedule
network_type = var.cluster_network_type
parameter_group_name = var.cluster_parameter_group_name
vpc_security_group_ids = var.cluster_vpc_security_group_ids
apply_immediately = var.cluster_apply_immediately
backup_retention_period = var.cluster_backup_retention_period
cluster_identifier = var.cluster_identifier
db_cluster_parameter_group_name = var.cluster_parameter_group_name
db_subnet_group_name = var.cluster_db_subnet_group_name
enabled_cloudwatch_logs_exports = var.cluster_enabled_cloudwatch_logs_exports
engine = "aurora-mysql"
engine_version = var.cluster_engine_version
master_password = var.cluster_master_password
master_username = var.cluster_master_username
network_type = var.cluster_network_type
port = var.cluster_port
preferred_maintenance_window = var.cluster_preferred_maintenance_window
skip_final_snapshot = var.cluster_skip_final_snapshot
vpc_security_group_ids = var.cluster_vpc_security_group_ids
}

module "aurora-mysql-instance" {
Expand Down
Loading

0 comments on commit 59ff760

Please sign in to comment.