diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 093121e0..8a010fdd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/antonbabenko/pre-commit-terraform - rev: v1.62.3 + rev: v1.64.0 hooks: - id: terraform_fmt - id: terraform_validate diff --git a/README.md b/README.md index 7e95ac0e..3fa471f9 100644 --- a/README.md +++ b/README.md @@ -14,18 +14,16 @@ Root module calls these modules which can also be used separately to create inde ```hcl module "db" { source = "terraform-aws-modules/rds/aws" - version = "~> 3.0" identifier = "demodb" engine = "mysql" - engine_version = "5.7.19" - instance_class = "db.t2.large" + engine_version = "5.7.25" + instance_class = "db.t3a.large" allocated_storage = 5 - name = "demodb" + db_name = "demodb" username = "user" - password = "YourPwdShouldBeLongAndSecure!" port = "3306" iam_database_authentication_enabled = true @@ -47,7 +45,8 @@ module "db" { } # DB subnet group - subnet_ids = ["subnet-12345678", "subnet-87654321"] + create_db_subnet_group = true + subnet_ids = ["subnet-12345678", "subnet-87654321"] # DB parameter group family = "mysql5.7" @@ -105,8 +104,8 @@ module "db" { # Disable creation of parameter group - provide a parameter group or default to AWS default create_db_parameter_group = false - # Disable creation of subnet group - provide a subnet group - create_db_subnet_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 @@ -206,8 +205,8 @@ Users have the ability to: | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | >= 0.12.26 | -| [aws](#requirement\_aws) | >= 2.49 | +| [terraform](#requirement\_terraform) | >= 0.13.1 | +| [aws](#requirement\_aws) | >= 4.0 | | [random](#requirement\_random) | >= 3.1 | ## Providers @@ -243,74 +242,74 @@ Users have the ability to: | [backup\_retention\_period](#input\_backup\_retention\_period) | The days to retain backups for | `number` | `null` | no | | [backup\_window](#input\_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 | | [ca\_cert\_identifier](#input\_ca\_cert\_identifier) | Specifies the identifier of the CA certificate for the DB instance | `string` | `null` | no | -| [character\_set\_name](#input\_character\_set\_name) | (Optional) 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 | -| [copy\_tags\_to\_snapshot](#input\_copy\_tags\_to\_snapshot) | On delete, copy all Instance tags to the final snapshot (if final\_snapshot\_identifier is specified) | `bool` | `false` | no | +| [character\_set\_name](#input\_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 | +| [copy\_tags\_to\_snapshot](#input\_copy\_tags\_to\_snapshot) | On delete, copy all Instance tags to the final snapshot | `bool` | `false` | no | | [create\_db\_instance](#input\_create\_db\_instance) | Whether to create a database instance | `bool` | `true` | no | -| [create\_db\_option\_group](#input\_create\_db\_option\_group) | (Optional) Create a database option group | `bool` | `true` | no | +| [create\_db\_option\_group](#input\_create\_db\_option\_group) | Create a database option group | `bool` | `true` | no | | [create\_db\_parameter\_group](#input\_create\_db\_parameter\_group) | Whether to create a database parameter group | `bool` | `true` | no | -| [create\_db\_subnet\_group](#input\_create\_db\_subnet\_group) | Whether to create a database subnet group | `bool` | `true` | no | -| [create\_monitoring\_role](#input\_create\_monitoring\_role) | Create IAM role with a defined name that permits RDS to send enhanced monitoring metrics to CloudWatch Logs. | `bool` | `false` | no | -| [create\_random\_password](#input\_create\_random\_password) | Whether to create random password for RDS primary cluster | `bool` | `false` | no | +| [create\_db\_subnet\_group](#input\_create\_db\_subnet\_group) | Whether to create a database subnet group | `bool` | `false` | no | +| [create\_monitoring\_role](#input\_create\_monitoring\_role) | Create IAM role with a defined name that permits RDS to send enhanced monitoring metrics to CloudWatch Logs | `bool` | `false` | no | +| [create\_random\_password](#input\_create\_random\_password) | Whether to create random password for RDS primary cluster | `bool` | `true` | no | | [cross\_region\_replica](#input\_cross\_region\_replica) | Specifies if the replica should be cross region. It allows the use of a subnet group in a region different than the master instance | `bool` | `false` | no | | [db\_instance\_tags](#input\_db\_instance\_tags) | Additional tags for the DB instance | `map(string)` | `{}` | no | +| [db\_name](#input\_db\_name) | The DB name to create. If omitted, no database is created initially | `string` | `null` | no | | [db\_option\_group\_tags](#input\_db\_option\_group\_tags) | Additional tags for the DB option group | `map(string)` | `{}` | no | | [db\_parameter\_group\_tags](#input\_db\_parameter\_group\_tags) | Additional tags for the DB parameter group | `map(string)` | `{}` | no | -| [db\_subnet\_group\_description](#input\_db\_subnet\_group\_description) | Description of the DB subnet group to create | `string` | `""` | no | +| [db\_subnet\_group\_description](#input\_db\_subnet\_group\_description) | Description of the DB subnet group to create | `string` | `null` | no | | [db\_subnet\_group\_name](#input\_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](#input\_db\_subnet\_group\_tags) | Additional tags for the DB subnet group | `map(string)` | `{}` | no | | [db\_subnet\_group\_use\_name\_prefix](#input\_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](#input\_delete\_automated\_backups) | Specifies whether to remove automated backups immediately after the DB instance is deleted | `bool` | `true` | no | -| [deletion\_protection](#input\_deletion\_protection) | The database can't be deleted when this value is set to true. | `bool` | `false` | no | +| [deletion\_protection](#input\_deletion\_protection) | The database can't be deleted when this value is set to true | `bool` | `false` | no | | [domain](#input\_domain) | The ID of the Directory Service Active Directory domain to create the instance in | `string` | `null` | no | | [domain\_iam\_role\_name](#input\_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](#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) | The database engine to use | `string` | `""` | 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) | The database engine to use | `string` | `null` | no | | [engine\_version](#input\_engine\_version) | The engine version to use | `string` | `null` | no | -| [family](#input\_family) | The family of the DB parameter group | `string` | `""` | no | -| [final\_snapshot\_identifier](#input\_final\_snapshot\_identifier) | The name of your final DB snapshot when this DB instance is deleted. | `string` | `null` | no | +| [family](#input\_family) | The family of the DB parameter group | `string` | `null` | no | | [final\_snapshot\_identifier\_prefix](#input\_final\_snapshot\_identifier\_prefix) | The name which is prefixed to the final snapshot on cluster destroy | `string` | `"final"` | no | | [iam\_database\_authentication\_enabled](#input\_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](#input\_identifier) | The name of the RDS instance, if omitted, Terraform will assign a random, unique identifier | `string` | n/a | yes | +| [identifier](#input\_identifier) | The name of the RDS instance | `string` | n/a | yes | | [instance\_class](#input\_instance\_class) | The instance type of the RDS instance | `string` | `null` | no | | [iops](#input\_iops) | The amount of provisioned IOPS. Setting this implies a storage\_type of 'io1' | `number` | `0` | no | | [kms\_key\_id](#input\_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 | `string` | `null` | no | | [license\_model](#input\_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](#input\_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](#input\_major\_engine\_version) | Specifies the major version of the engine that this option group should be associated with | `string` | `""` | no | +| [major\_engine\_version](#input\_major\_engine\_version) | Specifies the major version of the engine that this option group should be associated with | `string` | `null` | no | | [max\_allocated\_storage](#input\_max\_allocated\_storage) | Specifies the value for Storage Autoscaling | `number` | `0` | no | -| [monitoring\_interval](#input\_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](#input\_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\_interval](#input\_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](#input\_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](#input\_monitoring\_role\_description) | Description of the monitoring IAM role | `string` | `null` | no | -| [monitoring\_role\_name](#input\_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\_name](#input\_monitoring\_role\_name) | Name of the IAM role which will be created when create\_monitoring\_role is enabled | `string` | `"rds-monitoring-role"` | no | | [multi\_az](#input\_multi\_az) | Specifies if the RDS instance is multi-AZ | `bool` | `false` | no | -| [name](#input\_name) | The DB name to create. If omitted, no database is created initially | `string` | `null` | no | -| [option\_group\_description](#input\_option\_group\_description) | The description of the option group | `string` | `""` | no | +| [option\_group\_description](#input\_option\_group\_description) | The description of the option group | `string` | `null` | no | | [option\_group\_name](#input\_option\_group\_name) | Name of the option group | `string` | `null` | no | -| [option\_group\_timeouts](#input\_option\_group\_timeouts) | Define maximum timeout for deletion of `aws_db_option_group` resource | `map(string)` |
{| no | +| [option\_group\_timeouts](#input\_option\_group\_timeouts) | Define maximum timeout for deletion of `aws_db_option_group` resource | `map(string)` | `{}` | no | | [option\_group\_use\_name\_prefix](#input\_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](#input\_options) | A list of Options to apply. | `any` | `[]` | no | -| [parameter\_group\_description](#input\_parameter\_group\_description) | Description of the DB parameter group to create | `string` | `""` | no | +| [options](#input\_options) | A list of Options to apply | `any` | `[]` | no | +| [parameter\_group\_description](#input\_parameter\_group\_description) | Description of the DB parameter group to create | `string` | `null` | no | | [parameter\_group\_name](#input\_parameter\_group\_name) | Name of the DB parameter group to associate or create | `string` | `null` | no | | [parameter\_group\_use\_name\_prefix](#input\_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](#input\_parameters) | A list of DB parameters (map) to apply | `list(map(string))` | `[]` | no | -| [password](#input\_password) | Password for the master DB user. Note that this may show up in logs, and it will be stored in the state file | `string` | `""` | no | +| [password](#input\_password) | Password for the master DB user. Note that this may show up in logs, and it will be stored in the state file | `string` | `null` | no | | [performance\_insights\_enabled](#input\_performance\_insights\_enabled) | Specifies whether Performance Insights are enabled | `bool` | `false` | no | -| [performance\_insights\_kms\_key\_id](#input\_performance\_insights\_kms\_key\_id) | The ARN for the KMS key to encrypt Performance Insights data. | `string` | `null` | no | -| [performance\_insights\_retention\_period](#input\_performance\_insights\_retention\_period) | The amount of time in days to retain Performance Insights data. Either 7 (7 days) or 731 (2 years). | `number` | `7` | no | +| [performance\_insights\_kms\_key\_id](#input\_performance\_insights\_kms\_key\_id) | The ARN for the KMS key to encrypt Performance Insights data | `string` | `null` | no | +| [performance\_insights\_retention\_period](#input\_performance\_insights\_retention\_period) | The amount of time in days to retain Performance Insights data. Either 7 (7 days) or 731 (2 years) | `number` | `7` | no | | [port](#input\_port) | The port on which the DB accepts connections | `string` | `null` | no | | [publicly\_accessible](#input\_publicly\_accessible) | Bool to control if instance is publicly accessible | `bool` | `false` | no | -| [random\_password\_length](#input\_random\_password\_length) | (Optional) Length of random password to create. (default: 10) | `number` | `10` | no | -| [replicate\_source\_db](#input\_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 | +| [random\_password\_length](#input\_random\_password\_length) | Length of random password to create | `number` | `16` | no | +| [replica\_mode](#input\_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](#input\_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](#input\_restore\_to\_point\_in\_time) | Restore to a point in time (MySQL is NOT supported) | `map(string)` | `null` | no | | [s3\_import](#input\_s3\_import) | Restore from a Percona Xtrabackup in S3 (only MySQL is supported) | `map(string)` | `null` | no | -| [skip\_final\_snapshot](#input\_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, using the value from final\_snapshot\_identifier | `bool` | `false` | no | -| [snapshot\_identifier](#input\_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](#input\_storage\_encrypted) | Specifies whether the DB instance is encrypted | `bool` | `false` | no | -| [storage\_type](#input\_storage\_type) | One of 'standard' (magnetic), 'gp2' (general purpose SSD), or 'io1' (provisioned IOPS SSD). The default is 'io1' if iops is specified, 'gp2' if not. | `string` | `null` | no | +| [skip\_final\_snapshot](#input\_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](#input\_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](#input\_storage\_encrypted) | Specifies whether the DB instance is encrypted | `bool` | `true` | no | +| [storage\_type](#input\_storage\_type) | One of 'standard' (magnetic), 'gp2' (general purpose SSD), or 'io1' (provisioned IOPS SSD). The default is 'io1' if iops is specified, 'gp2' if not | `string` | `null` | no | | [subnet\_ids](#input\_subnet\_ids) | A list of VPC subnet IDs | `list(string)` | `[]` | no | | [tags](#input\_tags) | A mapping of tags to assign to all resources | `map(string)` | `{}` | no | -| [timeouts](#input\_timeouts) | (Optional) Updated Terraform resource management timeouts. Applies to `aws_db_instance` in particular to permit resource management times | `map(string)` |
"delete": "15m"
}
{| no | -| [timezone](#input\_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. See MSSQL User Guide for more information. | `string` | `null` | no | +| [timeouts](#input\_timeouts) | Updated Terraform resource management timeouts. Applies to `aws_db_instance` in particular to permit resource management times | `map(string)` | `{}` | no | +| [timezone](#input\_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](#input\_username) | Username for the master DB user | `string` | `null` | no | | [vpc\_security\_group\_ids](#input\_vpc\_security\_group\_ids) | List of VPC security groups to associate | `list(string)` | `[]` | no | diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md new file mode 100644 index 00000000..403167c9 --- /dev/null +++ b/UPGRADE-4.0.md @@ -0,0 +1,108 @@ +# Upgrade from v3.x to v4.x + +If you have any questions regarding this upgrade process, please consult the [`examples/`](https://github.com/terraform-aws-modules/terraform-aws-rds/tree/master/examples) projects: + +If you find a bug, please open an issue with supporting configuration to reproduce. + +## List of backwards incompatible changes + +- Support for Terraform `<=v0.12.x` has been dropped; `v0.13.1` is now the minimum supported version +- Terraform AWS provider minimum version is now `v4.0.0` in order to support the replacement of `var.name`(deprecated) for `var.db_name` +- Separate RDS instance resource for MSSQL/SQLServer has been removed - all engines are supported under one resource +- `storage_encrypted` is now set to `true` by default; was previously `false` +- `create_random_password` is now set to `true` by default; was previously `false` +- `create_db_subnet_group` is now set to `false` by default; was previously `true`; typically a shared DB subnet group will be used, most likely from the VPC module +- `random_password_length` is now set to `16` by default, was previously `10` +- Random provider minimum version supported is now `v3.1.0` +- `final_snapshot_identifier` no longer coalesces `var.final_snapshot_identifier` and instead relies on `var.final_snapshot_identifier_prefix` with a random suffix to avoid name collisions + +## Additional changes + +### Added + +- `latest_restorable_time` added to ignored changes +- `replica_mode` support added to DB instance + +### Modified + +- `username`, `password`, and `engine` are set to `null` when a `replicate_source_db` or `snapshot_identifier` is provided; these values are already provided in the respective source +- `engine_version` is set to `null` when a value is provided for `replicate_source_db` +- `db_subnet_group_name` has been updated to use full name when prefix is enabled +- `Name` tag removed from instance resource; name is set via `identifier` and not through tags; users can add back into the tags they provide if desired +- Outputs have been updated to use `try()` syntax; local variable usage has been removed within outputs +- `engine`, `major_engine_version`, `family`, `password`, `db_subnet_group_name`,`db_subnet_group_description`,`parameter_group_name`, +`parameter_group_description`, `option_group_name`, `option_group_description` is now set to `null` by default; was previously `""` +- `timeouts` is now set to `{}` by default; was previously a copy+paste of default value used by provider. This is a no-op but will show up in plans as a diff + +### Variable and output changes + +1. Removed variables: + + - `final_snapshot_identifier` + +2. Renamed variables: + + - `name` (deprecated) -> `db_name` + +3. Added variables: + + - `replica_mode` + +4. Removed outputs: + + - None + +5. Renamed outputs: + + - None + +6. Added outputs: + + - None + +## Upgrade Migrations + +The following examples demonstrate some of the changes that users can elect to make to avoid any potential disruptions when upgrading. + +### Before 3.x Example + +```hcl +module "rds" { + source = "terraform-aws-modules/rds/aws" + version = "~> 3.0" + + master_password = "MySuperStrongPassword!" + + # Previously on read-replicas or restored from snapshot instances you needed to explicitly set these to null + # These can now be safely removed and instead on the module to resolve these appropriately + username = null + password = null + engine = null +} +``` + +### After 4.x Example + +```hcl +module "asg" { + source = "terraform-aws-modules/rds/aws" + version = "~> 4.0" + + master_password = "MySuperStrongPassword!" + # Set random password creation to false if providing your own password as input + create_random_password = false + + # If you did not have storage encrypted in `v3.x`, you can explicitly disable in `v4.x` to avoid disruption + storage_encrypted = false +} +``` + +#### MSSQL/SQLServer + +For MSSSQL/SQLServer, users will want to rename the resource in their Terraform state to align with the flattened DB instance resource module in v4.x: + +```bash +terraform state mv 'module.
"create": "40m",
"delete": "40m",
"update": "80m"
}
{| no | -| [timezone](#input\_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. See MSSQL User Guide for more information. | `string` | `null` | no | +| [timeouts](#input\_timeouts) | Updated Terraform resource management timeouts. Applies to `aws_db_instance` in particular to permit resource management times | `map(string)` | `{}` | no | +| [timezone](#input\_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](#input\_username) | Username for the master DB user | `string` | `null` | no | | [vpc\_security\_group\_ids](#input\_vpc\_security\_group\_ids) | List of VPC security groups to associate | `list(string)` | `[]` | no | diff --git a/modules/db_instance/main.tf b/modules/db_instance/main.tf index c4f2c461..043a074e 100644 --- a/modules/db_instance/main.tf +++ b/modules/db_instance/main.tf @@ -1,7 +1,16 @@ locals { - is_mssql = element(split("-", var.engine), 0) == "sqlserver" + is_mssql = try(element(split("-", var.engine), 0) == "sqlserver", false) monitoring_role_arn = var.create_monitoring_role ? aws_iam_role.enhanced_monitoring[0].arn : var.monitoring_role_arn + + final_snapshot_identifier = var.skip_final_snapshot ? null : "${var.final_snapshot_identifier_prefix}-${var.identifier}-${try(random_id.snapshot_identifier[0].hex, "")}" + + # For replica instances or instances restored from snapshot, the metadata is already baked into the source + metadata_already_exists = var.snapshot_identifier != null || var.replicate_source_db != null + username = local.metadata_already_exists ? null : var.username + password = local.metadata_already_exists ? null : var.password + engine = local.metadata_already_exists ? null : var.engine + engine_version = var.replicate_source_db != null ? null : var.engine_version } # Ref. https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#genref-aws-service-namespaces @@ -22,8 +31,8 @@ resource "aws_db_instance" "this" { identifier = var.identifier - engine = var.engine - engine_version = var.engine_version + engine = local.engine + engine_version = local.engine_version instance_class = var.instance_class allocated_storage = var.allocated_storage storage_type = var.storage_type @@ -31,9 +40,9 @@ resource "aws_db_instance" "this" { kms_key_id = var.kms_key_id license_model = var.license_model - name = var.name - username = var.username - password = var.password + db_name = var.db_name + username = local.username + password = local.password port = var.port domain = var.domain domain_iam_role_name = var.domain_iam_role_name @@ -55,17 +64,17 @@ resource "aws_db_instance" "this" { apply_immediately = var.apply_immediately maintenance_window = var.maintenance_window - snapshot_identifier = var.snapshot_identifier - copy_tags_to_snapshot = var.copy_tags_to_snapshot - skip_final_snapshot = var.skip_final_snapshot - # TODO - remove coalesce() at next breaking change - adding existing name as fallback to maintain backwards compatibility - final_snapshot_identifier = var.skip_final_snapshot ? null : coalesce(var.final_snapshot_identifier, "${var.final_snapshot_identifier_prefix}-${var.identifier}-${random_id.snapshot_identifier[0].hex}") + snapshot_identifier = var.snapshot_identifier + copy_tags_to_snapshot = var.copy_tags_to_snapshot + skip_final_snapshot = var.skip_final_snapshot + final_snapshot_identifier = local.final_snapshot_identifier performance_insights_enabled = var.performance_insights_enabled performance_insights_retention_period = var.performance_insights_enabled ? var.performance_insights_retention_period : null performance_insights_kms_key_id = var.performance_insights_enabled ? var.performance_insights_kms_key_id : null replicate_source_db = var.replicate_source_db + replica_mode = var.replica_mode backup_retention_period = var.backup_retention_period backup_window = var.backup_window max_allocated_storage = var.max_allocated_storage @@ -73,12 +82,12 @@ resource "aws_db_instance" "this" { monitoring_role_arn = var.monitoring_interval > 0 ? local.monitoring_role_arn : null character_set_name = var.character_set_name + timezone = var.timezone enabled_cloudwatch_logs_exports = var.enabled_cloudwatch_logs_exports deletion_protection = var.deletion_protection delete_automated_backups = var.delete_automated_backups - dynamic "restore_to_point_in_time" { for_each = var.restore_to_point_in_time != null ? [var.restore_to_point_in_time] : [] @@ -90,7 +99,6 @@ resource "aws_db_instance" "this" { } } - dynamic "s3_import" { for_each = var.s3_import != null ? [var.s3_import] : [] @@ -103,12 +111,7 @@ resource "aws_db_instance" "this" { } } - tags = merge( - var.tags, - { - "Name" = format("%s", var.identifier) - }, - ) + tags = var.tags timeouts { create = lookup(var.timeouts, "create", null) @@ -123,82 +126,6 @@ resource "aws_db_instance" "this" { } } -resource "aws_db_instance" "this_mssql" { - count = var.create && local.is_mssql ? 1 : 0 - - identifier = var.identifier - - engine = var.engine - engine_version = var.engine_version - instance_class = var.instance_class - allocated_storage = var.allocated_storage - storage_type = var.storage_type - storage_encrypted = var.storage_encrypted - kms_key_id = var.kms_key_id - license_model = var.license_model - - name = var.name - username = var.username - password = var.password - port = var.port - domain = var.domain - domain_iam_role_name = var.domain_iam_role_name - iam_database_authentication_enabled = var.iam_database_authentication_enabled - - vpc_security_group_ids = var.vpc_security_group_ids - db_subnet_group_name = var.db_subnet_group_name - parameter_group_name = var.parameter_group_name - option_group_name = var.option_group_name - - availability_zone = var.availability_zone - multi_az = var.multi_az - iops = var.iops - publicly_accessible = var.publicly_accessible - ca_cert_identifier = var.ca_cert_identifier - - allow_major_version_upgrade = var.allow_major_version_upgrade - auto_minor_version_upgrade = var.auto_minor_version_upgrade - apply_immediately = var.apply_immediately - maintenance_window = var.maintenance_window - - snapshot_identifier = var.snapshot_identifier - copy_tags_to_snapshot = var.copy_tags_to_snapshot - skip_final_snapshot = var.skip_final_snapshot - # TODO - remove coalesce() at next breaking change - adding existing name as fallback to maintain backwards compatibility - final_snapshot_identifier = var.skip_final_snapshot ? null : coalesce(var.final_snapshot_identifier, "${var.final_snapshot_identifier_prefix}-${var.identifier}-${random_id.snapshot_identifier[0].hex}") - - performance_insights_enabled = var.performance_insights_enabled - performance_insights_retention_period = var.performance_insights_enabled ? var.performance_insights_retention_period : null - performance_insights_kms_key_id = var.performance_insights_enabled ? var.performance_insights_kms_key_id : null - - replicate_source_db = var.replicate_source_db - backup_retention_period = var.backup_retention_period - backup_window = var.backup_window - max_allocated_storage = var.max_allocated_storage - monitoring_interval = var.monitoring_interval - monitoring_role_arn = var.monitoring_interval > 0 ? local.monitoring_role_arn : null - - character_set_name = var.character_set_name - timezone = var.timezone # MSSQL only - enabled_cloudwatch_logs_exports = var.enabled_cloudwatch_logs_exports - - deletion_protection = var.deletion_protection - delete_automated_backups = var.delete_automated_backups - - tags = merge( - var.tags, - { - "Name" = format("%s", var.identifier) - }, - ) - - timeouts { - create = lookup(var.timeouts, "create", null) - delete = lookup(var.timeouts, "delete", null) - update = lookup(var.timeouts, "update", null) - } -} - ################################################################################ # Enhanced monitoring ################################################################################ diff --git a/modules/db_instance/outputs.tf b/modules/db_instance/outputs.tf index 8bfa04ba..ebcffc03 100644 --- a/modules/db_instance/outputs.tf +++ b/modules/db_instance/outputs.tf @@ -1,106 +1,86 @@ -locals { - enhanced_monitoring_iam_role_name = element(concat(aws_iam_role.enhanced_monitoring.*.name, [""]), 0) - enhanced_monitoring_iam_role_arn = element(concat(aws_iam_role.enhanced_monitoring.*.arn, [""]), 0) - db_instance_address = element(concat(aws_db_instance.this_mssql.*.address, aws_db_instance.this.*.address, [""]), 0) - db_instance_arn = element(concat(aws_db_instance.this_mssql.*.arn, aws_db_instance.this.*.arn, [""]), 0) - db_instance_availability_zone = element(concat(aws_db_instance.this_mssql.*.availability_zone, aws_db_instance.this.*.availability_zone, [""]), 0) - db_instance_endpoint = element(concat(aws_db_instance.this_mssql.*.endpoint, aws_db_instance.this.*.endpoint, [""]), 0) - db_instance_hosted_zone_id = element(concat(aws_db_instance.this_mssql.*.hosted_zone_id, aws_db_instance.this.*.hosted_zone_id, [""]), 0) - db_instance_id = element(concat(aws_db_instance.this_mssql.*.id, aws_db_instance.this.*.id, [""]), 0) - db_instance_resource_id = element(concat(aws_db_instance.this_mssql.*.resource_id, aws_db_instance.this.*.resource_id, [""]), 0) - db_instance_status = element(concat(aws_db_instance.this_mssql.*.status, aws_db_instance.this.*.status, [""]), 0) - db_instance_name = element(concat(aws_db_instance.this_mssql.*.name, aws_db_instance.this.*.name, [""]), 0) - db_instance_username = element(concat(aws_db_instance.this_mssql.*.username, aws_db_instance.this.*.username, [""]), 0) - db_instance_port = element(concat(aws_db_instance.this_mssql.*.port, aws_db_instance.this.*.port, [""]), 0) - db_instance_ca_cert_identifier = element(concat(aws_db_instance.this_mssql.*.ca_cert_identifier, aws_db_instance.this.*.ca_cert_identifier, [""]), 0) - db_instance_domain = element(concat(aws_db_instance.this_mssql.*.domain, [""]), 0) - db_instance_domain_iam_role_name = element(concat(aws_db_instance.this_mssql.*.domain_iam_role_name, [""]), 0) - db_instance_master_password = element(concat(aws_db_instance.this_mssql.*.password, aws_db_instance.this.*.password, [""]), 0) -} - output "enhanced_monitoring_iam_role_name" { description = "The name of the monitoring role" - value = local.enhanced_monitoring_iam_role_name + value = try(aws_iam_role.enhanced_monitoring[0].name, "") } output "enhanced_monitoring_iam_role_arn" { description = "The Amazon Resource Name (ARN) specifying the monitoring role" - value = local.enhanced_monitoring_iam_role_arn + value = try(aws_iam_role.enhanced_monitoring[0].arn, "") } output "db_instance_address" { description = "The address of the RDS instance" - value = local.db_instance_address + value = try(aws_db_instance.this[0].address, "") } output "db_instance_arn" { description = "The ARN of the RDS instance" - value = local.db_instance_arn + value = try(aws_db_instance.this[0].arn, "") } output "db_instance_availability_zone" { description = "The availability zone of the RDS instance" - value = local.db_instance_availability_zone + value = try(aws_db_instance.this[0].availability_zone, "") } output "db_instance_endpoint" { description = "The connection endpoint" - value = local.db_instance_endpoint + value = try(aws_db_instance.this[0].endpoint, "") } output "db_instance_hosted_zone_id" { description = "The canonical hosted zone ID of the DB instance (to be used in a Route 53 Alias record)" - value = local.db_instance_hosted_zone_id + value = try(aws_db_instance.this[0].hosted_zone_id, "") } output "db_instance_id" { description = "The RDS instance ID" - value = local.db_instance_id + value = try(aws_db_instance.this[0].id, "") } output "db_instance_resource_id" { description = "The RDS Resource ID of this instance" - value = local.db_instance_resource_id + value = try(aws_db_instance.this[0].resource_id, "") } output "db_instance_status" { description = "The RDS instance status" - value = local.db_instance_status + value = try(aws_db_instance.this[0].status, "") } output "db_instance_name" { description = "The database name" - value = local.db_instance_name + value = try(aws_db_instance.this[0].name, "") } output "db_instance_username" { description = "The master username for the database" - value = local.db_instance_username + value = try(aws_db_instance.this[0].username, "") sensitive = true } output "db_instance_port" { description = "The database port" - value = local.db_instance_port + value = try(aws_db_instance.this[0].port, "") } output "db_instance_ca_cert_identifier" { description = "Specifies the identifier of the CA certificate for the DB instance" - value = local.db_instance_ca_cert_identifier + value = try(aws_db_instance.this[0].ca_cert_identifier, "") } output "db_instance_domain" { description = "The ID of the Directory Service Active Directory domain the instance is joined to" - value = local.db_instance_domain + value = try(aws_db_instance.this[0].domain, "") } output "db_instance_domain_iam_role_name" { description = "The name of the IAM role to be used when making API calls to the Directory Service. " - value = local.db_instance_domain_iam_role_name + value = try(aws_db_instance.this[0].domain_iam_role_name, "") } output "db_instance_master_password" { description = "The master password" - value = local.db_instance_master_password + value = try(aws_db_instance.this[0].password, "") sensitive = true } diff --git a/modules/db_instance/variables.tf b/modules/db_instance/variables.tf index 24651bb9..cca375ba 100644 --- a/modules/db_instance/variables.tf +++ b/modules/db_instance/variables.tf @@ -5,7 +5,7 @@ variable "create" { } variable "identifier" { - description = "The name of the RDS instance, if omitted, Terraform will assign a random, unique identifier" + description = "The name of the RDS instance" type = string } @@ -24,7 +24,7 @@ variable "storage_type" { variable "storage_encrypted" { description = "Specifies whether the DB instance is encrypted" type = bool - default = false + default = true } variable "kms_key_id" { @@ -45,6 +45,12 @@ variable "license_model" { default = null } +variable "replica_mode" { + description = "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" + type = string + default = null +} + variable "iam_database_authentication_enabled" { description = "Specifies whether or mappings of AWS Identity and Access Management (IAM) accounts to database accounts is enabled" type = bool @@ -66,7 +72,7 @@ variable "domain_iam_role_name" { variable "engine" { description = "The database engine to use" type = string - default = "" + default = null } variable "engine_version" { @@ -81,7 +87,7 @@ variable "instance_class" { default = null } -variable "name" { +variable "db_name" { description = "The DB name to create. If omitted, no database is created initially" type = string default = null @@ -106,7 +112,7 @@ variable "port" { } variable "skip_final_snapshot" { - description = "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" + description = "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" type = bool default = false } @@ -118,17 +124,11 @@ variable "snapshot_identifier" { } variable "copy_tags_to_snapshot" { - description = "On delete, copy all Instance tags to the final snapshot (if final_snapshot_identifier is specified)" + description = "On delete, copy all Instance tags to the final snapshot" type = bool default = false } -variable "final_snapshot_identifier" { - description = "The name of your final DB snapshot when this DB instance is deleted." - type = string - default = null -} - variable "final_snapshot_identifier_prefix" { description = "The name which is prefixed to the final snapshot on cluster destroy" type = string @@ -144,13 +144,13 @@ variable "vpc_security_group_ids" { variable "db_subnet_group_name" { description = "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" type = string - default = "" + default = null } variable "parameter_group_name" { description = "Name of the DB parameter group to associate" type = string - default = "" + default = null } variable "availability_zone" { @@ -252,17 +252,17 @@ variable "tags" { variable "option_group_name" { description = "Name of the DB option group to associate." type = string - default = "" + default = null } variable "timezone" { - description = "(Optional) 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." + description = "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." type = string default = null } variable "character_set_name" { - description = "(Optional) 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." + description = "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." type = string default = null } @@ -274,13 +274,9 @@ variable "enabled_cloudwatch_logs_exports" { } variable "timeouts" { - description = "(Optional) Updated Terraform resource management timeouts. Applies to `aws_db_instance` in particular to permit resource management times" + description = "Updated Terraform resource management timeouts. Applies to `aws_db_instance` in particular to permit resource management times" type = map(string) - default = { - create = "40m" - update = "80m" - delete = "40m" - } + default = {} } variable "deletion_protection" { diff --git a/modules/db_instance/versions.tf b/modules/db_instance/versions.tf index 9234cc98..c849c1e9 100644 --- a/modules/db_instance/versions.tf +++ b/modules/db_instance/versions.tf @@ -1,15 +1,15 @@ terraform { - required_version = ">= 0.12.26" + required_version = ">= 0.13.1" required_providers { aws = { source = "hashicorp/aws" - version = ">= 2.49" + version = ">= 4.0" } random = { source = "hashicorp/random" - version = ">= 2.2" + version = ">= 3.1" } } } diff --git a/modules/db_option_group/README.md b/modules/db_option_group/README.md index f55eda67..2ad344a4 100644 --- a/modules/db_option_group/README.md +++ b/modules/db_option_group/README.md @@ -5,14 +5,14 @@ | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | >= 0.12.26 | -| [aws](#requirement\_aws) | >= 2.49 | +| [terraform](#requirement\_terraform) | >= 0.13.1 | +| [aws](#requirement\_aws) | >= 3.62 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 2.49 | +| [aws](#provider\_aws) | >= 3.62 | ## Modules @@ -32,10 +32,10 @@ No modules. | [engine\_name](#input\_engine\_name) | Specifies the name of the engine that this option group should be associated with | `string` | `null` | no | | [major\_engine\_version](#input\_major\_engine\_version) | Specifies the major version of the engine that this option group should be associated with | `string` | `null` | no | | [name](#input\_name) | The name of the option group | `string` | `""` | no | -| [option\_group\_description](#input\_option\_group\_description) | The description of the option group | `string` | `""` | no | +| [option\_group\_description](#input\_option\_group\_description) | The description of the option group | `string` | `null` | no | | [options](#input\_options) | A list of Options to apply | `any` | `[]` | no | | [tags](#input\_tags) | A mapping of tags to assign to the resource | `map(string)` | `{}` | no | -| [timeouts](#input\_timeouts) | Define maximum timeout for deletion of `aws_db_option_group` resource | `map(string)` |
"create": "40m",
"delete": "40m",
"update": "80m"
}
{| no | +| [timeouts](#input\_timeouts) | Define maximum timeout for deletion of `aws_db_option_group` resource | `map(string)` | `{}` | no | | [use\_name\_prefix](#input\_use\_name\_prefix) | Determines whether to use `name` as is or create a unique name beginning with `name` as the specified prefix | `bool` | `true` | no | ## Outputs diff --git a/modules/db_option_group/outputs.tf b/modules/db_option_group/outputs.tf index 5ef4b22c..3a87a8f6 100644 --- a/modules/db_option_group/outputs.tf +++ b/modules/db_option_group/outputs.tf @@ -1,9 +1,9 @@ output "db_option_group_id" { description = "The db option group id" - value = element(concat(aws_db_option_group.this.*.id, [""]), 0) + value = try(aws_db_option_group.this[0].id, "") } output "db_option_group_arn" { description = "The ARN of the db option group" - value = element(concat(aws_db_option_group.this.*.arn, [""]), 0) + value = try(aws_db_option_group.this[0].arn, "") } diff --git a/modules/db_option_group/variables.tf b/modules/db_option_group/variables.tf index 9d58cbf4..de4be194 100644 --- a/modules/db_option_group/variables.tf +++ b/modules/db_option_group/variables.tf @@ -19,7 +19,7 @@ variable "use_name_prefix" { variable "option_group_description" { description = "The description of the option group" type = string - default = "" + default = null } variable "engine_name" { @@ -43,9 +43,7 @@ variable "options" { variable "timeouts" { description = "Define maximum timeout for deletion of `aws_db_option_group` resource" type = map(string) - default = { - delete = "15m" - } + default = {} } variable "tags" { diff --git a/modules/db_option_group/versions.tf b/modules/db_option_group/versions.tf index a5953db4..c7b91448 100644 --- a/modules/db_option_group/versions.tf +++ b/modules/db_option_group/versions.tf @@ -1,10 +1,10 @@ terraform { - required_version = ">= 0.12.26" + required_version = ">= 0.13.1" required_providers { aws = { source = "hashicorp/aws" - version = ">= 2.49" + version = ">= 3.62" } } } diff --git a/modules/db_parameter_group/README.md b/modules/db_parameter_group/README.md index 5249ef1b..2487816b 100644 --- a/modules/db_parameter_group/README.md +++ b/modules/db_parameter_group/README.md @@ -5,14 +5,14 @@ | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | >= 0.12.26 | -| [aws](#requirement\_aws) | >= 2.49 | +| [terraform](#requirement\_terraform) | >= 0.13.1 | +| [aws](#requirement\_aws) | >= 3.62 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 2.49 | +| [aws](#provider\_aws) | >= 3.62 | ## Modules @@ -29,7 +29,7 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [create](#input\_create) | Whether to create this resource or not? | `bool` | `true` | no | -| [description](#input\_description) | The description of the DB parameter group | `string` | `""` | no | +| [description](#input\_description) | The description of the DB parameter group | `string` | `null` | no | | [family](#input\_family) | The family of the DB parameter group | `string` | `null` | no | | [name](#input\_name) | The name of the DB parameter group | `string` | `""` | no | | [parameters](#input\_parameters) | A list of DB parameter maps to apply | `list(map(string))` | `[]` | no | diff --git a/modules/db_parameter_group/outputs.tf b/modules/db_parameter_group/outputs.tf index 0f66124e..e67ec7c8 100644 --- a/modules/db_parameter_group/outputs.tf +++ b/modules/db_parameter_group/outputs.tf @@ -1,9 +1,9 @@ output "db_parameter_group_id" { description = "The db parameter group id" - value = element(concat(aws_db_parameter_group.this.*.id, [""]), 0) + value = try(aws_db_parameter_group.this[0].id, "") } output "db_parameter_group_arn" { description = "The ARN of the db parameter group" - value = element(concat(aws_db_parameter_group.this.*.arn, [""]), 0) + value = try(aws_db_parameter_group.this[0].arn, "") } diff --git a/modules/db_parameter_group/variables.tf b/modules/db_parameter_group/variables.tf index c6beb376..b7b7af9f 100644 --- a/modules/db_parameter_group/variables.tf +++ b/modules/db_parameter_group/variables.tf @@ -19,7 +19,7 @@ variable "use_name_prefix" { variable "description" { description = "The description of the DB parameter group" type = string - default = "" + default = null } variable "family" { diff --git a/modules/db_parameter_group/versions.tf b/modules/db_parameter_group/versions.tf index a5953db4..c7b91448 100644 --- a/modules/db_parameter_group/versions.tf +++ b/modules/db_parameter_group/versions.tf @@ -1,10 +1,10 @@ terraform { - required_version = ">= 0.12.26" + required_version = ">= 0.13.1" required_providers { aws = { source = "hashicorp/aws" - version = ">= 2.49" + version = ">= 3.62" } } } diff --git a/modules/db_subnet_group/README.md b/modules/db_subnet_group/README.md index e45bf75a..7e605618 100644 --- a/modules/db_subnet_group/README.md +++ b/modules/db_subnet_group/README.md @@ -5,14 +5,14 @@ | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | >= 0.12.26 | -| [aws](#requirement\_aws) | >= 2.49 | +| [terraform](#requirement\_terraform) | >= 0.13.1 | +| [aws](#requirement\_aws) | >= 3.62 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 2.49 | +| [aws](#provider\_aws) | >= 3.62 | ## Modules @@ -29,7 +29,7 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [create](#input\_create) | Whether to create this resource or not? | `bool` | `true` | no | -| [description](#input\_description) | The description of the DB subnet group | `string` | `""` | no | +| [description](#input\_description) | The description of the DB subnet group | `string` | `null` | no | | [name](#input\_name) | The name of the DB subnet group | `string` | `""` | no | | [subnet\_ids](#input\_subnet\_ids) | A list of VPC subnet IDs | `list(string)` | `[]` | no | | [tags](#input\_tags) | A mapping of tags to assign to the resource | `map(string)` | `{}` | no | diff --git a/modules/db_subnet_group/outputs.tf b/modules/db_subnet_group/outputs.tf index 4ef75253..aa803a34 100644 --- a/modules/db_subnet_group/outputs.tf +++ b/modules/db_subnet_group/outputs.tf @@ -1,9 +1,9 @@ output "db_subnet_group_id" { description = "The db subnet group name" - value = element(concat(aws_db_subnet_group.this.*.id, [""]), 0) + value = try(aws_db_subnet_group.this[0].id, "") } output "db_subnet_group_arn" { description = "The ARN of the db subnet group" - value = element(concat(aws_db_subnet_group.this.*.arn, [""]), 0) + value = try(aws_db_subnet_group.this[0].arn, "") } diff --git a/modules/db_subnet_group/variables.tf b/modules/db_subnet_group/variables.tf index 802f5e74..48185ab4 100644 --- a/modules/db_subnet_group/variables.tf +++ b/modules/db_subnet_group/variables.tf @@ -19,7 +19,7 @@ variable "use_name_prefix" { variable "description" { description = "The description of the DB subnet group" type = string - default = "" + default = null } variable "subnet_ids" { diff --git a/modules/db_subnet_group/versions.tf b/modules/db_subnet_group/versions.tf index a5953db4..c7b91448 100644 --- a/modules/db_subnet_group/versions.tf +++ b/modules/db_subnet_group/versions.tf @@ -1,10 +1,10 @@ terraform { - required_version = ">= 0.12.26" + required_version = ">= 0.13.1" required_providers { aws = { source = "hashicorp/aws" - version = ">= 2.49" + version = ">= 3.62" } } } diff --git a/variables.tf b/variables.tf index 871cbd92..76f6ce5a 100644 --- a/variables.tf +++ b/variables.tf @@ -1,5 +1,5 @@ variable "identifier" { - description = "The name of the RDS instance, if omitted, Terraform will assign a random, unique identifier" + description = "The name of the RDS instance" type = string } @@ -10,7 +10,7 @@ variable "allocated_storage" { } variable "storage_type" { - description = "One of 'standard' (magnetic), 'gp2' (general purpose SSD), or 'io1' (provisioned IOPS SSD). The default is 'io1' if iops is specified, 'gp2' if not." + description = "One of 'standard' (magnetic), 'gp2' (general purpose SSD), or 'io1' (provisioned IOPS SSD). The default is 'io1' if iops is specified, 'gp2' if not" type = string default = null } @@ -18,7 +18,7 @@ variable "storage_type" { variable "storage_encrypted" { description = "Specifies whether the DB instance is encrypted" type = bool - default = false + default = true } variable "kms_key_id" { @@ -28,7 +28,7 @@ variable "kms_key_id" { } variable "replicate_source_db" { - description = "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." + description = "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" type = string default = null } @@ -45,6 +45,12 @@ variable "license_model" { default = null } +variable "replica_mode" { + description = "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" + type = string + default = null +} + variable "iam_database_authentication_enabled" { description = "Specifies whether or not the mappings of AWS Identity and Access Management (IAM) accounts to database accounts are enabled" type = bool @@ -66,7 +72,7 @@ variable "domain_iam_role_name" { variable "engine" { description = "The database engine to use" type = string - default = "" + default = null } variable "engine_version" { @@ -76,29 +82,23 @@ variable "engine_version" { } variable "skip_final_snapshot" { - description = "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" + description = "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" type = bool default = false } variable "snapshot_identifier" { - description = "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." + description = "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" type = string default = null } variable "copy_tags_to_snapshot" { - description = "On delete, copy all Instance tags to the final snapshot (if final_snapshot_identifier is specified)" + description = "On delete, copy all Instance tags to the final snapshot" type = bool default = false } -variable "final_snapshot_identifier" { - description = "The name of your final DB snapshot when this DB instance is deleted." - type = string - default = null -} - variable "final_snapshot_identifier_prefix" { description = "The name which is prefixed to the final snapshot on cluster destroy" type = string @@ -111,7 +111,7 @@ variable "instance_class" { default = null } -variable "name" { +variable "db_name" { description = "The DB name to create. If omitted, no database is created initially" type = string default = null @@ -126,7 +126,7 @@ variable "username" { variable "password" { description = "Password for the master DB user. Note that this may show up in logs, and it will be stored in the state file" type = string - default = "" + default = null } variable "port" { @@ -166,19 +166,19 @@ variable "publicly_accessible" { } variable "monitoring_interval" { - description = "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." + description = "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" type = number default = 0 } variable "monitoring_role_arn" { - description = "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." + description = "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" type = string default = null } variable "monitoring_role_name" { - description = "Name of the IAM role which will be created when create_monitoring_role is enabled." + description = "Name of the IAM role which will be created when create_monitoring_role is enabled" type = string default = "rds-monitoring-role" } @@ -190,7 +190,7 @@ variable "monitoring_role_description" { } variable "create_monitoring_role" { - description = "Create IAM role with a defined name that permits RDS to send enhanced monitoring metrics to CloudWatch Logs." + description = "Create IAM role with a defined name that permits RDS to send enhanced monitoring metrics to CloudWatch Logs" type = bool default = false } @@ -277,7 +277,7 @@ variable "db_subnet_group_tags" { variable "create_db_subnet_group" { description = "Whether to create a database subnet group" type = bool - default = true + default = false } variable "db_subnet_group_name" { @@ -295,7 +295,7 @@ variable "db_subnet_group_use_name_prefix" { variable "db_subnet_group_description" { description = "Description of the DB subnet group to create" type = string - default = "" + default = null } variable "subnet_ids" { @@ -326,13 +326,13 @@ variable "parameter_group_use_name_prefix" { variable "parameter_group_description" { description = "Description of the DB parameter group to create" type = string - default = "" + default = null } variable "family" { description = "The family of the DB parameter group" type = string - default = "" + default = null } variable "parameters" { @@ -343,7 +343,7 @@ variable "parameters" { # DB option group variable "create_db_option_group" { - description = "(Optional) Create a database option group" + description = "Create a database option group" type = bool default = true } @@ -363,17 +363,17 @@ variable "option_group_use_name_prefix" { variable "option_group_description" { description = "The description of the option group" type = string - default = "" + default = null } variable "major_engine_version" { description = "Specifies the major version of the engine that this option group should be associated with" type = string - default = "" + default = null } variable "options" { - description = "A list of Options to apply." + description = "A list of Options to apply" type = any default = [] } @@ -385,43 +385,37 @@ variable "create_db_instance" { } variable "timezone" { - description = "(Optional) 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." + description = "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" type = string default = null } variable "character_set_name" { - description = "(Optional) 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." + description = "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" type = string default = null } variable "enabled_cloudwatch_logs_exports" { - description = "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)." + description = "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)" type = list(string) default = [] } variable "timeouts" { - description = "(Optional) Updated Terraform resource management timeouts. Applies to `aws_db_instance` in particular to permit resource management times" + description = "Updated Terraform resource management timeouts. Applies to `aws_db_instance` in particular to permit resource management times" type = map(string) - default = { - create = "40m" - update = "80m" - delete = "40m" - } + default = {} } variable "option_group_timeouts" { description = "Define maximum timeout for deletion of `aws_db_option_group` resource" type = map(string) - default = { - delete = "15m" - } + default = {} } variable "deletion_protection" { - description = "The database can't be deleted when this value is set to true." + description = "The database can't be deleted when this value is set to true" type = bool default = false } @@ -433,13 +427,13 @@ variable "performance_insights_enabled" { } variable "performance_insights_retention_period" { - description = "The amount of time in days to retain Performance Insights data. Either 7 (7 days) or 731 (2 years)." + description = "The amount of time in days to retain Performance Insights data. Either 7 (7 days) or 731 (2 years)" type = number default = 7 } variable "performance_insights_kms_key_id" { - description = "The ARN for the KMS key to encrypt Performance Insights data." + description = "The ARN for the KMS key to encrypt Performance Insights data" type = string default = null } @@ -465,11 +459,11 @@ variable "delete_automated_backups" { variable "create_random_password" { description = "Whether to create random password for RDS primary cluster" type = bool - default = false + default = true } variable "random_password_length" { - description = "(Optional) Length of random password to create. (default: 10)" + description = "Length of random password to create" type = number - default = 10 + default = 16 } diff --git a/versions.tf b/versions.tf index e9788343..c849c1e9 100644 --- a/versions.tf +++ b/versions.tf @@ -1,11 +1,12 @@ terraform { - required_version = ">= 0.12.26" + required_version = ">= 0.13.1" required_providers { aws = { source = "hashicorp/aws" - version = ">= 2.49" + version = ">= 4.0" } + random = { source = "hashicorp/random" version = ">= 3.1"
"delete": "15m"
}