Skip to content

avidhara/terraform-aws-rds

Repository files navigation

Terraform module for AWS RDS

Check the examples folder

Requirements

Name Version
terraform >= 1.3.2
aws >= 5.40

Providers

Name Version
aws >= 5.40

Modules

No modules.

Resources

Name Type
aws_db_instance.this resource
aws_db_option_group.this resource
aws_db_parameter_group.this resource
aws_db_subnet_group.this resource

Inputs

Name Description Type Default Required
allocated_storage (Required unless a snapshot_identifier or replicate_source_db is provided) The allocated storage in gibibytes. If max_allocated_storage is configured, this argument represents the initial storage allocation and differences from the configuration will be ignored automatically when Storage Autoscaling occurs. number n/a yes
allow_major_version_upgrade (Optional) Indicates that 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
apply_immediately Optional) Specifies whether any database modifications are applied immediately, or during the next maintenance window. Default is false. bool false no
auto_minor_version_upgrade (Optional) Indicates that minor engine upgrades will be applied automatically to the DB instance during the maintenance window. Defaults to true. bool true no
availability_zone (Optional) The AZ for the RDS instance. string null no
backup_retention_period (Optional) The days to retain backups for. Must be between 0 and 35. Must be greater than 0 if the database is used as a source for a Read Replica. number 35 no
backup_target (Optional, Forces new resource) Specifies where automated backups and manual snapshots are stored. Possible values are region (default) and outposts string "region" no
backup_window (Optional) 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 "03:00-06:00" no
ca_cert_identifier (Optional) The identifier of the CA certificate for the DB instance. string null no
character_set_name (Optional) The character set name to use for DB encoding in Oracle and Microsoft SQL instances (collation). This can't be changed. string null no
copy_tags_to_snapshot (Optional, boolean) Copy all Instance tags to snapshots. Default is false. bool false no
create (Optional) Do you want to create DB resoruces bool true no
create_db_subnet_group_name Do you want to create DB subnet Group bool true no
create_option_group_name (Optional) Do you want to create Option Group bool false no
create_parameter_group_name (Optional) Do you want to create Parameter Group bool false no
custom_iam_instance_profile (Optional) The instance profile associated with the underlying Amazon EC2 instance of an RDS Custom DB instance. string null no
customer_owned_ip_enabled (Optional) Indicates whether to enable a customer-owned IP address (CoIP) for an RDS on Outposts DB instance. See CoIP for RDS on Outposts for more information. bool null no
db_name (Optional) The name of the database to create when the DB instance is created. If this parameter is not specified, no database is created in the DB instance. Note that this does not apply for Oracle or SQL Server engines. See the AWS documentation for more details on what applies for those engines. If you are providing an Oracle db name, it needs to be in all upper case. Cannot be specified for a replica. string null no
db_subnet_group_name (Optional) 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. When working with read replicas, it should be specified only if the source database specifies an instance in another AWS Region. string null no
dedicated_log_volume (Optional, boolean) Use a dedicated log volume (DLV) for the DB instance. Requires Provisioned IOPS. See the AWS documentation for more details. bool false no
delete_automated_backups (Optional) Specifies whether to remove automated backups immediately after the DB instance is deleted. Default is true. bool true no
deletion_protection (Optional) If the DB instance should have deletion protection enabled. The database can't be deleted when this value is set to true. The default is false. bool false no
domain Optional) The ID of the Directory Service Active Directory domain to create the instance in. string null no
domain_auth_secret_arn (Optional, but required if domain_fqdn is provided) The ARN for the Secrets Manager secret with the self managed Active Directory credentials for the user joining the domain. Conflicts with domain and domain_iam_role_name. string null no
domain_dns_ips (Optional, but required if domain_fqdn is provided) The IPv4 DNS IP addresses of your primary and secondary self managed Active Directory domain controllers. Two IP addresses must be provided. If there isn't a secondary domain controller, use the IP address of the primary domain controller for both entries in the list. Conflicts with domain and domain_iam_role_name. list(string) null no
domain_fqdn (Optional) The fully qualified domain name (FQDN) of the self managed Active Directory domain. Conflicts with domain and domain_iam_role_name. string null no
domain_iam_role_name (Optional, but required if domain is provided) The name of the IAM role to be used when making API calls to the Directory Service. string null no
domain_ou (Optional, but required if domain_fqdn is provided) The self managed Active Directory organizational unit for your DB instance to join. Conflicts with domain and domain_iam_role_name. string null no
enable_blue_green_update (Optional) Enable Blue Green Update for RDS Deployment bool false no
enabled_cloudwatch_logs_exports (Optional) Set of log types to enable for exporting to CloudWatch logs. If omitted, no logs will be exported. Valid values (depending on engine). MySQL and MariaDB: audit, error, general, slowquery. PostgreSQL: postgresql, upgrade. MSSQL: agent , error. Oracle: alert, audit, listener, trace. list(string) [] no
engine (Required unless a snapshot_identifier or replicate_source_db is provided) The database engine to use. string n/a yes
engine_name (Required) Specifies the name of the engine that this option group should be associated with. string null no
engine_version (Required) The engine version to use. If auto_minor_version_upgrade is enabled, you can provide a prefix of the version such as 5.7 (for 5.7.10) and this attribute will ignore differences in the patch version automatically (e.g. 5.7.17). string n/a yes
family (Required, Forces new resource) The family of the DB parameter group. string n/a yes
final_snapshot_identifier (Optional) The name of your final DB snapshot when this DB instance is deleted. Must be provided if skip_final_snapshot is set to false. The value must begin with a letter, only contain alphanumeric characters and hyphens, and not end with a hyphen or contain two consecutive hyphens. Must not be provided when deleting a read replica. string "final" no
iam_database_authentication_enabled (Optional) Specifies whether or mappings of AWS Identity and Access Management (IAM) accounts to database accounts is enabled. bool false no
identifier (Required) The name of the RDS instance, if omitted, Terraform will assign a random, unique identifier. Required if restore_to_point_in_time is specified. string n/a yes
instance_class (Required) The instance type of the RDS instance. string n/a yes
iops (Optional) The amount of provisioned IOPS. Setting this implies a storage_type of io. number null no
kms_key_id (Required) The ARN for the KMS encryption key. If creating an encrypted replica, set this to the destination KMS ARN. string null no
license_model (Optional, but required for some DB engines, i.e. Oracle SE1) License model information for this DB instance. string null no
maintenance_window (Optional) The window to perform maintenance in. Syntax: ddd:hh24:mi-ddd:hh24:mi. Eg: Mon:00:00-Mon:03:00. See RDS Maintenance Window docs for more information. string "Mon:00:00-Mon:03:00" no
major_engine_version (Required) Specifies the major version of the engine that this option group should be associated with. string null no
manage_master_user_password (Optional) Set to true to allow RDS to manage the master user password in Secrets Manager. Cannot be set if password is provided. bool null no
master_user_secret_kms_key_id (Optional) The Amazon Web Services KMS key identifier is the key ARN, key ID, alias ARN, or alias name for the KMS key. To use a KMS key in a different Amazon Web Services account, specify the key ARN or alias ARN. If not specified, the default KMS key for your Amazon Web Services account is used. string null no
max_allocated_storage Optional) 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 0 no
monitoring_interval (Optional) The interval, in seconds, between points when Enhanced Monitoring metrics are collected for the DB instance. To disable collecting Enhanced Monitoring metrics, specify 0. The default is 0. Valid Values: 0, 1, 5, 10, 15, 30, 60. number 0 no
monitoring_role_arn (Optional) The ARN for the IAM role that permits RDS to send enhanced monitoring metrics to CloudWatch Logs. You can find more information on the AWS Documentation what IAM permissions are needed to allow Enhanced Monitoring for RDS Instances. string null no
multi_az (Optional) Specifies if the RDS instance is multi-AZ bool false no
nchar_character_set_name Optional, Forces new resource) The national character set is used in the NCHAR, NVARCHAR2, and NCLOB data types for Oracle instances. This can't be changed. string null no
network_type (Optional) The network type of the DB instance. Valid values: IPV4, DUAL. string "IPV4" no
option_group_name (Optional) Name of the DB option group to associate. string null no
options (Optional) A list of Options to apply with this option group. The following arguments are supported:
option_name - (Required) The name of the option.
port - (Optional) The port number that this option uses.
version - (Optional) The version of the option.
db_security_group_memberships - (Optional) A list of DB Security Groups to associate with this option.
vpc_security_group_memberships - (Optional) A list of VPC Security Groups to associate with this option.
option_settings - (Optional) A list of option settings to apply.
list(object({
option_name = string
port = optional(number)
version = optional(string)
db_security_group_memberships = optional(list(string))
vpc_security_group_memberships = optional(list(string))
option_settings = optional(list(object({
name = string
value = string
})))
}))
[] no
parameter_group_name (Optional) Name of the DB parameter group to associate. string null no
parameters (Optional) A list of DB parameters to apply with this parameter group. See the RDS User Guide for a list of valid parameters. Note that parameters may differ from a DB family to another. The following arguments are supported:
name - (Required) The name of the DB parameter.
value - (Required) The value of the DB parameter.
apply_method - (Optional) The apply method of the DB parameter. Valid values are immediate and pending-reboot. Default is immediate.
list(object({
name = string
value = string
apply_method = optional(string)
}))
[] no
password (Required unless a snapshot_identifier or replicate_source_db is provided) Password for the master DB user. Note that this may show up in logs, and it will be stored in the state file. string n/a yes
performance_insights_enabled (Optional) Specifies whether Performance Insights are enabled. Defaults to false. bool false no
performance_insights_kms_key_id (Optional) The ARN for the KMS key to encrypt Performance Insights data. When specifying performance_insights_kms_key_id, performance_insights_enabled needs to be set to true. Once KMS key is set, it can never be changed. string null no
performance_insights_retention_period (Optional) The amount of time in days to retain Performance Insights data. Either 7 (7 days) or 731 (2 years). When specifying performance_insights_retention_period, performance_insights_enabled needs to be set to true. Defaults to '7'. number null no
port (Required) The port on which the DB accepts connections. number n/a yes
publicly_accessible (Optional) Bool to control if instance is publicly accessible. Default is false. bool false no
replica_mode Optional) Specifies whether the replica is in either mounted or open-read-only mode. This attribute is only supported by Oracle instances. Oracle replicas operate in open-read-only mode unless otherwise specified. See Working with Oracle Read Replicas for more information. string null no
replicate_source_db (Optional) 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
restore_to_point_in_time (Optional) The settings to restore a DB instance to a specific point in time. The following arguments are supported:
restore_time - (Optional) The date and time to restore from. Valid values are in the format "YYYY-MM-DDTHH:MM:SSZ". Must be at least 5 minutes in the past.
source_db_instance_identifier - (Optional) The identifier of the source DB instance from which to restore.
source_db_instance_automated_backups_arn - (Optional) The ARN of the source DB instance from which to restore.
source_dbi_resource_id - (Optional) The resource ID of the source DB instance from which to restore.
use_latest_restorable_time - (Optional) When restoring from a DB snapshot, this value determines if the DB instance is restored from the latest backup time. By default, the DB instance is not restored from the latest backup time.
list(object({
restore_time = optional(string)
source_db_instance_identifier = optional(string)
source_db_instance_automated_backups_arn = optional(string)
source_dbi_resource_id = optional(string)
use_latest_restorable_time = optional(bool)
}))
[] no
s3_import (Optional) The settings to import data from an S3 bucket. The following arguments are supported:
bucket_name - (Required) The name of the S3 bucket.
bucket_prefix - (Optional) The prefix used when importing data from S3.
ingestion_role - (Required) The name of the role to grant RDS to access the S3 bucket.
source_engine - (Required) The name of the engine of the source database.
source_engine_version - (Required) The version of the engine of the source database.
list(object({
bucket_name = string
bucket_prefix = optional(string)
ingestion_role = string
source_engine = string
source_engine_version = string
}))
[] no
skip_final_snapshot (Optional) Determines whether a final DB snapshot is created before the DB instance is deleted. If true is specified, no DBSnapshot is created. If false is specified, a DB snapshot is created before the DB instance is deleted, using the value from final_snapshot_identifier. Default is false. bool false no
snapshot_identifier (Optional) Specifies whether or not to create this database from a snapshot. This correlates to the snapshot ID you'd find in the RDS console, e.g: rds:production-2015-06-26-06-05. string null no
storage_encrypted (Optional) Specifies whether the DB instance is encrypted. Note that if you are creating a cross-region read replica this field is ignored and you should instead declare kms_key_id with a valid ARN. The default is true if not specified. bool false no
storage_throughput (Optional) The storage throughput value for the DB instance. Can only be set when storage_type is "gp3". Cannot be specified if the allocated_storage value is below a per-engine threshold. See the RDS User Guide for details. number null no
storage_type (Optional) One of "standard" (magnetic), "gp2" (general purpose SSD), "gp3" (general purpose SSD that needs iops independently) or "io1" (provisioned IOPS SSD). The default is "io1" if iops is specified, "gp2" if not. string "gp3" no
subnet_ids (Required) A list of VPC subnet IDs. list(string) [] no
tags (Optional) A map of tags to assign to the resource. map(string) {} no
timezone (Optional) Time zone of the DB instance. timezone is currently only supported by Microsoft SQL Server. The timezone can only be set on creation. string null no
username (Required unless a snapshot_identifier or replicate_source_db is provided) Username for the master DB user. string n/a yes
vpc_security_group_ids (Required) List of VPC security groups to associate. list(string) n/a yes

Outputs

Name Description
address The hostname of the RDS instance.
endpoint The connection endpoint in address:port format.
engine_version_actual The running version of the database.
id RDS DBI resource ID.
resource_id The RDS Resource ID of this instance.
status The RDS instance status.