An open API service indexing awesome lists of open source software.

https://github.com/nventive/terraform-aws-rds

Terraform module to provision an RDS instance.
https://github.com/nventive/terraform-aws-rds

Last synced: 2 months ago
JSON representation

Terraform module to provision an RDS instance.

Awesome Lists containing this project

README

          

![nventive](https://nventive-public-assets.s3.amazonaws.com/nventive_logo_github.svg?v=2)

# terraform-aws-rds

[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square)](LICENSE) [![Latest Release](https://img.shields.io/github/release/nventive/terraform-aws-rds.svg?style=flat-square)](https://github.com/nventive/terraform-aws-rds/releases/latest)

Terraform module to create an RDS instance.

---

## Examples

**IMPORTANT:** We do not pin modules to versions in our examples because of the difficulty of keeping the versions in
the documentation in sync with the latest released versions. We highly recommend that in your code you pin the version
to the exact version you are using so that your infrastructure remains stable, and update versions in a systematic way
so that they do not catch you by surprise.

```hcl
module "network" {
source = "nventive/network/aws"
# We recommend pinning every module to a specific version
# version = "x.x.x"

namespace = "eg"
stage = "test"
name = "app"

vpc_cidr_block = "10.0.0.0/16"
subnets_ipv4_cidr_block = ["10.0.0.0/16"]
subnets_availability_zones = ["us-east-1a", "us-east-1b"]
subnets_nat_gateway_enabled = true
s3_endpoint_enabled = false
}

module "db" {
source = "nventive/network/aws"
# We recommend pinning every module to a specific version
# version = "x.x.x"

namespace = "eg"
stage = "test"
name = "app"

enabled = true
name = "wordpress-db"
security_group_ids = []
allowed_cidr_blocks = []
database_name = "wordpress"
database_user = "wp_admin"
database_password = "VXBVcERvd25Eb3duTGVmdFJpZ2h0TGVmdFJpZ2h0QkE="
database_port = 3306
allocated_storage = 100
engine = "mysql"
engine_version = "5.7"
major_engine_version = "5.7"
instance_class = "db.t3.micro"
db_parameter_group = "mysql5.7"
publicly_accessible = false
subnet_ids = module.network.private_subnet_ids
vpc_id = module.network.vpc_id
allow_major_version_upgrade = false
apply_immediately = false
skip_final_snapshot = false
backup_retention_period = 7
}
```

## Requirements

| Name | Version |
|------|---------|
| [terraform](#requirement\_terraform) | >= 0.13.0 |
| [aws](#requirement\_aws) | >= 3.0 |
| [null](#requirement\_null) | >= 2.0 |
| [random](#requirement\_random) | >= 3.0 |
| [template](#requirement\_template) | >= 2.0 |

## Providers

| Name | Version |
|------|---------|
| [aws](#provider\_aws) | >= 3.0 |
| [null](#provider\_null) | >= 2.0 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| [db](#module\_db) | cloudposse/rds/aws | 1.0.0 |
| [proxy\_label](#module\_proxy\_label) | cloudposse/label/null | 0.25.0 |
| [rds\_proxy](#module\_rds\_proxy) | cloudposse/rds-db-proxy/aws | 1.1.0 |
| [sg](#module\_sg) | cloudposse/security-group/aws | 2.0.0 |
| [ssm\_label](#module\_ssm\_label) | cloudposse/label/null | 0.25.0 |
| [this](#module\_this) | cloudposse/label/null | 0.25.0 |

## Resources

| Name | Type |
|------|------|
| [aws_iam_policy.ssm_get](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
| [aws_secretsmanager_secret.rds_username_and_password](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret) | resource |
| [aws_secretsmanager_secret_version.rds_username_and_password](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret_version) | resource |
| [aws_ssm_parameter.db_password](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_parameter) | resource |
| [null_resource.password_validation](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
| [aws_iam_policy_document.ssm](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| [additional\_tag\_map](#input\_additional\_tag\_map) | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.
This is for some rare cases where resources want additional configuration of tags
and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no |
| [allocated\_storage](#input\_allocated\_storage) | The allocated storage in GBs. | `number` | `null` | no |
| [allow\_major\_version\_upgrade](#input\_allow\_major\_version\_upgrade) | Allow major version upgrade. | `bool` | `false` | no |
| [allowed\_cidr\_blocks](#input\_allowed\_cidr\_blocks) | The whitelisted CIDRs which to allow `ingress` traffic to the DB instance. | `list(string)` | `[]` | no |
| [apply\_immediately](#input\_apply\_immediately) | Specifies whether any database modifications are applied immediately, or during the next maintenance window. | `bool` | `false` | no |
| [associate\_security\_group\_ids](#input\_associate\_security\_group\_ids) | The IDs of the existing security groups to associate with the DB instance. | `list(string)` | `[]` | no |
| [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,
in the order they appear in the list. New attributes are appended to the
end of the list. The elements of the list are joined by the `delimiter`
and treated as a single ID element. | `list(string)` | `[]` | no |
| [auto\_minor\_version\_upgrade](#input\_auto\_minor\_version\_upgrade) | Allow automated minor version upgrade (e.g. from Postgres 9.5.3 to Postgres 9.5.4). | `bool` | `true` | no |
| [backup\_retention\_period](#input\_backup\_retention\_period) | Backup retention period in days. Must be > 0 to enable backups. | `number` | `0` | no |
| [backup\_window](#input\_backup\_window) | When AWS can perform DB snapshots, can't overlap with maintenance window. | `string` | `"22:00-03:00"` | no |
| [ca\_cert\_identifier](#input\_ca\_cert\_identifier) | The identifier of the CA certificate for the DB instance. | `string` | `null` | no |
| [context](#input\_context) | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. | `any` |

{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"descriptor_formats": {},
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"labels_as_tags": [
"unset"
],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {},
"tenant": null
}
| no |
| [copy\_tags\_to\_snapshot](#input\_copy\_tags\_to\_snapshot) | Copy tags from DB to a snapshot. | `bool` | `true` | no |
| [database\_name](#input\_database\_name) | The name of the database to create when the DB instance is created. | `string` | n/a | yes |
| [database\_password](#input\_database\_password) | (Required unless a snapshot\_identifier or replicate\_source\_db is provided)
BASE64 encoded Password for the master DB user.
The password for the database master user can include any printable ASCII character except /, ", @, or a space. | `string` | `""` | no |
| [database\_port](#input\_database\_port) | Database port (\_e.g.\_ `3306` for `MySQL`). Used in the DB Security Group to allow access to the DB instance from the provided `security_group_ids`. | `number` | `5432` | no |
| [database\_user](#input\_database\_user) | (Required unless a `snapshot_identifier` or `replicate_source_db` is provided) Username for the master DB user. | `string` | `""` | no |
| [db\_options](#input\_db\_options) | A list of DB options to apply with an option group. Depends on DB engine. |
list(object({
db_security_group_memberships = list(string)
option_name = string
port = number
version = string
vpc_security_group_memberships = list(string)

option_settings = list(object({
name = string
value = string
}))
}))
| `[]` | no |
| [db\_parameter](#input\_db\_parameter) | A list of DB parameters to apply. Note that parameters may differ from a DB family to another. |
list(object({
apply_method = string
name = string
value = string
}))
| `[]` | no |
| [db\_parameter\_group](#input\_db\_parameter\_group) | The DB parameter group family name. The value depends on DB engine used.
See [DBParameterGroupFamily](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBParameterGroup.html#API_CreateDBParameterGroup_RequestParameters) for instructions on how to retrieve applicable value." | `string` | n/a | yes |
| [deletion\_protection](#input\_deletion\_protection) | Set to true to enable deletion protection on the RDS instance. | `bool` | `true` | no |
| [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
| [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.
Map of maps. Keys are names of descriptors. Values are maps of the form
`{
format = string
labels = list(string)
}`
(Type is `any` so the map values can later be enhanced to provide additional options.)
`format` is a Terraform format string to be passed to the `format()` function.
`labels` is a list of labels, in order, to pass to `format()` function.
Label values will be normalized before being passed to `format()` so they will be
identical to how they appear in `id`.
Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
| [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
| [enabled\_cloudwatch\_logs\_exports](#input\_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](#input\_engine) | Database engine type. | `string` | `"postgres"` | no |
| [engine\_version](#input\_engine\_version) | Database engine version, depends on engine type. | `string` | n/a | yes |
| [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
| [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).
Set to `0` for unlimited length.
Set to `null` for keep the existing setting, which defaults to `0`.
Does not affect `id_full`. | `number` | `null` | no |
| [instance\_class](#input\_instance\_class) | Class of RDS instance. | `string` | n/a | yes |
| [kms\_key\_arn](#input\_kms\_key\_arn) | The ARN of the existing KMS key to encrypt storage. | `string` | `""` | no |
| [label\_key\_case](#input\_label\_key\_case) | Controls the letter case of the `tags` keys (label names) for tags generated by this module.
Does not affect keys of tags passed in via the `tags` input.
Possible values: `lower`, `title`, `upper`.
Default value: `title`. | `string` | `null` | no |
| [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no |
| [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,
set as tag values, and output by this module individually.
Does not affect values of tags passed in via the `tags` input.
Possible values: `lower`, `title`, `upper` and `none` (no transformation).
Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.
Default value: `lower`. | `string` | `null` | no |
| [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.
Default is to include all labels.
Tags with empty values will not be included in the `tags` output.
Set to `[]` to suppress all generated tags.
**Notes:**
The value of the `name` tag, if included, will be the `id`, not the `name`.
Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be
changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` |
[
"default"
]
| no |
| [maintenance\_window](#input\_maintenance\_window) | The window to perform maintenance in. Syntax: 'ddd:hh24:mi-ddd:hh24:mi' UTC. | `string` | `"Mon:03:00-Mon:04:00"` | no |
| [major\_engine\_version](#input\_major\_engine\_version) | Database MAJOR engine version, depends on engine type. | `string` | `""` | no |
| [multi\_az](#input\_multi\_az) | Set to true if multi AZ deployment must be supported. | `bool` | `false` | no |
| [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a `tag`.
The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no |
| [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no |
| [option\_group\_name](#input\_option\_group\_name) | Name of the DB option group to associate. | `string` | `""` | no |
| [parameter\_group\_name](#input\_parameter\_group\_name) | Name of the DB parameter group to associate. | `string` | `""` | no |
| [proxy\_connection\_borrow\_timeout](#input\_proxy\_connection\_borrow\_timeout) | The number of seconds for a proxy to wait for a connection to become available in the connection pool. Only applies when the proxy has opened its maximum number of connections and all connections are busy with client sessions. | `number` | `120` | no |
| [proxy\_debug\_logging](#input\_proxy\_debug\_logging) | Whether the proxy includes detailed information about SQL statements in its logs. | `bool` | `false` | no |
| [proxy\_enabled](#input\_proxy\_enabled) | Set to `true` to enable RDS proxy. Only available for Postgre and MySQL engines. | `bool` | `false` | no |
| [proxy\_existing\_iam\_role\_arn](#input\_proxy\_existing\_iam\_role\_arn) | The ARN of an existing IAM role that the proxy can use to access secrets in AWS Secrets Manager. If not provided, the module will create a role to access secrets in Secrets Manager. | `string` | `null` | no |
| [proxy\_idle\_client\_timeout](#input\_proxy\_idle\_client\_timeout) | The number of seconds that a connection to the proxy can be inactive before the proxy disconnects it. | `number` | `1800` | no |
| [proxy\_init\_query](#input\_proxy\_init\_query) | One or more SQL statements for the proxy to run when opening each new database connection. | `string` | `null` | no |
| [proxy\_max\_connections\_percent](#input\_proxy\_max\_connections\_percent) | The maximum size of the connection pool for each target in a target group. | `number` | `100` | no |
| [proxy\_max\_idle\_connections\_percent](#input\_proxy\_max\_idle\_connections\_percent) | Controls how actively the proxy closes idle database connections in the connection pool. A high value enables the proxy to leave a high percentage of idle connections open. A low value causes the proxy to close idle client connections and return the underlying database connections to the connection pool. | `number` | `50` | no |
| [proxy\_require\_tls](#input\_proxy\_require\_tls) | A Boolean parameter that specifies whether Transport Layer Security (TLS) encryption is required for connections to the proxy. By enabling this setting, you can enforce encrypted TLS connections to the proxy. | `bool` | `false` | no |
| [proxy\_session\_pinning\_filters](#input\_proxy\_session\_pinning\_filters) | Each item in the list represents a class of SQL operations that normally cause all later statements in a session using a proxy to be pinned to the same underlying database connection. | `list(string)` | `null` | no |
| [publicly\_accessible](#input\_publicly\_accessible) | Determines if database can be publicly available (NOT recommended). | `bool` | `false` | no |
| [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.
Characters matching the regex will be removed from the ID elements.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
| [security\_group\_ids](#input\_security\_group\_ids) | The IDs of the security groups from which to allow `ingress` traffic to the DB instance. | `list(string)` | `[]` | no |
| [skip\_final\_snapshot](#input\_skip\_final\_snapshot) | If true (default), no snapshot will be made before deleting DB. | `bool` | `false` | no |
| [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
| [storage\_encrypted](#input\_storage\_encrypted) | (Optional) Specifies whether the DB instance is encrypted. The default is false if not specified. | `bool` | `true` | no |
| [storage\_type](#input\_storage\_type) | One of 'standard' (magnetic), 'gp2' (general purpose SSD), or 'io1' (provisioned IOPS SSD). | `string` | `"gp2"` | no |
| [subnet\_ids](#input\_subnet\_ids) | List of subnet IDs for the DB. DB instance will be created in the VPC associated with the DB subnet group provisioned using the subnet IDs. Specify one of `subnet_ids`, `db_subnet_group_name` or `availability_zone`. | `list(string)` | `[]` | no |
| [tags](#input\_tags) | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).
Neither the tag keys nor the tag values will be modified by this module. | `map(string)` | `{}` | no |
| [tenant](#input\_tenant) | ID element \_(Rarely used, not included by default)\_. A customer identifier, indicating who this instance of a resource is for | `string` | `null` | no |
| [vpc\_id](#input\_vpc\_id) | VPC ID the DB instance will be created in. | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| [database\_name](#output\_database\_name) | The name of the database to create when the DB instance is created |
| [database\_user](#output\_database\_user) | Username for the master DB user |
| [enabled](#output\_enabled) | Whether or not the database is enabled |
| [hostname](#output\_hostname) | DNS host name of the instance |
| [iam\_policy\_ssm\_get\_arn](#output\_iam\_policy\_ssm\_get\_arn) | ARN of the IAM Policy with GET permission for the database password SSM parameter |
| [instance\_address](#output\_instance\_address) | Address of the instance |
| [instance\_arn](#output\_instance\_arn) | ARN of the instance |
| [instance\_endpoint](#output\_instance\_endpoint) | DNS Endpoint of the instance |
| [instance\_id](#output\_instance\_id) | ID of the instance |
| [option\_group\_id](#output\_option\_group\_id) | ID of the Option Group |
| [parameter\_group\_id](#output\_parameter\_group\_id) | ID of the Parameter Group |
| [password\_ssm\_arn](#output\_password\_ssm\_arn) | ARN of the SSM parameter for the database password |
| [proxy\_arn](#output\_proxy\_arn) | Proxy ARN |
| [proxy\_default\_target\_group\_arn](#output\_proxy\_default\_target\_group\_arn) | The Amazon Resource Name (ARN) representing the default target group |
| [proxy\_default\_target\_group\_name](#output\_proxy\_default\_target\_group\_name) | The name of the default target group |
| [proxy\_enabled](#output\_proxy\_enabled) | Whether or not the database proxy is enabled |
| [proxy\_endpoint](#output\_proxy\_endpoint) | Proxy endpoint |
| [proxy\_iam\_role\_arn](#output\_proxy\_iam\_role\_arn) | The ARN of the IAM role that the proxy uses to access secrets in AWS Secrets Manager |
| [proxy\_id](#output\_proxy\_id) | Proxy ID |
| [proxy\_target\_endpoint](#output\_proxy\_target\_endpoint) | Hostname for the target RDS DB Instance. Only returned for `RDS_INSTANCE` type |
| [proxy\_target\_id](#output\_proxy\_target\_id) | Identifier of `db_proxy_name`, `target_group_name`, `target type` (e.g. `RDS_INSTANCE` or `TRACKED_CLUSTER`), and resource identifier separated by forward slashes (`/`) |
| [proxy\_target\_port](#output\_proxy\_target\_port) | Port for the target RDS DB instance or Aurora DB cluster |
| [proxy\_target\_rds\_resource\_id](#output\_proxy\_target\_rds\_resource\_id) | Identifier representing the DB instance or DB cluster target |
| [proxy\_target\_target\_arn](#output\_proxy\_target\_target\_arn) | Amazon Resource Name (ARN) for the DB instance or DB cluster |
| [proxy\_target\_tracked\_cluster\_id](#output\_proxy\_target\_tracked\_cluster\_id) | DB Cluster identifier for the DB instance target. Not returned unless manually importing an `RDS_INSTANCE` target that is part of a DB cluster |
| [proxy\_target\_type](#output\_proxy\_target\_type) | Type of target. e.g. `RDS_INSTANCE` or `TRACKED_CLUSTER` |
| [resource\_id](#output\_resource\_id) | The RDS Resource ID of this instance |
| [security\_group\_id](#output\_security\_group\_id) | ID of the Security Group |
| [security\_group\_id\_self](#output\_security\_group\_id\_self) | ID of the Security Group with self referencing ingress |
| [subnet\_group\_id](#output\_subnet\_group\_id) | ID of the created Subnet Group |

## Breaking Changes

Please consult [BREAKING\_CHANGES.md](BREAKING\_CHANGES.md) for more information about version
history and compatibility.

## Contributing

Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on the process for
contributing to this project.

Be mindful of our [Code of Conduct](CODE\_OF\_CONDUCT.md).

## We're hiring

Look for current openings on BambooHR https://nventive.bamboohr.com/careers/

## Stay in touch

[nventive.com](https://nventive.com/) | [Linkedin](https://www.linkedin.com/company/nventive/) | [Instagram](https://www.instagram.com/hellonventive/) | [YouTube](https://www.youtube.com/channel/UCFQyvGEKMO10hEyvCqprp5w) | [Spotify](https://open.spotify.com/show/0lsxfIb6Ttm76jB4wgutob)