• Stars
    star
    879
  • Rank 51,943 (Top 2 %)
  • Language HCL
  • License
    Apache License 2.0
  • Created about 7 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Terraform module to create AWS RDS resources πŸ‡ΊπŸ‡¦

AWS RDS Terraform module

Terraform module which creates RDS resources on AWS.

SWUbanner

Root module calls these modules which can also be used separately to create independent resources:

Usage

module "db" {
  source = "terraform-aws-modules/rds/aws"

  identifier = "demodb"

  engine            = "mysql"
  engine_version    = "5.7"
  instance_class    = "db.t3a.large"
  allocated_storage = 5

  db_name  = "demodb"
  username = "user"
  port     = "3306"

  iam_database_authentication_enabled = true

  vpc_security_group_ids = ["sg-12345678"]

  maintenance_window = "Mon:00:00-Mon:03:00"
  backup_window      = "03:00-06:00"

  # Enhanced Monitoring - see example for details on how to create the role
  # by yourself, in case you don't want to create it automatically
  monitoring_interval    = "30"
  monitoring_role_name   = "MyRDSMonitoringRole"
  create_monitoring_role = true

  tags = {
    Owner       = "user"
    Environment = "dev"
  }

  # DB subnet group
  create_db_subnet_group = true
  subnet_ids             = ["subnet-12345678", "subnet-87654321"]

  # DB parameter group
  family = "mysql5.7"

  # DB option group
  major_engine_version = "5.7"

  # Database Deletion Protection
  deletion_protection = true

  parameters = [
    {
      name  = "character_set_client"
      value = "utf8mb4"
    },
    {
      name  = "character_set_server"
      value = "utf8mb4"
    }
  ]

  options = [
    {
      option_name = "MARIADB_AUDIT_PLUGIN"

      option_settings = [
        {
          name  = "SERVER_AUDIT_EVENTS"
          value = "CONNECT"
        },
        {
          name  = "SERVER_AUDIT_FILE_ROTATIONS"
          value = "37"
        },
      ]
    },
  ]
}

Conditional creation

The following values are provided to toggle on/off creation of the associated resources as desired:

module "db" {
  source = "terraform-aws-modules/rds/aws"

  # Disable creation of RDS instance(s)
  create_db_instance = false

  # Disable creation of option group - provide an option group or default AWS default
  create_db_option_group = false

  # Disable creation of parameter group - provide a parameter group or default to AWS default
  create_db_parameter_group = false

  # Enable creation of subnet group (disabled by default)
  create_db_subnet_group = true

  # Enable creation of monitoring IAM role
  create_monitoring_role = true

  # ... omitted
}

Option Groups

Reference

Users have the ability to:

  • Create an option group with the name provided:
  option_group_name            = "prod-instance-mysql-8.0"
  option_group_use_name_prefix = false
  • Create an option group using a unique prefix beginning with the name provided:
  option_group_name = "prod-instance-mysql-8.0"
  • Pass the name of an option group to use that has been created outside of the module:
  create_db_option_group = false
  option_group_name      = "prod-instance-mysql-8.0" # must already exist in AWS
  • Skip creating an option group for PostgreSQL entirely as that is not supported
  engine            = "postgres"
  option_group_name = "prod-instance-postgresql-11.0" # this will be ignored, no option group created
  • Use a default option group provided by AWS
  create_db_option_group = false

Parameter Groups

Reference

Users have the ability to:

  • Create a parameter group with the name provided:
  parameter_group_name            = "prod-instance-mysql-8.0"
  parameter_group_use_name_prefix = false
  • Create a parameter group using a unique prefix beginning with the name provided:
  parameter_group_name = "prod-instance-mysql-8.0"
  • Pass the name of a parameter group to use that has been created outside of the module:
  create_db_parameter_group = false
  parameter_group_name   = "prod-instance-mysql-8.0" # must already exist in AWS
  • Use a default parameter group provided by AWS
  create_db_parameter_group = false

