Skip to content

intel/terraform-intel-aws-aurora-mysql

Intel Logo

Intel® Optimized Cloud Modules for Terraform

© Copyright 2024, Intel Corporation

AWS Aurora MySQL Module

This code creates an Amazon Aurora instance and RDS cluster for MySQL. The instance is created on an Intel Icelake instance R6i.large by default. The instance is pre-configured with parameters within the database parameter group that is optimized for Intel architecture. The goal of this module is to get you started with a database configured to run best on Intel architecture. As you configure your application's environment, choose the configurations for your infrastructure that matches your application's requirements. The MySQL Optimizations were based off Intel Xeon Tuning Guide

AWS Aurora Performance Data

Large R6i instances executed queries faster

AWS MySQL Performance Data - Following Data is Specific to MySQL and the Results May Vary for Aurora Module

Link

Link

Link

Link

Usage

See examples folder for complete examples.

By default, you will only have to pass three variables

db_password
subnet_id
vpc_id

variables.tf

variable "db_password" {
  description = "Password for the master database user."
  type        = string
  sensitive   = true
}

main.tf

module "optimized-aurora-server" {
  source         = "intel/aws-aurora-mysql/intel"
  db_password    = var.db_password
  subnet_id   = "<ENTER YOUR SUBNET ID>"
  vpc_id = "<YOUR-VPC-ID-HERE>"
}

Run terraform

export TF_VAR_db_password ='<USE_A_STRONG_PASSWORD>'

terraform init  
terraform plan
terraform apply

Considerations

  • Check the variables.tf file for incoming ports allowed to connect to the database instance. The variable name is ingress_cidr_blocks. Currently it is defaulted to be open to the world like 0.0.0.0/0. Before runing the code, configure it based on specific security policies and requirements within the environment it is being implemented
  • Check if you getting errors while running this Terraform code due to AWS defined soft limits or hard limits within your AWS account. Please work with your AWS support team to resolve limit constraints
  • Using HashiCorp Modules alongside green-blue deployment allows for a secure and efficient deployment process. The modules can be easily integrated into both the active and inactive environments, ensuring consistency across both environments.
    • Instance - If you apply the instances will shut down immediately and restart, creating service interruption.
    • Platform - If you apply, it will wait for the next maintenance window to change the instance & configuration. You can force apply with additional TF code.

Requirements

Name Version
aws 5.31.0

Providers

Name Version
aws 5.31.0
random n/a

Modules

No modules.

Resources

Name Type
aws_rds_cluster.default resource
aws_rds_cluster_instance.cluster_instances resource
aws_rds_cluster_parameter_group.rds resource
random_id.rid resource

Inputs

