Use this module for any RDS that is not Aurora. Use the rds_cluster for Aurora instances.
Known issues:
If you receive:
╷ │ Error: Creating CloudWatch Log Group failed: ResourceAlreadyExistsException: The specified log group already exists: The CloudWatch Log Group '/aws/rds/instance/website-stack-20220819105124303000000001/error' already exists. │ │ with module.website_stack.module.website_database.aws_cloudwatch_log_group.log_exports["error"], │ on ../../modules/rds_instance/cloudwatch_logs_exports.tf line 1, in resource "aws_cloudwatch_log_group" "log_exports": │ 1: resource "aws_cloudwatch_log_group" "log_exports" { │ ╵
Upon initial creation then import the resource or delete it and rerun the TerraForm module. The reason this happens is because we want to control automically created CloudWatch log groups. This happens in more places in AWS unfortunately.
This Terraform command uses the coalesce function, which is commonly used to set default values or to check values for null or zero.
max_allocated_storage = coalesce(
var.max_allocated_storage != null ? (
var.max_allocated_storage != 0 ? var.max_allocated_storage : null
) : null,
var.max_allocated_storage
)
Explanation:
-
coalesce is a Terraform function that selects one of the given values, starting from left to right, and returns the first non-null value. If all values are null, it returns null.
-
var.max_allocated_storage != null ? ... : null checks if the variable max_allocated_storage is not null. If it's not null, it proceeds to check if it's not equal to 0. If it's not null and not equal to 0, it uses the value of max_allocated_storage. Otherwise, it returns null.
-
If var.max_allocated_storage != null ? ... : null returns null (because var.max_allocated_storage is null), then the default value of null is re-evaluated in the coalesce function, and then the value of var.max_allocated_storage is used.
Name | Version |
---|---|
aws | >=4.8.0 |
random | >=3.1.2 |
Name | Source | Version |
---|---|---|
iam_role | git@github.com:wearetechnative/terraform-aws-iam-role.git | v1.0.0 |
Name | Type |
---|---|
aws_cloudwatch_log_group.log_exports | resource |
aws_db_instance.replica | resource |
aws_db_instance.this | resource |
aws_db_option_group.this | resource |
aws_db_parameter_group.this | resource |
aws_db_subnet_group.this | resource |
random_password.login_suffix | resource |
random_password.password | resource |
aws_caller_identity.current | data source |
Name | Description | Type | Default | Required |
---|---|---|---|---|
additional_tags | Additional tags to be added to resources. | map(string) |
{} |
no |
allocated_storage | Set the amount of storage to be used by RDS. | number |
20 |
no |
auto_minor_version_upgrade | Allow minor updates during maintenance window. | bool |
true |
no |
az | specify availability zone for instance if preferred | string |
null |
no |
az_replica | specify availability zone for replica instance if preferred | string |
null |
no |
backup_retention_period | number of days to retain backups | number |
35 |
no |
backup_window | Add a window in the folling format: 03:00-04:00 | string |
"03:00-04:00" |
no |
db_name | Name of the database to create when the DB instance is created. | string |
null |
no |
deletion_protection | protect the instance from deletion | bool |
false |
no |
enable_aws_backup_tag | To enable aws backup service tag to RDS instance. | bool |
false |
no |
enable_aws_backup_tag_replica | To enable aws backup service tag to RDS replica instance. | bool |
false |
no |
enabled_cloudwatch_logs_exports | Enabled CloudWatch log exports. | list(string) |
[ |
no |
engine | RDS database engine to use. | string |
"mariadb" |
no |
engine_family | RDS database parameter group family. | string |
"mariadb10.5" |
no |
engine_major_version | RDS database engine version to use for option group. | string |
"10.5" |
no |
engine_version | RDS database engine version to use. | string |
"10.5.12" |
no |
instance_class | Instance class to be used for database instance. | string |
"db.t3.medium" |
no |
kms_key_arn | KMS key to use for encrypting RDS instances. | string |
n/a | yes |
maintenance_window | maintenance window for rds instance updates | string |
"Sun:02:00-Sun:03:00" |
no |
max_allocated_storage | Set the maximum storage to be used by RDS. | number |
20 |
no |
multi_az | Use 2 AZs for high availability. | bool |
true |
no |
name | Unique name for RDS instance. | string |
n/a | yes |
parameter_group_overrides | Optional map of user defined parameters. The map key is the parameter name. The map contains value and apply_method as attributes. | map(object({ |
{} |
no |
password | Set a password for username. If set to null, a random password will be created | string |
null |
no |
performance_insights_enabled | performance insights | bool |
false |
no |
performance_insights_retention_period | Retention period of performance insights data | number |
31 |
no |
replica | create a read replica or not | bool |
false |
no |
security_group_ids | Provide at least one security group to be associated with this instance. | list(string) |
n/a | yes |
storage_io1_iops | Overrides storage_type to io1 if set and defines the provisioned iops required. | number |
null |
no |
storage_type | Storage type to be used for instances. | string |
"gp2" |
no |
subnet_ids | Required list of subnets to launch instances in. | list(string) |
n/a | yes |
username | Set a username for database. If set to null, a random username will be created | string |
null |
no |
Name | Description |
---|---|
db_dns_address | n/a |
db_name | n/a |
db_port | n/a |
domain | n/a |
instance_arn | n/a |
master_db_user_name | n/a |
master_db_user_password | n/a |