Examples

Notes

  1. This module does not create RDS security group. Use terraform-aws-security-group module for this.
  2. For an RDS instance with storage_type using gp3, be aware that iops and storage_throughput cannot be specified if the allocated_storage value is below a per-engine threshold. See the RDS User Guide for details.

Requirements

Name Version
terraform >= 1.0
aws >= 5.0

Providers

No providers.

Modules

Name Source Version
db_instance ./modules/db_instance n/a
db_option_group ./modules/db_option_group n/a
db_parameter_group ./modules/db_parameter_group n/a
db_subnet_group ./modules/db_subnet_group n/a

Resources

No resources.

Inputs

Name Description Type Default Required
allocated_storage The allocated storage in gigabytes string null no
allow_major_version_upgrade 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 Specifies whether any database modifications are applied immediately, or during the next maintenance window bool false no
auto_minor_version_upgrade Indicates that minor engine upgrades will be applied automatically to the DB instance during the maintenance window bool true no
availability_zone The Availability Zone of the RDS instance string null no
backup_retention_period The days to retain backups for number null no
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
blue_green_update Enables low-downtime updates using RDS Blue/Green deployments. map(string) {} no
ca_cert_identifier Specifies the identifier of the CA certificate for the DB instance string null no
character_set_name The character set name to use for DB encoding in Oracle instances. This can't be changed. See Oracle Character Sets Supported in Amazon RDS and Collations and Character Sets for Microsoft SQL Server for more information. This can only be set on creation string null no
cloudwatch_log_group_kms_key_id The ARN of the KMS Key to use when encrypting log data string null no
cloudwatch_log_group_retention_in_days The number of days to retain CloudWatch logs for the DB instance number 7 no
copy_tags_to_snapshot On delete, copy all Instance tags to the final snapshot bool false no
create_cloudwatch_log_group Determines whether a CloudWatch log group is created for each enabled_cloudwatch_logs_exports bool false no
create_db_instance Whether to create a database instance bool true no
create_db_option_group Create a database option group bool true no
create_db_parameter_group Whether to create a database parameter group bool true no
create_db_subnet_group Whether to create a database subnet group bool false no
create_monitoring_role Create IAM role with a defined name that permits RDS to send enhanced monitoring metrics to CloudWatch Logs bool false no
custom_iam_instance_profile RDS custom iam instance profile string null no
db_instance_tags Additional tags for the DB instance map(string) {} no
db_name The DB name to create. If omitted, no database is created initially string null no
db_option_group_tags Additional tags for the DB option group map(string) {} no
db_parameter_group_tags Additional tags for the DB parameter group map(string) {} no
db_subnet_group_description Description of the DB subnet group to create string null no
db_subnet_group_name 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 string null no
db_subnet_group_tags Additional tags for the DB subnet group map(string) {} no
db_subnet_group_use_name_prefix Determines whether to use subnet_group_name as is or create a unique name beginning with the subnet_group_name as the prefix bool true no
delete_automated_backups Specifies whether to remove automated backups immediately after the DB instance is deleted bool true no
deletion_protection The database can't be deleted when this value is set to true bool false no
domain The ID of the Directory Service Active Directory domain to create the instance in string null no
domain_iam_role_name (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
enabled_cloudwatch_logs_exports List of log types to enable for exporting to CloudWatch logs. If omitted, no logs will be exported. Valid values (depending on engine): alert, audit, error, general, listener, slowquery, trace, postgresql (PostgreSQL), upgrade (PostgreSQL) list(string) [] no
engine The database engine to use string null no
engine_version The engine version to use string null no
family The family of the DB parameter group string null no
final_snapshot_identifier_prefix The name which is prefixed to the final snapshot on cluster destroy string "final" no
iam_database_authentication_enabled Specifies whether or not the mappings of AWS Identity and Access Management (IAM) accounts to database accounts are enabled bool false no
identifier The name of the RDS instance string n/a yes
instance_class The instance type of the RDS instance string null no
instance_use_identifier_prefix Determines whether to use identifier as is or create a unique identifier beginning with identifier as the specified prefix bool false no
iops The amount of provisioned IOPS. Setting this implies a storage_type of 'io1' or gp3. See notes for limitations regarding this variable for gp3 number null no
kms_key_id The ARN for the KMS encryption key. If creating an encrypted replica, set this to the destination KMS ARN. If storage_encrypted is set to true and kms_key_id is not specified the default KMS key created in your account will be used. Be sure to use the full ARN, not a key alias. string null no
license_model License model information for this DB instance. Optional, but required for some DB engines, i.e. Oracle SE1 string null no
maintenance_window The window to perform maintenance in. Syntax: 'ddd:hh24:mi-ddd:hh24:mi'. Eg: 'Mon:00:00-Mon:03:00' string null no
major_engine_version Specifies the major version of the engine that this option group should be associated with string null no
manage_master_user_password Set to true to allow RDS to manage the master user password in Secrets Manager bool true no
master_user_secret_kms_key_id The key ARN, key ID, alias ARN or alias name for the KMS key to encrypt the master user password secret in Secrets Manager.
If not specified, the default KMS key for your Amazon Web Services account is used.
string null no
max_allocated_storage Specifies the value for Storage Autoscaling number 0 no
monitoring_interval 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 The ARN for the IAM role that permits RDS to send enhanced monitoring metrics to CloudWatch Logs. Must be specified if monitoring_interval is non-zero string null no
monitoring_role_description Description of the monitoring IAM role string null no
monitoring_role_name Name of the IAM role which will be created when create_monitoring_role is enabled string "rds-monitoring-role" no
monitoring_role_permissions_boundary ARN of the policy that is used to set the permissions boundary for the monitoring IAM role string null no
monitoring_role_use_name_prefix Determines whether to use monitoring_role_name as is or create a unique identifier beginning with monitoring_role_name as the specified prefix bool false no
multi_az Specifies if the RDS instance is multi-AZ bool false no
nchar_character_set_name 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 The type of network stack to use string null no
option_group_description The description of the option group string null no
option_group_name Name of the option group string null no
option_group_timeouts Define maximum timeout for deletion of aws_db_option_group resource map(string) {} no
option_group_use_name_prefix Determines whether to use option_group_name as is or create a unique name beginning with the option_group_name as the prefix bool true no
options A list of Options to apply any [] no
parameter_group_description Description of the DB parameter group to create string null no
parameter_group_name Name of the DB parameter group to associate or create string null no
parameter_group_use_name_prefix Determines whether to use parameter_group_name as is or create a unique name beginning with the parameter_group_name as the prefix bool true no
parameters A list of DB parameters (map) to apply list(map(string)) [] no
password Password for the master DB user. Note that this may show up in logs, and it will be stored in the state file.
The password provided will not be used if manage_master_user_password is set to true.
string null no
performance_insights_enabled Specifies whether Performance Insights are enabled bool false no
performance_insights_kms_key_id The ARN for the KMS key to encrypt Performance Insights data string null no
performance_insights_retention_period The amount of time in days to retain Performance Insights data. Valid values are 7, 731 (2 years) or a multiple of 31 number 7 no
port The port on which the DB accepts connections string null no
publicly_accessible Bool to control if instance is publicly accessible bool false no
putin_khuylo Do you agree that Putin doesn't respect Ukrainian sovereignty and territorial integrity? More info: https://en.wikipedia.org/wiki/Putin_khuylo! bool true no
replica_mode 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 string null no
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 string null no
restore_to_point_in_time Restore to a point in time (MySQL is NOT supported) map(string) null no
s3_import Restore from a Percona Xtrabackup in S3 (only MySQL is supported) map(string) null no
skip_final_snapshot 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 bool false no
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, e.g: rds:production-2015-06-26-06-05 string null no
storage_encrypted Specifies whether the DB instance is encrypted bool true no
storage_throughput Storage throughput value for the DB instance. See notes for limitations regarding this variable for gp3 number null no
storage_type One of 'standard' (magnetic), 'gp2' (general purpose SSD), 'gp3' (new generation of general purpose SSD), or 'io1' (provisioned IOPS SSD). The default is 'io1' if iops is specified, 'gp2' if not. If you specify 'io1' or 'gp3' , you must also include a value for the 'iops' parameter string null no
subnet_ids A list of VPC subnet IDs list(string) [] no
tags A mapping of tags to assign to all resources map(string) {} no
timeouts Updated Terraform resource management timeouts. Applies to aws_db_instance in particular to permit resource management times map(string) {} no
timezone Time zone of the DB instance. timezone is currently only supported by Microsoft SQL Server. The timezone can only be set on creation. See MSSQL User Guide for more information string null no
username Username for the master DB user string null no
vpc_security_group_ids List of VPC security groups to associate list(string) [] no

Outputs

Name Description
db_instance_address The address of the RDS instance
db_instance_arn The ARN of the RDS instance
db_instance_availability_zone The availability zone of the RDS instance
db_instance_ca_cert_identifier Specifies the identifier of the CA certificate for the DB instance
db_instance_cloudwatch_log_groups Map of CloudWatch log groups created and their attributes
db_instance_domain The ID of the Directory Service Active Directory domain the instance is joined to
db_instance_domain_iam_role_name The name of the IAM role to be used when making API calls to the Directory Service
db_instance_endpoint The connection endpoint
db_instance_engine The database engine
db_instance_engine_version_actual The running version of the database
db_instance_hosted_zone_id The canonical hosted zone ID of the DB instance (to be used in a Route 53 Alias record)
db_instance_identifier The RDS instance identifier
db_instance_master_user_secret_arn The ARN of the master user secret (Only available when manage_master_user_password is set to true)
db_instance_name The database name
db_instance_port The database port
db_instance_resource_id The RDS Resource ID of this instance
db_instance_status The RDS instance status
db_instance_username The master username for the database
db_listener_endpoint Specifies the listener connection endpoint for SQL Server Always On
db_option_group_arn The ARN of the db option group
db_option_group_id The db option group id
db_parameter_group_arn The ARN of the db parameter group
db_parameter_group_id The db parameter group id
db_subnet_group_arn The ARN of the db subnet group
db_subnet_group_id The db subnet group name
enhanced_monitoring_iam_role_arn The Amazon Resource Name (ARN) specifying the monitoring role
enhanced_monitoring_iam_role_name The name of the monitoring role

Authors

Module is maintained by Anton Babenko with help from these awesome contributors.

License

Apache 2 Licensed. See LICENSE for full details.

Additional information for users from Russia and Belarus

More Repositories

1

terraform-aws-eks

Terraform module to create Amazon Elastic Kubernetes (EKS) resources πŸ‡ΊπŸ‡¦
HCL
4,372
star
2

terraform-aws-vpc

Terraform module to create AWS VPC resources πŸ‡ΊπŸ‡¦
HCL
2,949
star
3

terraform-aws-lambda

Terraform module, which takes care of a lot of AWS Lambda/serverless tasks (build dependencies, packages, updates, deployments) in countless combinations πŸ‡ΊπŸ‡¦
HCL
899
star
4

terraform-aws-iam

Terraform module to create AWS IAM resources πŸ‡ΊπŸ‡¦
HCL
779
star
5

terraform-aws-ec2-instance

Terraform module to create AWS EC2 instance(s) resources πŸ‡ΊπŸ‡¦
HCL
751
star
6

terraform-aws-security-group

Terraform module to create AWS Security Group resources πŸ‡ΊπŸ‡¦
HCL
563
star
7

terraform-aws-ecs

Terraform module to create AWS ECS resources πŸ‡ΊπŸ‡¦
HCL
555
star
8

terraform-aws-atlantis

Terraform module to deploy Atlantis on AWS Fargate πŸ‡ΊπŸ‡¦
HCL
519
star
9

terraform-aws-s3-bucket

Terraform module to create AWS S3 resources πŸ‡ΊπŸ‡¦
HCL
511
star
10

terraform-aws-notify-slack

Terraform module to create AWS resources for sending notifications to Slack πŸ‡ΊπŸ‡¦
Python
466
star
11

terraform-aws-alb

Terraform module to create AWS Application/Network Load Balancer (ALB/NLB) resources πŸ‡ΊπŸ‡¦
HCL
433
star
12

terraform-aws-rds-aurora

Terraform module to create AWS RDS Aurora resources πŸ‡ΊπŸ‡¦
HCL
384
star
13

terraform-aws-autoscaling

Terraform module to create AWS Auto Scaling resources πŸ‡ΊπŸ‡¦
HCL
292
star
14

terraform-aws-pricing

Terraform module which calculates price of AWS infrastructure (from Terraform state and plan) πŸ‡ΊπŸ‡¦
HCL
183
star
15

terraform-aws-acm

Terraform module to create AWS ACM resources πŸ‡ΊπŸ‡¦
HCL
182
star
16

terraform-aws-cloudwatch

Terraform module to create AWS Cloudwatch resources πŸ‡ΊπŸ‡¦
HCL
163
star
17

terraform-aws-elb

Terraform module to create AWS ELB resources πŸ‡ΊπŸ‡¦
HCL
148
star
18

terraform-aws-apigateway-v2

Terraform module to create AWS API Gateway v2 (HTTP/WebSocket) πŸ‡ΊπŸ‡¦
HCL
146
star
19

terraform-aws-eventbridge

Terraform module to create AWS EventBridge resources πŸ‡ΊπŸ‡¦
HCL
142
star
20

terraform-aws-transit-gateway

Terraform module to create AWS Transit Gateway resources πŸ‡ΊπŸ‡¦
HCL
141
star
21

terraform-aws-route53

Terraform module to create AWS Route53 resources πŸ‡ΊπŸ‡¦
HCL
126
star
22

terraform-aws-cloudfront

Terraform module to create AWS CloudFront resources πŸ‡ΊπŸ‡¦
HCL
119
star
23

terraform-aws-vpn-gateway

Terraform module to create AWS VPN gateway resources πŸ‡ΊπŸ‡¦
HCL
111
star
24

terraform-aws-dynamodb-table

Terraform module to create AWS DynamoDB resources πŸ‡ΊπŸ‡¦
HCL
100
star
25

terraform-aws-sns

Terraform module to create AWS SNS resources πŸ‡ΊπŸ‡¦
HCL
95
star
26

terraform-aws-sqs

Terraform module to create AWS SQS resources πŸ‡ΊπŸ‡¦
HCL
92
star
27

terraform-aws-key-pair

Terraform module to create AWS EC2 key pair resources πŸ‡ΊπŸ‡¦
HCL
83
star
28

terraform-aws-redshift

Terraform module to create AWS Redshift resources πŸ‡ΊπŸ‡¦
HCL
81
star
29

meta

Meta-configurations for repositories, teams, files in terraform-aws-modules organization πŸ‡ΊπŸ‡¦
HCL
76
star
30

terraform-aws-solutions

Set of standalone and reusable AWS/DevOps solutions implemented as Terraform modules πŸ‡ΊπŸ‡¦
HCL
75
star
31

terraform-aws-step-functions

Terraform module to create AWS Step Functions πŸ‡ΊπŸ‡¦
HCL
70
star
32

terraform-aws-dms

Terraform module to create AWS DMS (Database Migration Service) resources πŸ‡ΊπŸ‡¦
HCL
62
star
33

terraform-aws-rds-proxy

Terraform module to create AWS RDS Proxy resources πŸ‡ΊπŸ‡¦
HCL
56
star
34

terraform-aws-msk-kafka-cluster

Terraform module to create AWS MSK (Managed Streaming for Kafka) resources πŸ‡ΊπŸ‡¦
HCL
55
star
35

terraform-aws-datadog-forwarders

Terraform module to create resources on AWS to forward logs/metrics to Datadog πŸ‡ΊπŸ‡¦
HCL
53
star
36

terraform-aws-eks-pod-identity

Terraform module to create AWS EKS Pod Identity resources πŸ‡ΊπŸ‡¦
HCL
52
star
37

terraform-aws-appsync

Terraform module to create AWS AWS AppSync resources πŸ‡ΊπŸ‡¦
HCL
50
star
38

terraform-aws-kms

Terraform module to create AWS KMS resources πŸ‡ΊπŸ‡¦
HCL
49
star
39

terraform-aws-ecr

Terraform module to create AWS ECR resources πŸ‡ΊπŸ‡¦
HCL
49
star
40

terraform-aws-managed-service-grafana

Terraform module to create AWS Managed Service for Grafana (AMG) resources πŸ‡ΊπŸ‡¦
HCL
36
star
41

terraform-aws-batch

Terraform module to create AWS Batch resources πŸ‡ΊπŸ‡¦
HCL
35
star
42

terraform-aws-app-runner

Terraform module to create AWS App Runner resources πŸ‡ΊπŸ‡¦
HCL
32
star
43

terraform-aws-secrets-manager

Terraform module to create AWS Secrets Manager resources πŸ‡ΊπŸ‡¦
HCL
28
star
44

terraform-aws-appconfig

Terraform module to create AWS AppConfig resources πŸ‡ΊπŸ‡¦
HCL
27
star
45

terraform-aws-managed-service-prometheus

Terraform module to create AWS Managed Service for Prometheus (AMP) resources πŸ‡ΊπŸ‡¦
HCL
26
star
46

terraform-aws-efs

Terraform module to create AWS EFS resources πŸ‡ΊπŸ‡¦
HCL
24
star
47

terraform-aws-emr

Terraform module to create AWS EMR resources πŸ‡ΊπŸ‡¦
HCL
23
star
48

.github

Meta-GitHub repository for all terraform-aws-modules repositories πŸ‡ΊπŸ‡¦
22
star
49

terraform-aws-ssm-parameter

Terraform module to create AWS SSM Parameter resources πŸ‡ΊπŸ‡¦
HCL
20
star
50

terraform-aws-s3-object

Terraform module which creates S3 object resources on AWS
HCL
17
star
51

terraform-aws-ebs-optimized

Terraform module to determine if an instance can be flagged for EBS optimization
HCL
17
star
52

terraform-aws-customer-gateway

Terraform module to create AWS Customer Gateway resources πŸ‡ΊπŸ‡¦
HCL
17
star
53

terraform-aws-global-accelerator

Terraform module to create AWS Global Accelerator resources πŸ‡ΊπŸ‡¦
HCL
16
star
54

terraform-aws-memory-db

Terraform module to create AWS MemoryDB resources πŸ‡ΊπŸ‡¦
HCL
16
star
55

terraform-aws-opensearch

Terraform module to create AWS OpenSearch resources πŸ‡ΊπŸ‡¦
HCL
15
star
56

terraform-aws-elasticache

Terraform module to create AWS ElastiCache resources πŸ‡ΊπŸ‡¦
HCL
12
star
57

terraform-aws-network-firewall

Terraform module to create AWS Network Firewall resources πŸ‡ΊπŸ‡¦
HCL
12
star
58

terraform-aws-fsx

Terraform module to create AWS FSx resources πŸ‡ΊπŸ‡¦
HCL
4
star
59

atlantis-demo

Demo repository for Atlantis
3
star