Name Description Type Default Required
auto_major_version_upgrades Flag that specifices if major version upgrades are allowed. Changing this parameter does not result in an outage and the change is asynchronously applied as soon as possible. bool false no
auto_minor_version_upgrades Flag that specifies if minor engine upgrades will be applied automatically to the DB instance during the maintenance window. bool true no
availability_zones Name of the Availability Zone the DB instance is located in. list(string) null no
aws_security_group_name security group name for the rds string "mysql_rds" no
backup_retention_period Specifies the number of days for which automatic DB snapshots are retained. number 5 no
cluster_identifier If the DB instance is a member of a DB cluster, contains the name of the DB cluster that the DB instance is a member of. string "aurora-cluster-demo" no
cluster_instance_identifier The identifier of the cluster instances. string "aurora-cluster-instance-demo" no
create_security_group Flag that allows for the creation of a security group that allows access to the instance. Please use this for non-production use cases only. bool false no
create_subnet_group Flag that allows for the creation of a subnet group that allows public access. bool true no
database_name Contains the name of the initial database of this instance that was provided at create time string "mydb" no
db_allocated_storage Allocated storage for AWS database instance. number 200 no
db_apply_immediately Flag that specifies whether any database modifications are applied immediately, or during the next maintenance window. bool false no
db_automated_backup_arn The ARN of the automated backup from which to restore. Required if source_db_instance_identifier or source_dbi_resource_id is not specified. string null no
db_backup_window The daily time range (in UTC) during which automated backups are created if they are enabled. Example: 09:46-10:16. Must not overlap with maintenance_window. string null no
db_ca_cert_identifier The identifier of the CA certificate for the DB instance. string null no
db_cloudwatch_logs_export Set of log types to enable for exporting to CloudWatch logs. If omitted, no logs will be exported. list(string) [] no
db_custom_iam_profile The instance profile associated with the underlying Amazon EC2 instance of an RDS Custom DB instance. string null no
db_deletion_protection Flag that specifies whether the DB instance is protected from deletion. bool false no
db_domain The ID of the Directory Service Active Directory domain to create the instance in. string null no
db_domain_iam_role (Required if db_domain is provided) The name of the IAM role to be used when making API calls to the Directory Service. string null no
db_encryption Flag that specifies whether the DB instance is encrypted. bool true no
db_iam_authentication Flag that specifies whether mappings of AWS Identity and Access Management (IAM) accounts to database accounts is enabled. bool false no
db_iops The amount of provisioned IOPS. Setting this implies a storage_type of io1. number 10000 no
db_maintenance_window The window to perform maintenance in. Syntax: ddd:hh24:mi-ddd:hh24:mi string null no
db_max_allocated_storage When configured, the upper limit to which Amazon RDS can automatically scale the storage of the DB instance. Configuring this will automatically ignore differences to allocated_storage. Must be greater than or equal to allocated_storage or 0 to disable Storage Autoscaling. number 10000 no
db_monitoring_interval The interval, in seconds, between points when Enhanced Monitoring metrics are collected for the DB instance string 0 no
db_monitoring_role_arn The ARN for the IAM role that permits RDS to send enhanced monitoring metrics to CloudWatch Logs string null no
db_option_group Option group name to associate with the database instance. string null no
db_parameter_group_family Family identifier for the RDS database parameter group. string "mysql8.0" no
db_parameter_group_name Name for the RDS database parameter group. string "aurora-mysql" no
db_parameters Intel Cloud optimizations for Xeon processors
object({
aurora-mysql = object({
table_open_cache = optional(object({
value = optional(string, "8000")
apply_method = optional(string, "immediate")
}))
table_open_cache_instances = optional(object({
value = optional(string, "16")
apply_method = optional(string, "pending-reboot")
}))
max_connections = optional(object({
value = optional(string, "4000")
apply_method = optional(string, "immediate")
}))
back_log = optional(object({
value = optional(string, "1500")
apply_method = optional(string, "pending-reboot")
}))

performance_schema = optional(object({
value = optional(string, "0")
apply_method = optional(string, "pending-reboot")
}))
max_prepared_stmt_count = optional(object({
value = optional(string, "128000")
apply_method = optional(string, "immediate")
}))
character_set_server = optional(object({
value = optional(string, "latin1")
apply_method = optional(string, "immediate")
}))
collation_server = optional(object({
value = optional(string, "latin1_swedish_ci")
apply_method = optional(string, "immediate")
}))
transaction_isolation = optional(object({
value = optional(string, "REPEATABLE-READ")
apply_method = optional(string, "immediate")
}))
innodb_log_file_size = optional(object({
value = optional(string, 1024 * 1024 * 1024)
apply_method = optional(string, "pending-reboot")
}))
innodb_open_files = optional(object({
value = optional(string, "4000")
apply_method = optional(string, "pending-reboot")
}))
innodb_file_per_table = optional(object({
value = optional(string, "1")
apply_method = optional(string, "pending-reboot")
}))
innodb_buffer_pool_instances = optional(object({
value = optional(string, "16")
apply_method = optional(string, "pending-reboot")
}))
innodb_buffer_pool_size = optional(object({
value = optional(string, "64424509440") # 60 Gigabytes #Calculator https://convertlive.com/u/convert/gigabytes/to/bytes
apply_method = optional(string, "pending-reboot")
}))
innodb_log_buffer_size = optional(object({
value = optional(string, "67108864")
apply_method = optional(string, "pending-reboot")
}))
innodb_thread_concurrency = optional(object({
value = optional(string, "0")
apply_method = optional(string, "immediate")
}))
join_buffer_size = optional(object({
value = optional(string, 32 * 1024)
apply_method = optional(string, "immediate")
}))
sort_buffer_size = optional(object({
value = optional(string, 32 * 1024)
apply_method = optional(string, "immediate")
}))
innodb_stats_persistent = optional(object({
value = optional(string, "ON")
apply_method = optional(string, "immediate")
}))
innodb_spin_wait_delay = optional(object({
value = optional(string, "6")
apply_method = optional(string, "immediate")
}))
innodb_max_purge_lag_delay = optional(object({
value = optional(string, "300000")
apply_method = optional(string, "immediate")
}))
innodb_max_purge_lag = optional(object({
value = optional(string, "0")
apply_method = optional(string, "immediate")
}))
innodb_lru_scan_depth = optional(object({
value = optional(string, "9000")
apply_method = optional(string, "immediate")
}))
innodb_read_io_threads = optional(object({
value = optional(string, "16")
apply_method = optional(string, "pending-reboot")
}))
innodb_purge_threads = optional(object({
value = optional(string, "4")
apply_method = optional(string, "pending-reboot")
}))
innodb_adaptive_hash_index = optional(object({
value = optional(string, "0")
apply_method = optional(string, "immediate")
}))
/* Cannot be Modified (AWS doesnt allow to modify this parameter)
innodb_flush_log_at_trx_commit = optional(object({
value = optional(string, "0")
apply_method = optional(string, "immediate")
}))*/
})
})
{
"aurora-mysql": {
"back_log": {},
"character_set_server": {},
"collation_server": {},
"default_password_lifetime": {},
"innodb_adaptive_flushing": {},
"innodb_adaptive_hash_index": {},
"innodb_buffer_pool_instances": {},
"innodb_buffer_pool_size": {},
"innodb_change_buffering": {},
"innodb_checksum_algorithm": {},
"innodb_file_per_table": {},
"innodb_flush_neighbors": {},
"innodb_io_capacity": {},
"innodb_io_capacity_max": {},
"innodb_log_buffer_size": {},
"innodb_log_file_size": {},
"innodb_lru_scan_depth": {},
"innodb_max_dirty_pages_pct": {},
"innodb_max_dirty_pages_pct_lwm": {},
"innodb_max_purge_lag": {},
"innodb_max_purge_lag_delay": {},
"innodb_open_files": {},
"innodb_page_cleaners": {},
"innodb_purge_threads": {},
"innodb_read_io_threads": {},
"innodb_spin_wait_delay": {},
"innodb_stats_persistent": {},
"innodb_thread_concurrency": {},
"innodb_undo_log_truncate": {},
"innodb_use_native_aio": {},
"innodb_write_io_threads": {},
"join_buffer_size": {},
"max_connections": {},
"max_prepared_stmt_count": {},
"performance_schema": {},
"sort_buffer_size": {},
"table_open_cache": {},
"table_open_cache_instances": {},
"transaction_isolation": {}
}
}
no
db_password Password for the master database user. string n/a yes
db_performance_insights Flag that specifies whether Performance Insights are enabled. bool false no
db_performance_retention_period Amount of time in days to retain Performance Insights data.Valid values are 7, 731 (2 years) or a multiple of 31. string null no
db_port The port on which the DB accepts connections. number null no
db_publicly_accessible Flag to indicate whether the database will be publicly accessible. bool false no
db_replicate_source_db Specifies that this resource is a Replicate database, and to use this value as the source database. This correlates to the identifier of another Amazon RDS Database to replicate (if replicating within a single region) or ARN of the Amazon RDS Database to replicate (if replicating cross-region). Note that if you are creating a cross-region replica of an encrypted database you will also need to specify a kms_key_id. string null no
db_restore_time The date and time to restore from. Value must be a time in Universal Coordinated Time (UTC) format and must be before the latest restorable time for the DB instance. string null no
db_snapshot_identifier Specifies whether or not to create this database from a snapshot. This correlates to the snapshot ID you'd find in the RDS console. string null no
db_source_db_instance_id The identifier of the source DB instance from which to restore. Must match the identifier of an existing DB instance. Required if source_db_instance_automated_backups_arn or source_dbi_resource_id is not specified. string null no
db_source_dbi_resource_id The resource ID of the source DB instance from which to restore. Required if source_db_instance_identifier or source_db_instance_automated_backups_arn is not specified. string null no
db_storage_type The storage type that will be set on the instance. If db_iops is set then this will be set to io1 string "io1" no
db_subnet_group_name Database subnet group name. string null no
db_subnet_group_tag Tag for the database subnet group. map(string)
{
"Name": "mysql"
}
no
db_timeouts Map of timeouts that can be adjusted when executing the module. This allows you to customize how long certain operations are allowed to take before being considered to have failed.
object({
create = optional(string, null)
delete = optional(string, null)
update = optional(string, null)
})
{
"db_timeouts": {}
}
no
db_use_latest_restore_time Flag that indicates whether the DB instance is restored from the latest backup time. bool null no
egress_cidr_blocks Egress CIDR block for the RDS security group. list(string)
[
"0.0.0.0/0"
]
no
egress_from_port Starting egress port for the RDS security group. number 3306 no
egress_protocol Egress protocol for the port defined in the RDS security group. string "tcp" no
egress_to_port Ending egress port for the RDS security group. number 3306 no
engine Database engine version for AWS database instance. string "aurora-mysql" no
engine_version Database engine version for AWS database instance. string "5.7.mysql_aurora.2.11.2" no
family The family of the DB cluster parameter group. string "aurora5.6" no
final_snapshot_prefix The name which is prefixed to the final snapshot on database termination. string "mysql-snap-" no
ingress_cidr_blocks Ingress CIDR block for the RDS security group. list(string)
[
"0.0.0.0/0"
]
no
ingress_from_port Starting ingress port for the RDS security group. number 3306 no
ingress_protocol Ingress protocol for the port defined in the RDS security group. string "tcp" no
ingress_to_port Ending ingress port for the RDS security group. number 3306 no
instance_class The compute and memory capacity of each DB instance in the Multi-AZ DB cluster, for example db.m6g.xlarge. Not all DB instance classes are available in all AWS Regions, or for all database engines string "db.r6i.large" no
kms_key_id The ARN for the KMS encryption key. If creating an encrypted replica, set this to the destination KMS ARN. string null no
master_username Contains the master username for the DB instance. string "foo" no
multi_az Flag that specifies if the RDS instance is multi_az. bool true no
name The name of the DB cluster parameter group. string "rds-cluster-pg" no
preferred_backup_window Specifies the daily time range during which automated backups are created. string "07:00-09:00" no
rds_security_group_tag Map of tags for the RDS security group. map(string)
{
"Name": "mysql_rds"
}
no
security_group_ids List of existing AWS security groups that will be attached to the RDS instance. list(string) null no
skip_final_snapshot Flag to indicate whether a final snapshot will be skipped upon database termination. bool true no
subnet_id The ID of the subnet where the EC2 instance will be launched. string n/a yes
tags A mapping of tags to assign to all resources. map(string) {} no
vpc_id VPC ID within which the database resource will be created. string n/a yes

Outputs

Name Description
availability_zones Name of the Availability Zone the DB instance is located in.
backup_retention_period Specifies the number of days for which automatic DB snapshots are retained.
cluster_identifier Identifier of the aws_rds_cluster in which to launch this instance.
cluster_identifier1 Identifier of the aws_rds_cluster in which to launch this instance.
cluster_identifier_default If the DB instance is a member of a DB cluster, contains the name of the DB cluster that the DB instance is a member of.
count To make multiple instances and join them all to the same RDS Cluster.
database_name Contains the name of the initial database of this instance that was provided at create time.
db_allocated_storage Storage that was allocated to the instance when it configured.
db_arn ARN of the database instance.
db_endpoint Connection endpoint for the database instance that has been created.
db_engine The database engine used by the RDS cluster.
db_instance_id The identifier of the RDS cluster instance.
db_kms_key_id KMS key that is configured on the database instance if storage encryption is enabled.
db_name Name of the database that was created (if specified) during instance creation.
db_port The port on which the RDS cluster is accessible.
dbi_resource_id Region-unique, immutable identifier for the DB instance.
dbi_resource_id1 Region-unique, immutable identifier for the DB instance.
engine Database engine version for AWS database instance.
engine_default Default engine to use.
engine_version Database engine version for AWS database instance.
engine_version_default Default engine version to use.
family The family of the DB cluster parameter group.
identifier Identifier for the RDS instance, if omitted, Terraform will assign a random, unique identifier.
identifier1 Identifier for the RDS instance, if omitted, Terraform will assign a random, unique identifier.
instance_class The compute and memory capacity of each DB instance in the Multi-AZ DB cluster, for example db.m6g.xlarge. Not all DB instance classes are available in all AWS Regions, or for all database engines.
kms_key_id The ARN for the KMS encryption key. If creating an encrypted replica, set this to the destination KMS ARN.
name The name of the DB cluster parameter group.
preferred_backup_window Specifies the daily time range during which automated backups are created.
skip_final_snapshot Flag to indicate whether a final snapshot will be skipped upon database termination.